From: Andres Mejia Date: Fri, 1 Feb 2013 00:20:34 +0000 (-0500) Subject: Add CMake option to explicitly enable/disable /SAFESEH linker flag for Visual Studio... X-Git-Tag: v3.1.2~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=146a5067ca976b208b4aab06127efdf4ba9096f9;p=thirdparty%2Flibarchive.git Add CMake option to explicitly enable/disable /SAFESEH linker flag for Visual Studio builds. Visual Studio 12 enables this option by default. Enabling /SAFESEH will produce build failures when attempting to link other libraries which were not built with /SAFESEH. This would typically be the case for libraries built using the mingw toolchain, where the option to use structured exception handling is not yet available. The option is used as follows. Setting to "YES" sets "/SAFESEH" linker flag Setting to "NO" sets "/SAFESEH:NO" linker flag Setting to any other value such as "AUTO" won't do anything (set the default linker flag from Visual Studio) --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a77ff513..8ad6504e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,7 @@ OPTION(ENABLE_ACL "Enable ACL support" ON) OPTION(ENABLE_ICONV "Enable iconv support" ON) OPTION(ENABLE_PCREPOSIX "Enable POSIX regular expression support using PCRE" OFF) OPTION(ENABLE_TEST "Enable unit and regression tests" ON) +SET(ENABLE_SAFESEH "AUTO" CACHE STRING "Enable use of /SAFESEH linker flag (MSVC only)") IF(ENABLE_TEST) ENABLE_TESTING() @@ -166,6 +167,18 @@ IF(WIN32) SET(_WIN32_WINNT ${WINVER}) ENDIF(WIN32) +IF(MSVC) + IF(ENABLE_SAFESEH STREQUAL "YES") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH") + SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH") + ELSEIF(ENABLE_SAFESEH STREQUAL "NO") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") + SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO") + ENDIF(ENABLE_SAFESEH STREQUAL "YES") +ENDIF(MSVC) + IF("${CMAKE_C_PLATFORM_ID}" MATCHES "^(HP-UX)$") ADD_DEFINITIONS(-D_XOPEN_SOURCE=500) # Ask wchar.h for mbstate_t ENDIF()