[CMake] Changing link flags for one target

Marc CHEVRIER marc.chevrier at gmail.com
Wed Jul 4 02:45:04 EDT 2018


LINK_FLAGS property do not support generator expressions.

In CMake 3.13, directory and target properties LINK_OPTIONS, supporting
generator expressions, managed by commands add_link_options and
target_link_options are introduced, .

For earlier versions you can use global variables to set flags for all
targets (CMAKE_*_LINKER_FLAGS) and use target property LINK_FLAGS to
override default settings (options specified by LINK_FLAGS are defined
*after* those coming from global variable).


Le mer. 4 juil. 2018 à 05:06, Hendrik Sattler <post at hendrik-sattler.de> a
écrit :

> You could try a generator expression with a custom target property.
>
> Am 4. Juli 2018 04:27:58 MESZ schrieb Andrew White <
> andrew.white at audinate.com>:
> >In my cross-compile environment for an embedded platform, I need to set
> >the stack size for each executable.  The linker flag to set the stack
> >size is (for example) "-Wl,-elf2flt='-s 20000'".
> >
> >Is there an easy way to set this flag for every executable except one,
> >for which I set "-Wl,-elf2flt='-s 40000'"?  Obviously I can call
> >       Set_target_properties(<target> PROPERTIES LINK_FLAGS
> "-Wl,-elf2flt='-s
> >20000'")
> >on each target, but is there a mechanism to make this the default and
> >then set a different value on a single target?
> >
> >If necessary, I suspect "-Wl,-elf2flt='-s 20000' -Wl,-elf2flt='-s
> >40000'" will produce the correct result.
> >* can I avoid doing it like this?
> >* how can I be sure that the more specific option will follow the
> >general one?
> >
> >(Assume all the targets are added via add_subdirectory commands that
> >are common across multiple platforms, and that I'm adding
> >platform-specific build rules in the project CMakeLists.txt)
> >
> >Thanks
> >
> >--
> >Andrew
> --
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180704/5492d799/attachment.html>


More information about the CMake mailing list