Skip to content

Commit

Permalink
give up using toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
wusatosi committed Nov 15, 2024
1 parent f4932e9 commit cc37b1a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ jobs:
args: ""
- description: "TSan"
config: "Debug"
args: "-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain.cmake -DBEMAN_BUILDSYS_SANITIZER=TSan"
args: "-DBEMAN_BUILDSYS_SANITIZER=TSan"
- description: "ASan"
config: "Debug"
args: "-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain.cmake -DBEMAN_BUILDSYS_SANITIZER=ASan"
args: "-DBEMAN_BUILDSYS_SANITIZER=ASan"
include:
- platform: ubuntu-latest
compiler:
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ option(
${PROJECT_IS_TOP_LEVEL}
)

if(DEFINED BEMAN_BUILDSYS_SANITIZER)
include(cmake/apply_santizers.cmake)
endif()

include(CTest)
include(FetchContent)
include(GNUInstallDirs)
Expand Down
2 changes: 0 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "cmake/toolchain.cmake",
"BEMAN_BUILDSYS_SANITIZER": "ASan"
}
},
Expand All @@ -24,7 +23,6 @@
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_TOOLCHAIN_FILE": "cmake/toolchain.cmake",
"BEMAN_BUILDSYS_SANITIZER": "OFF"
}
},
Expand Down
37 changes: 37 additions & 0 deletions cmake/apply_santizers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# BEMAN_BUILDSYS_SANITIZER is not a general use option
# It is used by preset and CI system.
# There's three possible values:
# TSan: Thread sanitizer
# ASan: All sanitizer (majorly Address sanitizer) that doesn't conflict with TSan
# OFF: No sanitizer

message("Applying sanitizers for ${CMAKE_CXX_COMPILER_ID}")

if(BEMAN_BUILDSYS_SANITIZER STREQUAL "ASan")
# Basic ASan flags
set(SANITIZER_FLAGS
"-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
)

# Exclude -fsanitize=leak on Apple Clang (gcc on macos) as it is not supported.
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
message(STATUS "Using GCC on macOS; excluding -fsanitize=leak")
else()
set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fsanitize=leak")
endif()
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan")
# Basic ASan flags
set(SANITIZER_FLAGS "-fsanitize=thread")
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "OFF")
set(SANITIZER_FLAGS "")
else()
message(
FATAL_ERROR
"Invalid BEMAN_BUILDSYS_SANITIZER option: ${BEMAN_BUILDSYS_SANITIZER}"
)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}")
47 changes: 0 additions & 47 deletions cmake/toolchain.cmake

This file was deleted.

0 comments on commit cc37b1a

Please sign in to comment.