[CMake] Disabling exceptions and rtti on VS
David Cole
david.cole at kitware.com
Fri Dec 31 09:53:31 EST 2010
Don't use add_definitions for stuff that aren't "definitions" --
add_definitions should only be used for -D flags to the compiler. It
is a long-standing accidental side effect that you can pass compiler
flags through there, but you shouldn't. Instead, as John already
pointed out in his reply, you should manipulate CMAKE_CXX_FLAGS(_*)
variables (and possibly the _C_ variants as well).
Something like this (sample CMakeLists.txt file) -- see the bottom for
replacing the "/EHsc" with "/EHs-c-" :
cmake_minimum_required(VERSION 2.8)
project(ShowCxxFlags)
message(STATUS "One of the following *should* be empty:")
message(STATUS "CMAKE_CONFIGURATION_TYPES='${CMAKE_CONFIGURATION_TYPES}'")
message(STATUS "CMAKE_BUILD_TYPE='${CMAKE_BUILD_TYPE}'")
message(STATUS " (but if not, CMAKE_BUILD_TYPE is only used by
Makefile generators)")
message(STATUS "")
message(STATUS "CMAKE_CXX_FLAGS always applies:")
message(STATUS "CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}'")
message(STATUS "")
if(CMAKE_BUILD_TYPE)
if(CMAKE_GENERATOR MATCHES "Make")
message(STATUS "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE} applies:")
message(STATUS
"CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}='${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}'")
message(STATUS "")
endif()
endif()
if(CMAKE_CONFIGURATION_TYPES)
message(STATUS "One of the following applies, based on user's choice
of 'Configuration' at build time:")
foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${cfg}" UCFG)
message(STATUS "CMAKE_CXX_FLAGS_${UCFG}='${CMAKE_CXX_FLAGS_${UCFG}}'")
endforeach()
message(STATUS "")
endif()
if(CMAKE_CXX_FLAGS MATCHES "/EHsc ")
string(REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS matches /EHsc before end of string
-- replaced...")
message(STATUS "")
endif()
if(CMAKE_CXX_FLAGS MATCHES "/EHsc$")
string(REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS matches /EHsc at end of string --
replaced...")
message(STATUS "")
endif()
message(STATUS "CMAKE_CXX_FLAGS after possible REPLACE operation:")
message(STATUS "CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}'")
message(STATUS "")
On Fri, Dec 31, 2010 at 9:27 AM, Óscar Fuentes <ofv at wanadoo.es> wrote:
> If /EHs- /EHs-c- are added with add_definitions, the output of the build
> contains warnings:
>
> cl : Command line warning D9025 : overriding '/EHs' with '/EHs-'
> cl : Command line warning D9025 : overriding '/EHc' with '/EHc-'
>
> This is because cmake automatically adds /EHsc to the command line
> options.
>
> How can I remove /EHsc from the command line options before adding
> /EHs-c- ?
>
> _______________________________________________
> 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
>
More information about the CMake
mailing list