[CMake] Setting global link flags

Axel Roebel Axel.Roebel at ircam.fr
Wed Oct 11 07:14:14 EDT 2006


Hello,

I frequently struggle with the problem to set
global linker flags. Global here means these flags should be used 
whenever the linker is used. The main example where I need that
is the -mno-cygwin flag of the cygwin compiler. 
This flag creates objects that will not make use of the cygwin dll.
It has to be present during compilation and linking.

So for compilation I use

ADD_DEFINITION(-mno-cygwin)

for the linker there seems nothing equivalent

I tried
      SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -mno-cygwin")
      SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -mno-cygwin")

but I found that those are not used
for all  targets (dlls and executables)
So my guess is I would probably need to set 
  
     SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_CXX_LINK_FLAGS} -mno-cygwin")
     SET(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_C_LINK_FLAGS} -mno-cygwin")

To summarize, my questions are:

1) is this the correct way to select link flags for all excutables and shared 
libraries?
 
      SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -mno-cygwin")
      SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -mno-cygwin")
     SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_CXX_LINK_FLAGS} -mno-cygwin")
     SET(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_C_LINK_FLAGS} -mno-cygwin")
2)
I wonder about the mapping of the build command tags and cmake variables
In every build command I find the <LINK_FLAGS> tag.
I don't see any variable of that name though, could I simply do?

   SET(LINK_FLAGS "${LINK_FLAGS} -mno-cygwin")
   
Thanks
-- 
Axel Roebel
IRCAM Analysis/Synthesis Team
Phone: ++33-1-4478 4845 | Fax: ++33-1-4478 1540


More information about the CMake mailing list