diff --git a/cmake/common_build_flags.cmake b/cmake/common_build_flags.cmake index 0e6839b..f0c87f9 100644 --- a/cmake/common_build_flags.cmake +++ b/cmake/common_build_flags.cmake @@ -12,10 +12,18 @@ macro(replace_cxx_flag pattern text) endmacro() # Fixup default compiler settings -add_compile_options( - # Be as strict as reasonably possible, since we want to support consumers using strict warning levels - /W4 /WX +if (MSVC) + add_compile_options( + # Be as strict as reasonably possible, since we want to support consumers using strict warning levels + /W4 /WX + ) +else() + # Clang with non-MSVC commandline syntax + add_compile_options( + # Effectively the same as /W4 /WX + -Wall -Werror ) +endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options( diff --git a/scripts/init.cmd b/scripts/init.cmd index fc2ba01..a5ee8ce 100644 --- a/scripts/init.cmd +++ b/scripts/init.cmd @@ -142,6 +142,8 @@ goto :init :: Formulate CMake arguments if %GENERATOR%==ninja set CMAKE_ARGS=%CMAKE_ARGS% -G Ninja + :: NOTE: clang++ seems to currently have an issue handling SEH & destructors, so use clang-cl for now which, for + :: some reason, doesn't seem to have the same issue if %COMPILER%==clang set CMAKE_ARGS=%CMAKE_ARGS% -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl if %COMPILER%==msvc set CMAKE_ARGS=%CMAKE_ARGS% -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl diff --git a/scripts/runtests.cmd b/scripts/runtests.cmd index c0d3002..129c384 100644 --- a/scripts/runtests.cmd +++ b/scripts/runtests.cmd @@ -4,13 +4,24 @@ setlocal EnableDelayedExpansion set TEST_ARGS=%* +:: For some reason, '__asan_default_options' seems to have no effect under some unknown circumstances (despite the +:: function being called), so set the environment variable as a workaround. This ensures that we get the correct +:: behavior at least when this script is being used, which should cover most developer scenarios as well as the CI +set ASAN_OPTIONS=allocator_may_return_null=1:new_delete_type_mismatch=0 + set BUILD_ROOT=%~dp0\..\build -:: Unlike building, we don't need to limit ourselves to the Platform of the command window set COMPILERS=clang msvc -set ARCHITECTURES=32 64 set BUILD_TYPES=debug release relwithdebinfo minsizerel +:: The asan binaries are architecture specific, so we unfortunately must limit the tests we run by the architecture of +:: the command window. +if "%Platform%"=="x64" ( + set ARCHITECTURES=64 +) else ( + set ARCHITECTURES=32 +) + for %%c in (%COMPILERS%) do ( for %%a in (%ARCHITECTURES%) do ( for %%b in (%BUILD_TYPES%) do ( @@ -42,6 +53,7 @@ call :execute_test sanitize-undefined-behavior witest.ubsan.exe if %ERRORLEVEL% NEQ 0 ( goto :execute_tests_done ) call :execute_test win7 witest.win7.exe if %ERRORLEVEL% NEQ 0 ( goto :execute_tests_done ) +:: Fall through :execute_tests_done set EXIT_CODE=%ERRORLEVEL% diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d2d3cd0..0abb43a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,14 +34,19 @@ include_directories(BEFORE SYSTEM ${CMAKE_BINARY_DIR}/include) # The build pipelines have limitations that local development environments do not, so turn a few knobs if (${FAST_BUILD}) - replace_cxx_flag("/GR" "/GR-") # Disables RTTI + if (MSVC) + replace_cxx_flag("/GR" "/GR-") # Disables RTTI + else() + add_compile_options(-fno-rtti) + endif() + add_definitions(-DCATCH_CONFIG_FAST_COMPILE -DWIL_FAST_BUILD) endif() # For some unknown reason, 'RelWithDebInfo' compiles with '/Ob1' as opposed to '/Ob2' which prevents inlining of # functions not marked 'inline'. The reason we prefer 'RelWithDebInfo' over 'Release' is to get debug info, so manually # revert to the desired (and default) inlining behavior as that exercises more interesting code paths -if (${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") +if (MSVC AND ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") # TODO: This is currently blocked by an apparent Clang bug: https://github.com/llvm/llvm-project/issues/59690 # replace_cxx_flag("/Ob1" "/Ob2") endif() @@ -63,7 +68,9 @@ set(COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../natvis/wil.natvis ) -add_link_options(/NATVIS:${CMAKE_SOURCE_DIR}/natvis/wil.natvis) +if (MSVC) + add_link_options(/NATVIS:${CMAKE_SOURCE_DIR}/natvis/wil.natvis) +endif() add_subdirectory(app) add_subdirectory(cpplatest) diff --git a/tests/noexcept/CMakeLists.txt b/tests/noexcept/CMakeLists.txt index e02b27d..2bda36a 100644 --- a/tests/noexcept/CMakeLists.txt +++ b/tests/noexcept/CMakeLists.txt @@ -2,7 +2,12 @@ add_executable(witest.noexcept) # Turn off exceptions for this test -replace_cxx_flag("/EHsc" "/EHs-c-") +if (MSVC) + replace_cxx_flag("/EHsc" "/EHs-c-") +else() + target_compile_options(witest.noexcept PRIVATE -fno-exceptions) +endif() + target_compile_definitions(witest.noexcept PRIVATE -DCATCH_CONFIG_DISABLE_EXCEPTIONS ) diff --git a/tests/sanitize-address/CMakeLists.txt b/tests/sanitize-address/CMakeLists.txt index d7f6194..3799605 100644 --- a/tests/sanitize-address/CMakeLists.txt +++ b/tests/sanitize-address/CMakeLists.txt @@ -18,7 +18,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") ) # Clang ASan on Windows has issues with exceptions: https://github.com/google/sanitizers/issues/749 - replace_cxx_flag("/EHsc" "/EHs-c-") + if (MSVC) + replace_cxx_flag("/EHsc" "/EHs-c-") + else() + target_compile_options(witest.asan PRIVATE -fno-exceptions) + endif() if ($ENV{Platform} STREQUAL "x86") target_link_libraries(witest.asan PRIVATE