[CMake] How too set properties on all executables

Yuri Timenkov yuri at timenkov.ru
Fri Feb 25 04:08:30 EST 2011


Is changing global compiler/linker flags for all executables an option?

When you enable "show advanced options" in CMake, you should see them as
CMAKE_EXE_LINKER_FLAGS_<CONFIG>.

Also, if you want to set them initially by your build system, use

set(CMAKE_USER_MAKE_RULES_OVERRIDE MyInitialFlags)

This "MyInitialFlags.cmake" is processed after compiler is determined and
you can modify flags. But note, that they have "_INIT" suffix. For example,

if(WIN32)
    set(CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT
"${CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT} /SUBSYSTEM:WINDOWS")
endif()

Later the cache will be populated from these _INIT variables (when you call
project() or enable_language() command).

On Thu, Feb 24, 2011 at 11:34 PM, Hanna Symanska <hsymanska at gmail.com>wrote:

> Hey,
> I have a fairly large project with multiple executables, about 90 to
> be exact and I would like to set the subsystem based on the
> LINK_FLAGS_* property.
> Is there a way for me to globally set this up in a top level
> CMakeLists.txt file so that i do not have to place the below code in
> every single project.
> add_executable(project_n ....)
> IF (WIN32)
>   SET_TARGET_PROPERTIES(project_n PROPERTIES LINK_FLAGS_RELEASE
> "/INCREMENTAL:NO /NODEFAULTLIB:LIBCMT.lib /SUBSYSTEM:WINDOWS" )
>   SET_TARGET_PROPERTIES(project_n PROPERTIES LINK_FLAGS_RELWITHDEBINFO
> "/NODEFAULTLIB:LIBCMT.lib /SUBSYSTEM:WINDOWS" )
>   SET_TARGET_PROPERTIES(project_n PROPERTIES LINK_FLAGS_DEBUG
> "/NODEFAULTLIB:LIBCMTD.lib /SUBSYSTEM:CONSOLE" )
> ENDIF (WIN32)
>
> As it stands right now I have a top level CMakeLists.txt file with
> several other CMakeLists.txt files in subsequent directories.
> I have 1 CMakeLists.txt per project executable. I am trying to avoid
> putting the above code in EVERY CMakeLists.txt file, when the only
> thing I am changing is the target to reflect the the project that I am
> setting the properties on.
> I am using CMake 2.8.4 to generate visual studio 2008 project files to
> be compiled 64-bit.
> I do not want to use set_executable(project_n WIN32...) because I want
> the subsystem to be console for projects that are being compiled as
> debug.
> - Hanna
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110225/6ba1ee02/attachment.htm>


More information about the CMake mailing list