diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94d247c6..879e6435 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,10 @@ jobs: compiler: "gcc" cmake: true vcvarsall: true + - os: "macos-13" + compiler: "gcc" + cmake: true + vcvarsall: true exclude: # fails with an internal error - os: "macos-12" @@ -80,7 +84,7 @@ jobs: cppcheck: true clangtidy: true task: true - doxygen: ${{ !contains(matrix.os, 'macos-11') }} + doxygen: ${{ !contains(matrix.os, 'macos-11') && !contains(matrix.os, 'macos-13') }} - name: Test if: ${{ !cancelled() }} diff --git a/src/DynamicProjectOptions.cmake b/src/DynamicProjectOptions.cmake index 8f6c8b92..bd7cec7e 100644 --- a/src/DynamicProjectOptions.cmake +++ b/src/DynamicProjectOptions.cmake @@ -1,5 +1,7 @@ include_guard() +include("${CMAKE_CURRENT_LIST_DIR}/Sanitizers.cmake") + #[[.rst: ``dynamic_project_options`` @@ -101,20 +103,24 @@ macro(dynamic_project_options) ) endif() - if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") - AND NOT WIN32 + check_sanitizers_support( + ENABLE_SANITIZER_ADDRESS + ENABLE_SANITIZER_UNDEFINED_BEHAVIOR + ENABLE_SANITIZER_LEAK + ENABLE_SANITIZER_THREAD + ENABLE_SANITIZER_MEMORY ) - set(SUPPORTS_UBSAN ON) + + if(ENABLE_SANITIZER_ADDRESS) + set(SUPPORTS_ASAN ON) else() - set(SUPPORTS_UBSAN OFF) + set(SUPPORTS_ASAN OFF) endif() - if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") - AND WIN32 - ) - set(SUPPORTS_ASAN OFF) + if(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR) + set(SUPPORTS_UBSAN ON) else() - set(SUPPORTS_ASAN ON) + set(SUPPORTS_UBSAN OFF) endif() # ccache, clang-tidy, cppcheck are only supported with Ninja and Makefile based generators diff --git a/src/Sanitizers.cmake b/src/Sanitizers.cmake index 830f209e..df927a9b 100644 --- a/src/Sanitizers.cmake +++ b/src/Sanitizers.cmake @@ -1,5 +1,7 @@ include_guard() +include("${CMAKE_CURRENT_LIST_DIR}/Utilities.cmake") + # Enable the sanitizers for the given project function( enable_sanitizers @@ -133,11 +135,28 @@ function( ) set(SANITIZERS "") if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") - list(APPEND SANITIZERS "address") - list(APPEND SANITIZERS "undefined") - list(APPEND SANITIZERS "leak") - list(APPEND SANITIZERS "thread") - list(APPEND SANITIZERS "memory") + set(HAS_SANITIZER_SUPPORT ON) + + # Disable gcc sanitizer on some macos according to https://github.com/orgs/Homebrew/discussions/3384#discussioncomment-6264292 + if((CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND APPLE) + detect_macos_version(MACOS_VERSION) + if(MACOS_VERSION VERSION_GREATER_EQUAL 13) + set(HAS_SANITIZER_SUPPORT OFF) + endif() + + detect_architecture(ARCHITECTURE) + if(ARCHITECTURE STREQUAL "arm64") + set(HAS_SANITIZER_SUPPORT OFF) + endif() + endif() + + if (HAS_SANITIZER_SUPPORT) + list(APPEND SANITIZERS "address") + list(APPEND SANITIZERS "undefined") + list(APPEND SANITIZERS "leak") + list(APPEND SANITIZERS "thread") + list(APPEND SANITIZERS "memory") + endif() elseif(MSVC) # or it is MSVC and has run vcvarsall string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) diff --git a/src/Utilities.cmake b/src/Utilities.cmake index 25086238..0e539f56 100644 --- a/src/Utilities.cmake +++ b/src/Utilities.cmake @@ -125,6 +125,15 @@ function(detect_architecture arch) endif() endfunction() +function(detect_macos_version version) + find_program(SW_VERS_EXECUTABLE sw_vers) + execute_process( + COMMAND "${SW_VERS_EXECUTABLE}" -productVersion + OUTPUT_VARIABLE MACOS_VERSION + ) + set(${version} "${MACOS_VERSION}" PARENT_SCOPE) +endfunction() + # convert semicolons in generator expression to $ function(convert_genex_semicolons genex output) set(result) diff --git a/tests/install/CMakeLists.txt b/tests/install/CMakeLists.txt index e4a78b9d..8983ce29 100644 --- a/tests/install/CMakeLists.txt +++ b/tests/install/CMakeLists.txt @@ -8,6 +8,26 @@ run_conan() project(anotherproj VERSION 0.1.0 LANGUAGES CXX C) +option(FEATURE_TESTS "Enable the tests" ON) +if(FEATURE_TESTS) + # Enable sanitizers and static analyzers when running the tests + check_sanitizers_support( + ENABLE_SANITIZER_ADDRESS ENABLE_SANITIZER_UNDEFINED_BEHAVIOR ENABLE_SANITIZER_LEAK + ENABLE_SANITIZER_THREAD ENABLE_SANITIZER_MEMORY + ) +endif() + +set(ENABLE_INTERPROCEDURAL_OPTIMIZATION "ENABLE_INTERPROCEDURAL_OPTIMIZATION") +if(APPLE) + detect_macos_version(apple_version) + if(apple_version VERSION_GREATER_EQUAL 13) + # workaround for linkage error as described in https://github.com/Homebrew/homebrew-core/issues/145991 + # although fixed, this problem still exists in github actions + add_link_options(-Wl,-ld_classic) + set(ENABLE_INTERPROCEDURAL_OPTIMIZATION "") + endif() +endif() + # Initialize project_options project_options( ENABLE_CACHE @@ -23,14 +43,14 @@ project_options( DOXYGEN_THEME "${CMAKE_CURRENT_LIST_DIR}/css/my_custom_theme.css" "${CMAKE_CURRENT_LIST_DIR}/css/my_custom_theme_extra.css" - ENABLE_INTERPROCEDURAL_OPTIMIZATION + ${ENABLE_INTERPROCEDURAL_OPTIMIZATION} # ENABLE_BUILD_WITH_TIME_TRACE # ENABLE_UNITY - # ENABLE_SANITIZER_ADDRESS - # ENABLE_SANITIZER_LEAK - # ENABLE_SANITIZER_UNDEFINED_BEHAVIOR - # ENABLE_SANITIZER_THREAD - # ENABLE_SANITIZER_MEMORY + ${ENABLE_SANITIZER_ADDRESS} + # ${ENABLE_SANITIZER_LEAK} + ${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR} + # ${ENABLE_SANITIZER_THREAD} + # ${ENABLE_SANITIZER_MEMORY} ) # add src, tests, etc here: diff --git a/tests/myproj/CMakeLists.txt b/tests/myproj/CMakeLists.txt index 1a29ddbf..5c4b88e2 100644 --- a/tests/myproj/CMakeLists.txt +++ b/tests/myproj/CMakeLists.txt @@ -33,7 +33,7 @@ set(PCH_HEADERS ) -option(FEATURE_TESTS "Enable the tests" OFF) +option(FEATURE_TESTS "Enable the tests" ON) if(FEATURE_TESTS) # Enable sanitizers and static analyzers when running the tests @@ -49,6 +49,17 @@ if(NOT MSVC) #message(STATUS "Detect Linker: ${LINKER}") endif() +set(ENABLE_INTERPROCEDURAL_OPTIMIZATION "ENABLE_INTERPROCEDURAL_OPTIMIZATION") +if(APPLE) + detect_macos_version(apple_version) + if(apple_version VERSION_GREATER_EQUAL 13) + # workaround for linkage error as described in https://github.com/Homebrew/homebrew-core/issues/145991 + # although fixed, this problem still exists in github actions + add_link_options(-Wl,-ld_classic) + set(ENABLE_INTERPROCEDURAL_OPTIMIZATION "") + endif() +endif() + # Initialize project_options # uncomment the options to enable them project_options( @@ -65,7 +76,7 @@ project_options( # PCH_HEADERS # ${PCH_HEADERS} ENABLE_DOXYGEN - ENABLE_INTERPROCEDURAL_OPTIMIZATION + ${ENABLE_INTERPROCEDURAL_OPTIMIZATION} ENABLE_NATIVE_OPTIMIZATION # ENABLE_BUILD_WITH_TIME_TRACE # ENABLE_UNITY