]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add CMake option to explicitly enable/disable /SAFESEH linker flag for Visual Studio...
authorAndres Mejia <amejia004@gmail.com>
Fri, 1 Feb 2013 00:20:34 +0000 (19:20 -0500)
committerAndres Mejia <amejia004@gmail.com>
Fri, 1 Feb 2013 00:20:34 +0000 (19:20 -0500)
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)

CMakeLists.txt

index 6a77ff5139b431039e752b14317a1de21dbd2a96..8ad6504e60ef580946921b0330abe63d707494ff 100644 (file)
@@ -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()