Skip to content

Commit f30699c

Browse files
committed
- manually set cxx flags to avoid conflict between default /W3 and /MT and what we're aiming for (/W4 and /MD)
1 parent 0156704 commit f30699c

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CMakeList.txt : Top-level CMake project file, do global configuration
22
# and include sub-projects here.
33
#
4-
cmake_minimum_required (VERSION 3.8)
4+
cmake_minimum_required (VERSION 3.24)
55

66
set(CMAKE_SYSTEM_VERSION 10.0.10941 CACHE STRING "" FORCE)
77
set(CMAKE_CXX_STANDARD 20)

src/modern_win32/CMakeLists.txt

+32-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CMakeList.txt : CMake project for modern_win32, include source and define
22
# project specific logic here.
33
#
4-
cmake_minimum_required (VERSION 3.8)
4+
cmake_minimum_required (VERSION 3.24)
55

66
set(root_header_files
77
"../../include/modern_win32/access_denied_exception.h"
@@ -68,7 +68,11 @@ set(source_files
6868

6969
# Add source to this project's executable.
7070

71-
add_definitions(-DMODERN_WIN32_EXPORTS -DUNICODE -D_UNICODE)
71+
if (CMAKE_BUILD_TYPE MATCHES "Release")
72+
add_definitions(-DMODERN_WIN32_EXPORTS -DUNICODE -D_UNICODE -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DNDEBUG -D_MBCS -DWIN32 -D_WINDOWS)
73+
else()
74+
add_definitions(-DMODERN_WIN32_EXPORTS -DUNICODE -D_UNICODE -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_DEBUG -D_MBCS)
75+
endif()
7276

7377
add_library(modern_win32 SHARED ${source_files} ${public_header_files})
7478

@@ -80,24 +84,38 @@ generate_export_header(modern_win32)
8084
set_target_properties(modern_win32 PROPERTIES VS_GLOBAL_KEYWORD "Win32Proj")
8185
set_target_properties(modern_win32 PROPERTIES EXPORT_NAME modern_win32)
8286

87+
8388
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
8489
message(status " using msvc compiler")
8590
set(MSVC_TOOLSET_VERSION 143)
8691

87-
if (${USE_SPECTRE} MATCHES "true")
88-
message(status " Spectre is enabled, adding /QSpectre flag")
89-
target_compile_options(modern_win32 PRIVATE /Zi /Qspectre /guard:cf /MP)
90-
target_link_options(modern_win32 PRIVATE /DYNAMICBASE)
91-
92-
else()
93-
message(status " Spectre is not enabled")
94-
#target_compile_options(modern_win32 PRIVATE /Zi /MP)
95-
target_compile_options(modern_win32 PRIVATE /Zi /Qspectre /guard:cf /MP)
96-
target_link_options(modern_win32 PRIVATE /DYNAMICBASE)
97-
endif()
92+
message(status " ${CMAKE_CXX_FLAGS_RELEASE}")
93+
set(CMAKE_CXX_FLAGS "/W4 /GR /GS /EHsc /wd4100 /wd4206 /wd4702 /wd6255 /nologo /diagnostics:column /std:c++20 /Zc:inline /fp:precise /errorReport:prompt /WX- /Zc:forScope /Zc:wchar_t /Zi /Gm- /we4715 /we4172")
94+
set(CMAKE_CXX_FLAGS_RELEASE "/MP /Gy /O2 /Gd /Oi /MD /FC")
95+
set(CMAKE_CXX_FLAGS_DEBUG "/JMC /MP /we4172 /GS /Od /RTC1 /Gd /MDd ")
96+
message(status " after ${CMAKE_CXX_FLAGS}")
97+
message(status " after ${CMAKE_CXX_FLAGS_RELEASE}")
9898

9999
if (CMAKE_BUILD_TYPE MATCHES "Release")
100+
if (${USE_SPECTRE} MATCHES "true")
101+
message(status " Spectre is enabled, adding /QSpectre flag")
102+
target_compile_options(modern_win32 PRIVATE /Qspectre)
103+
104+
target_link_options(modern_win32 PRIVATE /DYNAMICBASE)
105+
106+
else()
107+
message(status " Spectre is not enabled")
108+
endif()
109+
100110
else()
111+
if (${USE_SPECTRE} MATCHES "true")
112+
message(status " Spectre is enabled, adding /QSpectre flag")
113+
target_compile_options(modern_win32 PRIVATE /Qspectre)
114+
115+
target_link_options(modern_win32 PRIVATE /DYNAMICBASE)
116+
else()
117+
message(status " Spectre is not enabled")
118+
endif()
101119
endif()
102120

103121
# Tell linker to include symbol data
@@ -111,8 +129,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
111129
COMPILE_PDB_OUTPUT_DIR ${CMAKE_BINARY_DIR}
112130
)
113131

114-
set_property(TARGET modern_win32 PROPERTY
115-
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
132+
set_property(TARGET modern_win32 PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
116133
endif()
117134

118135
target_include_directories(modern_win32

0 commit comments

Comments
 (0)