[CMake] How to set different compiler flags for two projects in one solution

Tyler Roscoe tyler at cryptio.net
Wed Sep 30 14:08:57 EDT 2009


On Wed, Sep 30, 2009 at 06:18:04PM +0200, Tanguy Krotoff wrote:
> project(rimes_http_request)
> 
> # Statically link with Visual C++ libraries
> if (MSVC)
> 	foreach (MODE "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
> 		string(REPLACE "/MD" "/MT" TMP "${CMAKE_C_FLAGS${MODE}}")
> 		set(CMAKE_C_FLAGS${MODE} "${TMP}" CACHE STRING "" FORCE)
> 		string(REPLACE "/MD" "/MT" TMP "${CMAKE_CXX_FLAGS${MODE}}")
> 		set(CMAKE_CXX_FLAGS${MODE} "${TMP}" CACHE STRING "" FORCE)
> 	endforeach (MODE)
> endif (MSVC)
> ##
> 
> add_library(rimes_http_request SHARED rimes_http_request.cpp)
> 
> # Revert to standard CMake Visual C++ flags
> # This does not work, command line for rimes_http_request still
> contains /MD instead of /MT
> # If I remove this part, all my projects get compiled with flag /MT
> if (MSVC)
> 	foreach (MODE "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
> 		string(REPLACE "/MT" "/MD" TMP "${CMAKE_C_FLAGS${MODE}}")
> 		set(CMAKE_C_FLAGS${MODE} "${TMP}" CACHE STRING "" FORCE)
> 		string(REPLACE "/MT" "/MD" TMP "${CMAKE_CXX_FLAGS${MODE}}")
> 		set(CMAKE_CXX_FLAGS${MODE} "${TMP}" CACHE STRING "" FORCE)
> 	endforeach (MODE)
> endif (MSVC)
> ##

So the first change, where you change from /MD to /MT, does work, but
the second change, where you change /MT back to /MD, does not work?

When I do this trick, I don't mess with the value in the cache; I just
change CMAKE_C_FLAGS. So maybe remove the CACHE parts and see if that
helps?

tyler


More information about the CMake mailing list