Linker flags on all except a couple of programs

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Linker flags on all except a couple of programs

Paul Smith
I have a CMake-based build that creates about 170 binaries (most of them
are individual unit test programs).

I have set the CMAKE_EXE_LINKER_FLAGS to a set of flags I wanted on all
the binaries.

Now it turns out that I need to remove, or not set, one specific flag on
a small number (like 5) of these binaries, but I still want it set on
all the others.  Unfortunately for this flag there's no "turn it off"
extra flag I can add to the end of the list of flags: I have to actually
remove the flag itself.

What's the cleanest/simplest way to accomplish this?  I don't really
want to modify my cmake files to add an explicit set_target_property()
to all 165 binaries that I _do_ want to have this flag set on, just so I
can avoid calling it on the 5 binaries I don't.  I want to add something
particular to the 5 "oddball" binaries, instead, to override these
values.

But I can't seem to come up with a way to remove a flag from a global
list like this, just for one (or a few) targets.


Any hints?
--

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
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL]: Linker flags on all except a couple of programs

Parag Chandra
Have you tried the various string commands?

https://cmake.org/cmake/help/v3.7/command/string.html

I’ve done something similar to replace default linker flags with ones of my own choosing. I bet you could use something like string(REGEX REPLACE …) to essentially remove the unwanted linker flags in each of the 5 projects that needs it. You might even be able to do this once, in a separate .cmake file, as either a function or macro, and then simply include() that .cmake file in each of the 5 projects for better maintenance.

 

Parag Chandra
Technical Lead, Mobile Team
Mobile: +1.919.824.1410

Ionic Security Inc.
1170 Peachtree St. NE STE 400, Atlanta, GA 30309
 

On 1/12/17, 12:49 AM, "CMake on behalf of Paul Smith" <[hidden email] on behalf of [hidden email]> wrote:

    I have a CMake-based build that creates about 170 binaries (most of them
    are individual unit test programs).
   
    I have set the CMAKE_EXE_LINKER_FLAGS to a set of flags I wanted on all
    the binaries.
   
    Now it turns out that I need to remove, or not set, one specific flag on
    a small number (like 5) of these binaries, but I still want it set on
    all the others.  Unfortunately for this flag there's no "turn it off"
    extra flag I can add to the end of the list of flags: I have to actually
    remove the flag itself.
   
    What's the cleanest/simplest way to accomplish this?  I don't really
    want to modify my cmake files to add an explicit set_target_property()
    to all 165 binaries that I _do_ want to have this flag set on, just so I
    can avoid calling it on the 5 binaries I don't.  I want to add something
    particular to the 5 "oddball" binaries, instead, to override these
    values.
   
    But I can't seem to come up with a way to remove a flag from a global
    list like this, just for one (or a few) targets.
   
   
    Any hints?
    --
   
    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
   

--

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
Reply | Threaded
Open this post in threaded view
|

Re: Linker flags on all except a couple of programs

Matthew Woehlke-2
In reply to this post by Paul Smith
On 2017-01-12 00:49, Paul Smith wrote:

> I have a CMake-based build that creates about 170 binaries (most of them
> are individual unit test programs).
>
> I have set the CMAKE_EXE_LINKER_FLAGS to a set of flags I wanted on all
> the binaries.
>
> Now it turns out that I need to remove, or not set, one specific flag on
> a small number (like 5) of these binaries, but I still want it set on
> all the others.  Unfortunately for this flag there's no "turn it off"
> extra flag I can add to the end of the list of flags: I have to actually
> remove the flag itself.
>
> What's the cleanest/simplest way to accomplish this?  I don't really
> want to modify my cmake files to add an explicit set_target_property()
> to all 165 binaries that I _do_ want to have this flag set on, just so I
> can avoid calling it on the 5 binaries I don't.  I want to add something
> particular to the 5 "oddball" binaries, instead, to override these
> values.
>
> But I can't seem to come up with a way to remove a flag from a global
> list like this, just for one (or a few) targets.

I *thought* (but have not checked) that after the target exists, you can
get its link flags as a target property, which you could then adjust as
needed.

Failing that, I think you can remove the flag from the appropriate
global variable, create the target (add_executabe or whatever), then
restore the previous value. If you wrap this in a function, it will
scope the value so you don't even have to worry about restoring it after.

Of course, you could also just wrap all your add_executable calls in a
function that handles the set_target_property dance for you...

Hope this helps!

--
Matthew
--

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