diff --git a/CMakeLists.txt b/CMakeLists.txt index feec9199..ccb92124 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,13 +106,17 @@ endif() #Enable or disable exception handling if (NOT ENABLE_EXCEPTIONS) - remove_definitions("-fexceptions") - add_definitions("-fno-exceptions") add_definitions(-D_EXCEPTIONS=0) + if(NOT MSVC) + remove_definitions("-fexceptions") + add_definitions("-fno-exceptions") + endif() else() - remove_definitions("-fno-exceptions") - add_definitions("-fexceptions") add_definitions(-D_EXCEPTIONS=1) + if(NOT MSVC) + remove_definitions("-fno-exceptions") + add_definitions("-fexceptions") + endif() endif() configure_file(${CMAKE_SOURCE_DIR}/version.hpp.cmakein ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/version.hpp @ONLY) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5029ebc1..8bb16de8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,25 @@ if(APPLE) set(CMAKE_OSX_ARCHITECTURES "x86_64") endif() +if(MSVC) + if (NOT ENABLE_EXCEPTIONS) + # support for C/C++ conformant preprocessor in MSVC was added starting with + # version Visual Studio 2019 version 16.6 (equivalent to 1926) + # https://devblogs.microsoft.com/cppblog/announcing-full-support-for-a-c-c-conformant-preprocessor-in-msvc/ + if(MSVC_VERSION GREATER_EQUAL 1926) + remove_definitions("/EHsc /Zc:preprocessor") + else() + remove_definitions("/EHsc /experimental:preprocessor") + endif() + else() + if(MSVC_VERSION GREATER_EQUAL 1926) + add_definitions("/permissive /EHsc /Zc:preprocessor") + else() + add_definitions("/permissive /EHsc /experimental:preprocessor") + endif() + endif() +endif() + SET(CMAKE_EXE_LINKER_FLAGS "/FORCE") FILE(GLOB_RECURSE SRC_LIST *.cpp *_impl.hpp */*_impl.hpp) @@ -38,7 +57,7 @@ if (ENABLE_LOG) target_compile_definitions(${PROJECT_NAME} PUBLIC LIBM2K_ENABLE_LOG) endif() if (MSVC) - add_definitions("/wd4250 /wd4251 /wd4275") + add_definitions("/MD /wd4250 /wd4251 /wd4275 /wd5105") endif() if(NOT MSVC)