summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2017-01-13 17:45:01 -0800
committerGitHub <noreply@github.com>2017-01-13 17:45:01 -0800
commiteafc06f8cf2b815d151b67c67086f33b3dae6b8b (patch)
treed6b99f10cffe0bafd574873d0e1c28b3073b4018
parent370029bf981bee0c88dfdc7b9f4739959a1b8c05 (diff)
downloadbinaryen-eafc06f8cf2b815d151b67c67086f33b3dae6b8b.tar.gz
binaryen-eafc06f8cf2b815d151b67c67086f33b3dae6b8b.tar.bz2
binaryen-eafc06f8cf2b815d151b67c67086f33b3dae6b8b.zip
Allow release builds with asserts on windows (#882)
The posix build enables assertions on release builds with ADD_NONDEBUG_COMPILE_FLAG("-UNDEBUG") but the windows build does not. This PR adds /UNDEBUG to the release build flags but has the additional complication that /DNDEBUG is added to CFLAGS by CMake by default, and MSVC will warn about having /UFOO after /DFOO on the command line. So we scrub DNDEBUG from CFLAGS as well. Additional windows build cleanups: Disable conversion/truncation warnings Canonicalize flag style to use slashes everywhere instead of mixing MSVC uses /Od (not /O0) to disable optimization
-rw-r--r--CMakeLists.txt24
1 files changed, 21 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1b2c4976d..74471d1e5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -60,11 +60,29 @@ IF(MSVC)
ADD_COMPILE_FLAG("/arch:sse2")
ENDIF()
ADD_COMPILE_FLAG("/wd4146") # Ignore warning "warning C4146: unary minus operator applied to unsigned type, result still unsigned", this pattern is used somewhat commonly in the code.
+ # 4267 and 4244 are conversion/truncation warnings. We might want to fix these but they are currently pervasive.
+ ADD_COMPILE_FLAG("/wd4267")
+ ADD_COMPILE_FLAG("/wd4244")
ADD_COMPILE_FLAG("/WX-")
- ADD_DEBUG_COMPILE_FLAG("/O0")
+ ADD_DEBUG_COMPILE_FLAG("/Od")
ADD_NONDEBUG_COMPILE_FLAG("/O2")
- ADD_COMPILE_FLAG("-D_CRT_SECURE_NO_WARNINGS")
- ADD_COMPILE_FLAG("-D_SCL_SECURE_NO_WARNINGS")
+ ADD_COMPILE_FLAG("/D_CRT_SECURE_NO_WARNINGS")
+ ADD_COMPILE_FLAG("/D_SCL_SECURE_NO_WARNINGS")
+
+ ADD_NONDEBUG_COMPILE_FLAG("/UNDEBUG") # Keep asserts.
+ # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
+ if( NOT CMAKE_BUILD_TYPE MATCHES "Debug" )
+ foreach (flags_var_to_scrub
+ CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS_MINSIZEREL
+ CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_C_FLAGS_MINSIZEREL)
+ string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
+ "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
+ endforeach()
+ endif()
IF(RUN_STATIC_ANALYZER)
ADD_DEFINITIONS(/analyze)