@@ -74,6 +74,18 @@ if(WIN32)
7474 )
7575endif ()
7676
77+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR MAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
78+ set (DEFAULT_COMPILE_DEFINITIONS
79+ ${DEFAULT_COMPILE_DEFINITIONS}
80+ DEBUG
81+ )
82+ else ()
83+ set (DEFAULT_COMPILE_DEFINITIONS
84+ ${DEFAULT_COMPILE_DEFINITIONS}
85+ NDEBUG
86+ )
87+ endif ()
88+
7789#
7890# Compile options
7991#
@@ -91,34 +103,41 @@ if(WIN32)
91103 #add_compile_options(/ZH:SHA_256) # use SHA256 for generating hashes of compiler processed source files.
92104
93105 # Release
94- if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
95- # TODO: Review debug optimization
96- #add_compile_options(/GL) # Enable debugging information
106+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
107+ # Disable optimizations
108+ add_compile_options (/Od)
109+
110+ # Multithread MSV CTR
111+ add_compile_options (/MDd)
112+
97113 ##add_compile_options(/LTCG) # Enable debugging information
98114 else ()
99115 add_compile_options (/GS) # Buffer Security Check
100116 add_compile_options (/GF) # Enable read-only string pooling
101- #add_compile_options(/GW) # Enable read-only string pooling
117+ add_compile_options (/GW) # Enable read-only string pooling
118+
119+ # Multithread MSV CTR
120+ add_compile_options (/MD )
121+
122+ # Enable optimizations
123+ add_compile_options (/O2)
124+ add_compile_options (/Ob)
125+ add_compile_options (/Og)
126+ add_compile_options (/Oi)
127+ add_compile_options (/Oy)
102128 endif ()
103129endif ()
104130
105131if (PROJECT_OS_FAMILY MATCHES "unix" )
106132
107133 if (APPLE )
108134 # We cannot enable "stack-protector-strong" On OS X due to a bug in clang compiler (current version 7.0.2)
109- if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
110- add_compile_options (-fstack-protector)
111- endif ()
112135
113136 # Enable threads in OS X
114137 add_compile_options (-pthread)
115138
116139 # clang options only
117140 add_compile_options (-Wreturn-stack-address)
118- else ()
119- if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
120- add_compile_options (-fstack-protector-strong)
121- endif ()
122141 endif ()
123142
124143 if (PROJECT_OS_LINUX)
@@ -128,6 +147,14 @@ if (PROJECT_OS_FAMILY MATCHES "unix")
128147
129148 # All warnings that are not explicitly disabled are reported as errors
130149 #add_compile_options(-Werror)
150+ add_compile_options (-Wall)
151+ add_compile_options (-Wextra)
152+
153+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
154+ add_compile_options (-g)
155+ else ()
156+ add_compile_options (-O3)
157+ endif ()
131158
132159 # Sanitizers
133160 if (OPTION_BUILD_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" ))
@@ -153,7 +180,7 @@ endif()
153180set (DEFAULT_LINKER_OPTIONS)
154181
155182# Use pthreads on mingw and linux
156- if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "GNU" OR "${CMAKE_SYSTEM_NAME} " MATCHES "Linux" )
183+ if (( "${CMAKE_C_COMPILER_ID} " MATCHES "GNU" AND " ${ CMAKE_CXX_COMPILER_ID} " MATCHES "GNU" ) OR "${CMAKE_SYSTEM_NAME} " MATCHES "Linux" )
157184 set (DEFAULT_LINKER_OPTIONS
158185 -pthread
159186 )
0 commit comments