[CMake] Override of link flag for one specific shared library

Martin Apel martin.apel at simpack.de
Thu Sep 4 02:42:53 EDT 2008


Unfortunately this does not work. It seems that CMake generates all
libraries defined in one CMakeLists.txt with the setting of
CMAKE_SHARED_LINKER_FLAGS at the end of the file.
This causes this setting to be applied to all libraries in the
CMakeLists.txt. As I have 4 libraries in this one CMakeLists.txt, this
doesn't help much.

I tried to do something like the following:
SET (CMAKE_SHARED_LINKER_FLAGS "${ORIG_SHARED_LINKER_FLAGS}")
ADD_LIBRARY (FortranInterface ${OBJS})
SET (CMAKE_SHARED_LINKER_FLAGS "${MODIFIED_SHARED_LINKER_FLAGS}")
but the FortranInterface library gets built with
MODIFIED_SHARED_LINKER_FLAGS in effect.

I would suggest to change the order of items in the build rules for a
future CMake release, such that it's possible to override general flags
with a target specific property. Today the link
rules look as follows:
SET(CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_CXX_COMPILER> ...
<LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> ....")


More information about the CMake mailing list