<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-08-23 14:10 GMT+02:00 Jean-Michaël Celerier <span dir="ltr"><<a href="mailto:jeanmichael.celerier@gmail.com" target="_blank">jeanmichael.celerier@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><span class="gmail-"><div>> - 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.<br><br></div></span>I also never understood how to handle this.<br><br></div>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 ? <br></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>I have some similar need.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div></div><div><br></div>* set(CMAKE_CXX_FLAGS "-fsanitize=address") is "not modern CMake" (and also would be harder to set / unset on specific targets).<br></div>* 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<br></div>* creating a function that would set the correct flags, etc and then call this function for each target is apparently "not modern CMake" either</div></div></div></div></div></blockquote><div><br></div><div>Why is it not "modern" ? You can leverage meta-informations offered by CMake in DIRECTORY and TARGET properties.</div><div><br></div><div>My solution is close to this one, I have written one macro (let's call it myproj_sanitize) which takes as input</div><div>an inclusion REGEX for exe, an inclusion REGEX for lib, an exclusion REGEX for exe/lib.</div><div>So that you only have a single call (near the end of the main CMakeLists.txt where I know every targets have been defined)</div><div><br></div><div><div>myproj_sanitize(</div><div>    EXCLUDE_EXE_REGEX ""</div><div>    INCLUDE_EXE_REGEX ""</div><div>    EXCLUDE_LIB_REGEX ""</div><div>    INCLUDE_LIB_REGEX ""</div><div>              )</div></div><div><br></div><div>The algorihtm of this macros is simple:</div><div><br></div><div>S1) collect all SHARED and STATUS LIBRARY and EXECUTABLES targets</div><div>      by </div><div>      examining the BUILDSYSTEM_TARGETS directory property</div><div>      and looping over all directories from the main one.</div><div>      At the end of this step I have 2 lists one for executable one for library</div><div><br></div><div>S2) apply exclusion and inclusion regexes for the one which are not empty.</div><div><br></div><div>S3) Call add_sanitizer (from <a href="https://github.com/arsenm/sanitizers-cmake">https://github.com/arsenm/sanitizers-cmake</a>)</div><div>      on the remaining targets.</div><div><br></div><div>I can can easily share the code of the step S1 of the macro. Once we have a mean</div><div>to get the list of concerned targets the remaining part is easy.</div><div><br></div><div>I was afraid of the collect processing time because the concerned project has 500+ libraries</div><div>and 800+ executables but  this is done in a couple of seconds and this is only done</div><div>when compiling in "sanitize" mode which is not ON by default.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><div>.<br></div><div>* creating and linking to "dummy" INTERFACE targets with the flags and properties I want have an awful lot of limitations</div><div><br></div>So what is the right course of actions here ? <br><br></div>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<br></div><div><br></div><div>    add_group(PluginGroup)<br></div><div>    target_compile_definitions(Plu<wbr>ginGroup -DBLAH)</div><div>    set_property(GROUP PluginGroup PROPERTIES /* whatever in cmake-properties*/)<br></div>    set_group(myTarget PluginGroup) // applies everything to the target<br></div></div></blockquote><div><br></div><div>I think this approach is already possible with not so much CMake scripting:</div><div><br></div><div>group_add(PluginGroup) --> create a bunch of global properties for internal group machinery.</div><div><br></div><div>G_PluginGroup_targets --> the list of targets belonging to the group</div><div>G_PluginGroup_compile_definitions</div><div>G_PluginGroup_properties --> the list of (property,value) pairs for the group</div><div><br></div><div>group_compile_definitions(Plu<wbr>ginGroup -DBLAH) append to G_PluginGroup_compile_definitions<br></div><div>group_set_properties(PluginGroup PROPERTIES /* whatever in cmake-properties*/) append to G_PluginGroup_properties</div><div><br></div><div>group_set(TARGETS myTarget1 myTarget2) // applies previously defined group things to the concerned targets.</div><div><br></div><div>The "only" limitation would be that you have to define the meta-informations for the groups before using group_set on any</div><div>targets OR you need group_process macro called neat the end of the main CMakeLists.txt</div><div><br></div></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Eric<br></div></div></div></div></div>
</div></div>