MantisBT - CMake
View Issue Details
0016029CMakeCMakepublic2016-03-22 10:292016-06-10 14:21
stw_sesa 
geoffviola 
normalminoralways
closedfixed 
x86_64Windows7
CMake 3.5 
CMake 3.6CMake 3.6 
0016029: GHS Generator does not support LINK_FLAGS property
The GHS Generator ignores the LINK_FLAGS property of targets.

It can be set with:
set_target_properties(<target> PROPERTIES LINK_FLAGS <link_flags>)


I did not test it, but other target properties are probably ignored as well. See https://cmake.org/cmake/help/v3.5/manual/cmake-properties.7.html#target-properties [^] for a complete list (for all Generators).
add_executable(MyExampleApp main.cpp)
set_target_properties(MyExampleApp PROPERTIES LINK_FLAGS "--myflag")

The option "--myflag" is ignored and not added in the project file (MyExampleApp.gpj).
I've attached a patch that implements the functionality, but I'm sure it needs some generalization and optimization to integrate it.
No tags attached.
patch 0001-LINK_FLAGS-property-implementation.patch (1,017) 2016-03-22 10:29
https://public.kitware.com/Bug/file/5653/0001-LINK_FLAGS-property-implementation.patch
zip LinkFlags.zip (447) 2016-03-26 19:38
https://public.kitware.com/Bug/file/5658/LinkFlags.zip
patch 0001-Grenn-Hills-MULTI-linker-flags-implementation.patch (1,026) 2016-03-26 19:39
https://public.kitware.com/Bug/file/5659/0001-Grenn-Hills-MULTI-linker-flags-implementation.patch
zip LinkFlags2.zip (704) 2016-03-26 23:31
https://public.kitware.com/Bug/file/5660/LinkFlags2.zip
patch 0001-GHS-MULTI-lflags-and-dirs-for-non-target-groups.patch (5,284) 2016-03-26 23:32
https://public.kitware.com/Bug/file/5661/0001-GHS-MULTI-lflags-and-dirs-for-non-target-groups.patch
Issue History
2016-03-22 10:29stw_sesaNew Issue
2016-03-22 10:29stw_sesaFile Added: 0001-LINK_FLAGS-property-implementation.patch
2016-03-22 10:34Brad KingAssigned To => geoffviola
2016-03-22 10:34Brad KingStatusnew => assigned
2016-03-22 10:49Brad KingNote Added: 0040743
2016-03-22 12:40stw_sesaNote Added: 0040749
2016-03-26 19:38geoffviolaFile Added: LinkFlags.zip
2016-03-26 19:39geoffviolaFile Added: 0001-Grenn-Hills-MULTI-linker-flags-implementation.patch
2016-03-26 19:42geoffviolaNote Added: 0040760
2016-03-26 23:31geoffviolaFile Added: LinkFlags2.zip
2016-03-26 23:32geoffviolaFile Added: 0001-GHS-MULTI-lflags-and-dirs-for-non-target-groups.patch
2016-03-26 23:44geoffviolaNote Added: 0040761
2016-03-28 10:36Brad KingNote Added: 0040762
2016-03-28 13:27Brad KingNote Added: 0040763
2016-03-29 09:21Brad KingNote Added: 0040767
2016-03-29 09:22Brad KingStatusassigned => resolved
2016-03-29 09:22Brad KingResolutionopen => fixed
2016-03-29 09:22Brad KingFixed in Version => CMake 3.6
2016-03-29 09:22Brad KingTarget Version => CMake 3.6
2016-06-10 14:21Kitware RobotNote Added: 0041211
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0040743)
Brad King   
2016-03-22 10:49   
The other generators have several places that they use to collect link flags. See cmLocalGenerator::GetTargetFlags and its call sites. Also see cmMakefileExecutableTargetGenerator::WriteExecutableRule and cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules.
(0040749)
stw_sesa   
2016-03-22 12:40   
(Just saw I accidentally included an additional quotation mark in the patch, which shouldn't be there; remove: << "\"")
(0040760)
geoffviola   
2016-03-26 19:42   
I tested out the above code with a small Green Hills MULTI CMake project. See LinkFlags.zip. The patch looked close. I adjusted the whitespace, removed the extra quote, and added a const to the pointer. The new patch is 0001-Grenn-Hills-MULTI-linker-flags-implementation.patch.
(0040761)
geoffviola   
2016-03-26 23:44   
I went through the code that Brad mentioned. The GetTargetFlags method seemed useful. It has the advantage of interpreting LINK_FLAGS_<CMAKE_BUILD_TYPE>. Also, it makes adding link directories easy to add.

Unfortunately, GetTargetFlags had some limitations. Unlike link directories, There are no extensions for prepending and appending to generated library names. So the previous implementation of linking to libraries was left. Also, since the Green Hills unique target groups concept is considered a cmState::EXECUTABLE, it would warn the user that there is no linker language, because the only files that it would see are .bsp and .int files. So the target groups do not get link directories or link flags.

LinkFlags2.zip was attached to show a build setup that exercises LINK_FLAGS, link_directories, and LINK_FLAGS_RELEASE. The patch is named 0001-GHS-MULTI-lflags-and-dirs-for-non-target-groups.patch.
(0040762)
Brad King   
2016-03-28 10:36   
Thanks Geoff. Once the conclusion here is that one of the patches is ready for integration please bring it to the dev list as usual.
(0040763)
Brad King   
2016-03-28 13:27   
http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/16121 [^]
(0040767)
Brad King   
2016-03-29 09:21   
Patch applied (split in two pieces):

GHS: Factor out compiler information shared among languages
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=230d50ed [^]

GHS: Implement link flags and dirs for non-target groups
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=36ad8dd4 [^]
(0041211)
Kitware Robot   
2016-06-10 14:21   
This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.