@@ -16,7 +16,7 @@ if(CMAKE_CONFIGURATION_TYPES)
1616 set (CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES} " CACHE STRING "Reset the configurations to what we need" FORCE)
1717endif ()
1818
19- IF ( MSVC_IDE ) # Check for Visual Studio
19+ IF ( MSVC ) # Check for Visual Studio
2020
2121 #1800 = VS 12.0 (v120 toolset)
2222 #1900 = VS 14.0 (v140 toolset)
@@ -30,25 +30,27 @@ IF( MSVC_IDE ) # Check for Visual Studio
3030 file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR} /Output/system" )
3131 file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR} /Output/c_api" )
3232
33- IF (CMAKE_GENERATOR_TOOLSET STREQUAL "v141_clang_c2" )
34- #1900 is reported
35- message ("v141_clang_c2 toolset was specified via -T. Reported MSVC_VERSION is: ${MSVC_VERSION} " )
36- set (CLANG_IN_VS "1" )
37- ENDIF ()
33+ IF (MSVC_IDE )
34+ IF (CMAKE_GENERATOR_TOOLSET STREQUAL "v141_clang_c2" )
35+ #1900 is reported
36+ message ("v141_clang_c2 toolset was specified via -T. Reported MSVC_VERSION is: ${MSVC_VERSION} " )
37+ set (CLANG_IN_VS "1" )
38+ ENDIF ()
3839
39- # We want our project to also run on Windows XP
40- # 1900 (VS2015) is not supported but we leave here
41- IF (MSVC_VERSION VERSION_LESS 1910 )
42- IF (NOT CLANG_IN_VS STREQUAL "1" )
43- set (CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2015
44- # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
45- add_definitions ("/Zc:threadSafeInit-" )
46- ENDIF ()
47- ELSE ()
48- IF (NOT CLANG_IN_VS STREQUAL "1" )
49- set (CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2017
50- # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
51- add_definitions ("/Zc:threadSafeInit-" )
40+ # We want our project to also run on Windows XP
41+ # 1900 (VS2015) is not supported but we leave here
42+ IF (MSVC_VERSION VERSION_LESS 1910 )
43+ IF (NOT CLANG_IN_VS STREQUAL "1" )
44+ set (CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2015
45+ # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
46+ add_definitions ("/Zc:threadSafeInit-" )
47+ ENDIF ()
48+ ELSE ()
49+ IF (NOT CLANG_IN_VS STREQUAL "1" )
50+ set (CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2017
51+ # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics
52+ add_definitions ("/Zc:threadSafeInit-" )
53+ ENDIF ()
5254 ENDIF ()
5355 ENDIF ()
5456
@@ -58,28 +60,33 @@ IF( MSVC_IDE ) # Check for Visual Studio
5860 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-inconsistent-missing-override" )
5961 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override" )
6062 ELSE ()
61- # Enable C++ with SEH exceptions
62- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /EHa" )
63- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHa" )
64- # or add_compile_options( /EHa ) for CMake>=3?
63+ # Enable C++ with SEH exceptions
64+ # Avoid an obnoxious 'overrriding /EHsc with /EHa' warning when
65+ # using something other than MSBuild
66+ STRING ( REPLACE "/EHsc" "/EHa" CMAKE_C_FLAGS "${CMAKE_C_FLAGS} " )
67+ STRING ( REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} " )
6568 ENDIF ()
6669 # Prevent VC++ from complaining about not using MS-specific functions
6770 add_definitions ("/D _CRT_SECURE_NO_WARNINGS /D _SECURE_SCL=0" )
6871
6972 # Enable CRT heap debugging - only effective in debug builds
7073 add_definitions ("/D _CRTDBG_MAP_ALLOC" )
71-
74+
7275 add_definitions ("/D __SSE2__" )
7376
7477 if (CMAKE_SIZEOF_VOID_P EQUAL 4)
75- # VC++ enables the SSE2 instruction set by default even on 32-bits. Step back a bit.
76- #add_definitions("/arch:SSE")
77- add_definitions ("/arch:SSE2" ) # Better use this one, it's 2017 now, and helps optimizing hbd stuff still in C
78- endif ()
78+ # CPU_ARCH can be overridden with the corresponding values when using MSVC:
79+ # IA32 (disabled),
80+ # SSE (Pentium III and higher, 1999),
81+ # SSE2 (Pentium 4 and higher, 2000/2001),
82+ # AVX (Sandy Bridge and higher, 2011),
83+ # AVX2 (Haswell and higher, 2013)
84+ set (MSVC_CPU_ARCH "SSE2" CACHE STRING "Set MSVC architecture optimization level (default: SSE2)" )
85+ endif ()
7986
8087 # Set additional optimization flags
81- set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy /Ot /GS- /Oi" )
82- set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy /Ot /GS- /Oi" )
88+ set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy /Ot /GS- /Oi /arch: ${MSVC_CPU_ARCH} " )
89+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy /Ot /GS- /Oi /arch: ${MSVC_CPU_ARCH} " )
8390
8491 # Set C++17 flag
8592 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c++17" )
8996 # c++17: if constexpr() and others from gcc 7
9097 SET ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17" ) # or -std=c++17 w/o gnu c++17 extensions
9198 SET ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native" )
99+ SET ( CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-stdcall-fixup" )
92100
93101ENDIF ()
94102
@@ -104,4 +112,4 @@ configure_file(
104112 IMMEDIATE @ONLY)
105113
106114add_custom_target (uninstall
107- COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake)
115+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR} /cmake_uninstall.cmake)
0 commit comments