[CMake] disabling features such as C++

William A. Hoffman billlist at nycap.rr.com
Mon Feb 6 16:09:50 EST 2006


At 03:13 PM 2/6/2006, Reggie Burnett wrote:
>Guys,
>
>Can you tell me how to disable a feature such as exception handling for a
>project under cmake control?  This is on Windows using Visual 7 and 8.
>Looking in the platform files, I see that /EHsc is automatically added to
>the build flags variable but I can't seem to find a good way to remove it.
>
>I've tried the brute force approach like so:
>
># replace /MDd with /MTd
>IF(CMAKE_GENERATOR MATCHES "Visual Studio 7" OR CMAKE_GENERATOR MATCHES
>"Visual Studio 8")
>STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG_INIT
>${CMAKE_CXX_FLAGS_DEBUG_INIT})
>STRING(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG_INIT
>${CMAKE_C_FLAGS_DEBUG_INIT})
>STRING(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
>STRING(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
>STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE
>${CMAKE_CXX_FLAGS_RELEASE})
>STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
>
># remove support for Exception handling
>STRING(REPLACE "/GX" "" CMAKE_CXX_FLAGS_INIT ${CMAKE_CXX_FLAGS_INIT})
>STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_INIT ${CMAKE_CXX_FLAGS_INIT})
>ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio 7" OR CMAKE_GENERATOR MATCHES
>"Visual Studio 8")
>
>However when I print out the variables with this:
>MESSAGE("c init = ${CMAKE_C_FLAGS_INIT}")
>MESSAGE("c debug init = ${CMAKE_C_FLAGS_DEBUG_INIT}")
>MESSAGE("c release = ${CMAKE_C_FLAGS_RELEASE}")
>MESSAGE("c debug = ${CMAKE_C_FLAGS_DEBUG}")
>MESSAGE("c++ init = ${CMAKE_CXX_FLAGS_INIT}")
>MESSAGE("c++ debug init = ${CMAKE_CXX_FLAGS_DEBUG_INIT}")
>MESSAGE("c++ release = ${CMAKE_CXX_FLAGS_RELEASE}")
>MESSAGE("c++ debug = ${CMAKE_CXX_FLAGS_DEBUG}")


The _INIT stuff should not be changed.  It is only used once to initialize the
cache variables CMAKE_CXX_FLAGS*.   You need to change:
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_DEBUG, etc.
Also, these are cache variables, so you will want to FORCE the change, or
preload a cache.

-Bill





More information about the CMake mailing list