Re: [CMake] Use interface libraries for providing compile options and definitions

2019-10-03 Thread Craig Scott
On Fri, Oct 4, 2019 at 2:27 AM Dustyn Blasig  wrote:

> Hi All,
>
> I have been cleaning up our legacy CMake to use newer features (available
> in 3.12+) including trying to use target_...() functions nearly
> exclusively. As part of this, I was toying with cleaning up our use cases
> for adding compiler flags and similar definitions using real targets and
> target_link_libraries.
>
> For instance, as a simple example, let's say I wanted to add/provide a
> definition MY_FLAG, I could do something like...
>
> ```
> add_library(my_flag INTERFACE)
> target_compile_definitions(my_flag INTERFACE MY_FLAG=1)
>
> add_library(other_library SHARED ...)
> target_link_libraries(other_library ... *PRIVATE *my_flag)
>
> export/install rules
> ```
>
> I want this library to be private to my component, and it's only used
> under the PRIVATE banner. However, the issue I'm running into is with the
> install/export rules. I get an error similar to ...
>
> ```
> CMake Error: install(EXPORT "MY_PROJECT" ...) includes target
> "other_library" which requires target "my_flag" that is not in the export
> set.
> ```
>
> If my_flag is defined in my component, I can add it to the export set
> perhaps to workaround the issue, but in many cases, it would be coming from
> a helper script in another sub-project I'm fetching using FetchContent and
> don't want to expose the functionality via my export scripts.
>
> (1) Is it recommended to use interface libraries to clean up compile
> defintions, etc.
>

Personally, I don't typically use interface libraries to do this, I prefer
to list the requirements directly on the targets that they apply to. Some
people/projects may choose to collect a commonly used set of requirements
into an interface library, but one drawback with that is it creates the
temptation to lump a bunch of things together in that interface library
"for convenience", but end up with some targets having requirements applied
to them that aren't actually requirements for those targets at all. Used
appropriately, the technique can be helpful, but don't over-use it. ;)



> (2) Should it be possible to link privately such libraries and not have
> the export functionality complain?
>

>From a usage requirement point of view, the interface library shouldn't
need to be exported/installed because it is private. However, from a
linking point of view, a shared library still needs all other libraries it
links against for the linker to succeed at link time. Interface libraries
don't appear on the linker command line, so they shouldn't need to be
installed for linking to succeed, but I'm wondering if CMake's internal
logic isn't properly handling this. Can you open an issue in CMake's gitlab
 and attach a complete,
minimal example which reproduces the error (seems you're almost there with
the extracted commands above)?

-- 
Craig Scott
Melbourne, Australia
https://crascit.com

Get the hand-book for every CMake user: Professional CMake: A Practical
Guide 
Consulting services (CMake, C++, build/release processes):
https://crascit.com/services
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] HOWTO declare component inter-dependencies in multi-component packages

2019-10-03 Thread Kyle Edwards via CMake
On Thu, 2019-10-03 at 17:08 -0400, stefan wrote:
> Yes, that is exactly what I'm trying to do, but it doesn't seem to
> have any effect. That is, `dpkg --info ...` doesn't list the
> additional dependency, and correspondingly, running `apt-get install
> ...` on the component package file will install the package without
> first installing the prerequisite component.
> Consider this declaration:
>   set(CPACK_COMPONENTS_ALL runtime development mstool)
> If I now write
>   set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS runtime)
> I will see no effect. That is, the "development" package still does
> not depend on the "runtime" package.
> So I try this:
>   set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS RUNTIME)
> in case capitalization is required. Now the "runtime" component seems
> to get packaged twice (as per the cmake logs), but still no correct
> dependencies.
> Is it time for a bug report ?

Please send us a minimal CMakeLists.txt that reproduces the issue.

Kyle
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] HOWTO declare component inter-dependencies in multi-component packages

2019-10-03 Thread stefan


On 2019-10-03 4:59 p.m., Kyle Edwards wrote:

On Thu, 2019-10-03 at 16:42 -0400, stefan wrote:

My project is already using this style:
   set(CPACK_COMPONENTS_ALL runtime development mstool)

i.e. all components are already defined. All that's missing is the
declaration of their (inter-)dependencies.
Are you suggesting I should *not* use CPACK_COMPONENTS_ALL, but
instead call `cpack_add_component()` instead ?
Thanks,

That's how I prefer to do it. Alternatively, you could set
CPACK_COMPONENT__DEPENDS directly (that's all that
cpack_add_component() is doing.)


Yes, that is exactly what I'm trying to do, but it doesn't seem to have 
any effect. That is, `dpkg --info ...` doesn't list the additional 
dependency, and correspondingly, running `apt-get install ...` on the 
component package file will install the package without first installing 
the prerequisite component.


Consider this declaration:

  set(CPACK_COMPONENTS_ALL runtime development mstool)

If I now write

  set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS runtime)

I will see no effect. That is, the "development" package still does not 
depend on the "runtime" package.


So I try this:

  set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS RUNTIME)

in case capitalization is required. Now the "runtime" component seems to 
get packaged twice (as per the cmake logs), but still no correct 
dependencies.


Is it time for a bug report ?

Stefan

--

  ...ich hab' noch einen Koffer in Berlin...


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] HOWTO declare component inter-dependencies in multi-component packages

2019-10-03 Thread Kyle Edwards via CMake
On Thu, 2019-10-03 at 16:42 -0400, stefan wrote:
> My project is already using this style:
>   set(CPACK_COMPONENTS_ALL runtime development mstool)
> 
> i.e. all components are already defined. All that's missing is the
> declaration of their (inter-)dependencies.
> Are you suggesting I should *not* use CPACK_COMPONENTS_ALL, but
> instead call `cpack_add_component()` instead ?
> Thanks,

That's how I prefer to do it. Alternatively, you could set
CPACK_COMPONENT__DEPENDS directly (that's all that
cpack_add_component() is doing.)

Kyle
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] HOWTO declare component inter-dependencies in multi-component packages

2019-10-03 Thread stefan


On 2019-10-03 4:37 p.m., Kyle Edwards wrote:

On Thu, 2019-10-03 at 16:30 -0400, stefan wrote:

Hi Kyle,
thanks for the quick followup.
On 2019-10-03 4:23 p.m., Kyle Edwards wrote:

Please take a look at cpack_add_component():
https://cmake.org/cmake/help/latest/module/CPackComponent.html

I'm not sure what specifically I should be looking for.
In general my setup is working fine, i.e. my build generates multiple
packages as expected. They even contain dependencies to external
packages, as I have set as per the available variables. What I
haven't been able to express is the component inter-dependency. That
is, I haven't found a way to make my "development" package depend on
the "runtime" package (generated from the same build process).
Sorry for being obtuse.

In particular, please look at the DEPENDS argument of
cpack_add_component():

"DEPENDS lists the components on which this component depends. If this
component is selected, then each of the components listed must also be
selected. The dependency information is encoded within the installer
itself, so that users cannot install inconsistent sets of components."


My project is already using this style:

  set(CPACK_COMPONENTS_ALL runtime development mstool)

i.e. all components are already defined. All that's missing is the 
declaration of their (inter-)dependencies.


Are you suggesting I should *not* use CPACK_COMPONENTS_ALL, but instead 
call `cpack_add_component()` instead ?


Thanks,


Stefan

--

  ...ich hab' noch einen Koffer in Berlin...


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] HOWTO declare component inter-dependencies in multi-component packages

2019-10-03 Thread Kyle Edwards via CMake
On Thu, 2019-10-03 at 16:30 -0400, stefan wrote:
> Hi Kyle,
> thanks for the quick followup.
> On 2019-10-03 4:23 p.m., Kyle Edwards wrote:
> > Please take a look at cpack_add_component():
> > https://cmake.org/cmake/help/latest/module/CPackComponent.html
> I'm not sure what specifically I should be looking for.
> In general my setup is working fine, i.e. my build generates multiple
> packages as expected. They even contain dependencies to external
> packages, as I have set as per the available variables. What I
> haven't been able to express is the component inter-dependency. That
> is, I haven't found a way to make my "development" package depend on
> the "runtime" package (generated from the same build process).
> Sorry for being obtuse.

In particular, please look at the DEPENDS argument of
cpack_add_component():

"DEPENDS lists the components on which this component depends. If this
component is selected, then each of the components listed must also be
selected. The dependency information is encoded within the installer
itself, so that users cannot install inconsistent sets of components."

Kyle
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] HOWTO declare component inter-dependencies in multi-component packages

2019-10-03 Thread stefan

Hi Kyle,

thanks for the quick followup.

On 2019-10-03 4:23 p.m., Kyle Edwards wrote:

Please take a look at cpack_add_component():
https://cmake.org/cmake/help/latest/module/CPackComponent.html


I'm not sure what specifically I should be looking for.

In general my setup is working fine, i.e. my build generates multiple 
packages as expected. They even contain dependencies to external 
packages, as I have set as per the available variables. What I haven't 
been able to express is the component inter-dependency. That is, I 
haven't found a way to make my "development" package depend on the 
"runtime" package (generated from the same build process).


Sorry for being obtuse.

Stefan

--

  ...ich hab' noch einen Koffer in Berlin...


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] HOWTO declare component inter-dependencies in multi-component packages

2019-10-03 Thread Kyle Edwards via CMake
On Thu, 2019-10-03 at 16:15 -0400, stefan wrote:
> I'm trying to generate (debian) packages for a project of mine using
> cmake. I need to generate multiple components ("runtime",
> "development", etc.). What is the expected way to have the
> "development" package depend on the "runtime" package ?
> I'v been trying to play with the
> CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS setting, but so far wasn't able
> to have my packages contain the expected dependencies in their
> metadata.
> Thanks,

Please take a look at cpack_add_component():

https://cmake.org/cmake/help/latest/module/CPackComponent.html

Kyle
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[CMake] HOWTO declare component inter-dependencies in multi-component packages

2019-10-03 Thread stefan
I'm trying to generate (debian) packages for a project of mine using 
cmake. I need to generate multiple components ("runtime", "development", 
etc.). What is the expected way to have the "development" package depend 
on the "runtime" package ?


I'v been trying to play with the CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS 
setting, but so far wasn't able to have my packages contain the expected 
dependencies in their metadata.


Thanks,


Stefan

--

  ...ich hab' noch einen Koffer in Berlin...


-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[CMake] Use interface libraries for providing compile options and definitions

2019-10-03 Thread Dustyn Blasig
Hi All,

I have been cleaning up our legacy CMake to use newer features (available
in 3.12+) including trying to use target_...() functions nearly
exclusively. As part of this, I was toying with cleaning up our use cases
for adding compiler flags and similar definitions using real targets and
target_link_libraries.

For instance, as a simple example, let's say I wanted to add/provide a
definition MY_FLAG, I could do something like...

```
add_library(my_flag INTERFACE)
target_compile_definitions(my_flag INTERFACE MY_FLAG=1)

add_library(other_library SHARED ...)
target_link_libraries(other_library ... *PRIVATE *my_flag)

export/install rules
```

I want this library to be private to my component, and it's only used under
the PRIVATE banner. However, the issue I'm running into is with the
install/export rules. I get an error similar to ...

```
CMake Error: install(EXPORT "MY_PROJECT" ...) includes target
"other_library" which requires target "my_flag" that is not in the export
set.
```

If my_flag is defined in my component, I can add it to the export set
perhaps to workaround the issue, but in many cases, it would be coming from
a helper script in another sub-project I'm fetching using FetchContent and
don't want to expose the functionality via my export scripts.

(1) Is it recommended to use interface libraries to clean up compile
defintions, etc.
(2) Should it be possible to link privately such libraries and not have the
export functionality complain?

Thanks!
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake