[CMake] Interface Libraries allow include directories but not link directories.. Why?

Eric Noulard eric.noulard at gmail.com
Wed Aug 23 10:27:19 EDT 2017


2017-08-23 15:28 GMT+02:00 Clément Gregoire <lectem at gmail.com>:

>     set_property(GROUP PluginGroup PROPERTIES /* whatever in
>> cmake-properties*/)
>>
>>     set_group(myTarget PluginGroup) // applies everything to the target
>
>
> Isn't it the same as having a custom target/library for the group and
> linking it with transitive properties ?
>

You mean an INTERFACE library?

For a simple set of targets properties like compile flags, probably yes.
If the set of properties to be applied to the group (of targets) contains
more information than the one
conveyed through an INTERFACE library no.

For example property "C_STANDARD"
https://cmake.org/cmake/help/v3.7/prop_tgt/C_STANDARD.html
is not conveyed by transitive linking/compiling.

INTERFACE library convey "only" INTERFACE_xxxx properties to targets
linking to them.

Eric


>
> 2017-08-23 14:51 GMT+02:00 Eric Noulard <eric.noulard at gmail.com>:
>
>>
>>
>> 2017-08-23 14:10 GMT+02:00 Jean-Michaël Celerier <
>> jeanmichael.celerier at gmail.com>:
>>
>>> > - Says that custom functions such as add_{project}_library shouldn't
>>> be used and function definitions should be used as little as possible.
>>> Except this just leads to extremely verbose CMakeLists where repeated
>>> properties are defined again and again and again.
>>>
>>> I also never understood how to handle this.
>>>
>>> I have a project where I want to define, say, -fsanitize=address,
>>> -DFOO_BAR and the SUFFIX property on a specific set of 25 targets amongst
>>> ~100 targets. What am I to do ?
>>>
>>
>> I have some similar need.
>>
>>
>>>
>>> * set(CMAKE_CXX_FLAGS "-fsanitize=address") is "not modern CMake" (and
>>> also would be harder to set / unset on specific targets).
>>> * calling target_compile_options(...) 25 times ... well I mean, everyone
>>> knows it's bad to duplicate code. Especially if the change is meant to be
>>> only when a specific option() is enabled, or for debugging purposes
>>> * creating a function that would set the correct flags, etc and then
>>> call this function for each target is apparently "not modern CMake" either
>>>
>>
>> Why is it not "modern" ? You can leverage meta-informations offered by
>> CMake in DIRECTORY and TARGET properties.
>>
>> My solution is close to this one, I have written one macro (let's call it
>> myproj_sanitize) which takes as input
>> an inclusion REGEX for exe, an inclusion REGEX for lib, an exclusion
>> REGEX for exe/lib.
>> So that you only have a single call (near the end of the main
>> CMakeLists.txt where I know every targets have been defined)
>>
>> myproj_sanitize(
>>     EXCLUDE_EXE_REGEX ""
>>     INCLUDE_EXE_REGEX ""
>>     EXCLUDE_LIB_REGEX ""
>>     INCLUDE_LIB_REGEX ""
>>               )
>>
>> The algorihtm of this macros is simple:
>>
>> S1) collect all SHARED and STATUS LIBRARY and EXECUTABLES targets
>>       by
>>       examining the BUILDSYSTEM_TARGETS directory property
>>       and looping over all directories from the main one.
>>       At the end of this step I have 2 lists one for executable one for
>> library
>>
>> S2) apply exclusion and inclusion regexes for the one which are not empty.
>>
>> S3) Call add_sanitizer (from https://github.com/arsenm/sanitizers-cmake)
>>       on the remaining targets.
>>
>> I can can easily share the code of the step S1 of the macro. Once we have
>> a mean
>> to get the list of concerned targets the remaining part is easy.
>>
>> I was afraid of the collect processing time because the concerned project
>> has 500+ libraries
>> and 800+ executables but  this is done in a couple of seconds and this is
>> only done
>> when compiling in "sanitize" mode which is not ON by default.
>>
>> .
>>> * creating and linking to "dummy" INTERFACE targets with the flags and
>>> properties I want have an awful lot of limitations
>>>
>>> So what is the right course of actions here ?
>>>
>>> Ideally I'd like to add "groups" to targets; e.g. "target Foo is a
>>> plugin for $software", "target Bar is an integration test" and set
>>> per-group options, flags, properties, etc. Like
>>>
>>>     add_group(PluginGroup)
>>>     target_compile_definitions(PluginGroup -DBLAH)
>>>     set_property(GROUP PluginGroup PROPERTIES /* whatever in
>>> cmake-properties*/)
>>>     set_group(myTarget PluginGroup) // applies everything to the target
>>>
>>
>> I think this approach is already possible with not so much CMake
>> scripting:
>>
>> group_add(PluginGroup) --> create a bunch of global properties for
>> internal group machinery.
>>
>> G_PluginGroup_targets --> the list of targets belonging to the group
>> G_PluginGroup_compile_definitions
>> G_PluginGroup_properties --> the list of (property,value) pairs for the
>> group
>>
>> group_compile_definitions(PluginGroup -DBLAH) append
>> to G_PluginGroup_compile_definitions
>> group_set_properties(PluginGroup PROPERTIES /* whatever in
>> cmake-properties*/) append to G_PluginGroup_properties
>>
>> group_set(TARGETS myTarget1 myTarget2) // applies previously defined
>> group things to the concerned targets.
>>
>> The "only" limitation would be that you have to define the
>> meta-informations for the groups before using group_set on any
>> targets OR you need group_process macro called neat the end of the main
>> CMakeLists.txt
>>
>> --
>> Eric
>>
>> --
>>
>> 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:
>> http://public.kitware.com/mailman/listinfo/cmake
>>
>
>


-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170823/d1e1affc/attachment.html>


More information about the CMake mailing list