MantisBT - CMake
View Issue Details
0010768CMakeCMakepublic2010-05-27 13:442012-12-07 10:44
Fraser Hutchison 
Brad King 
normalfeaturealways
closedfixed 
CMake-2-8 
 
0010768: Request STATIC_LIBRARY_FLAGS_<build type> variable for use by MSVC
I'd like to pass flags to build-specific static library targets (e.g. "/LTCG" to only Release build of my static lib). The only way to pass additional flags to the Librarian Command Line is by setting STATIC_LIBRARY_FLAGS, but this adds the flags to all build types.
No tags attached.
related to 0010094closed Patrick R. Gansterer Add support for CMAKE_STATIC_LINKER_FLAGS variable to set librarian flags 
patch static_lib_flags.patch (4,539) 2010-05-28 00:04
https://public.kitware.com/Bug/file/3149/static_lib_flags.patch
Issue History
2010-05-27 13:44Fraser HutchisonNew Issue
2010-05-27 14:56Bill HoffmanStatusnew => assigned
2010-05-27 14:56Bill HoffmanAssigned To => Brad King
2010-05-28 00:04Fraser HutchisonFile Added: static_lib_flags.patch
2010-05-28 00:05Fraser HutchisonNote Added: 0020850
2010-05-28 08:27Brad KingNote Added: 0020853
2010-05-28 08:40Fraser HutchisonNote Added: 0020855
2010-05-28 11:35Brad KingNote Added: 0020858
2010-05-28 13:33Brad KingNote Added: 0020859
2010-05-28 14:30Fraser HutchisonNote Added: 0020860
2010-06-07 16:15Brad KingNote Added: 0020936
2010-06-07 16:15Brad KingStatusassigned => closed
2010-06-07 16:15Brad KingResolutionopen => fixed
2012-12-07 10:44Brad KingRelationship addedrelated to 0010094

Notes
(0020850)
Fraser Hutchison   
2010-05-28 00:05   
The uploaded patch works for me on Win 7 with MSVC 2008 Express. I don't have access to MSVC 6 or 10 so I haven't amended cmLocalVisualStudio6Generator.cxx or cmVisualStudio10TargetGenerator.cxx.

Please look at the 2nd and 3rd changes I made to cmLocalGenerator.cxx; these aren't related to this feature request, but looked like bugs me. If I'm wrong, then my 1st change in this file is probably wrong too :-)

Also in cmLocalGenerator.cxx at the same places, it looks like per-config LINK_FLAGS are only considered if LINK_FLAGS is not empty. I matched this behaviour in my patch, but I'm not sure this is desired behaviour - should per-config flags not be added regardless of defining universal flags?
(0020853)
Brad King   
2010-05-28 08:27   
The references to LINK_FLAGS and STATIC_LINK_FLAGS in cmLocalGenerator.cxx are not used in any real generators and need not be updated for this change. They are left from an experimental feature that was never finished AFAIK. If the code were actually used then the bugs you spotted would be real bugs. As a separate task I may look at removing this whole chunk of code for cleanup purposes.

I have changes almost ready for all generators. Unfortunately this is very hard to test because there is no link flag that will be accepted by all linkers. Therefore any test needs to be customized for each platform :(
(0020855)
Fraser Hutchison   
2010-05-28 08:40   
The joys of cross-platform testing :-)

Lemme know if I can help - I've only got access to MSVC 2008 on Win 7 or Xp, and CodeBlocks on Win7, Xp, Ubuntu and Fedora.

My gmail address is fraser.hutchison
(0020858)
Brad King   
2010-05-28 11:35   
I decided to test this by adding bogus flags and regex-matching the errors in the output.

I've published a series of four commits to fix up LINK_FLAGS_<CONFIG>, test LINK_FLAGS and STATIC_LIBRARY_FLAGS, and add support for STATIC_LIBRARY_FLAGS_<CONFIG>. The topic has been merged into next:

http://cmake.org/gitweb?p=cmake.git;a=shortlog;h=be834bac [^]
(0020859)
Brad King   
2010-05-28 13:33   
I pushed support for STATIC_LIBRARY_FLAGS in Xcode, which was previously missing:

http://cmake.org/gitweb?p=cmake.git;a=shortlog;h=c81d128e [^]
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5c49aa0c [^]
(0020860)
Fraser Hutchison   
2010-05-28 14:30   
Great!

Thanks for implementing this so quickly.
(0020936)
Brad King   
2010-06-07 16:15   
This topic has been merged to 'master' for inclusion in the next release.