-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Refactored the CMake build system (#42)
- Loading branch information
Showing
6 changed files
with
211 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
option(ENABLE_CACHE "Enable cache if available" ON) | ||
if(NOT ENABLE_CACHE) | ||
return() | ||
endif() | ||
if (NOT ENABLE_CACHE) | ||
return() | ||
endif () | ||
|
||
set(CACHE_OPTION | ||
"ccache" | ||
CACHE STRING "Compiler cache to be used") | ||
"ccache" | ||
CACHE STRING "Compiler cache to be used") | ||
set(CACHE_OPTION_VALUES "ccache" "sccache") | ||
set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES}) | ||
list( | ||
FIND | ||
CACHE_OPTION_VALUES | ||
${CACHE_OPTION} | ||
CACHE_OPTION_INDEX) | ||
FIND | ||
CACHE_OPTION_VALUES | ||
${CACHE_OPTION} | ||
CACHE_OPTION_INDEX) | ||
|
||
if(${CACHE_OPTION_INDEX} EQUAL -1) | ||
message( | ||
STATUS | ||
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}") | ||
endif() | ||
if (${CACHE_OPTION_INDEX} EQUAL -1) | ||
message( | ||
STATUS | ||
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}") | ||
endif () | ||
|
||
find_program(CACHE_BINARY ${CACHE_OPTION}) | ||
if(CACHE_BINARY) | ||
message(STATUS "${CACHE_OPTION} found and enabled") | ||
set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BINARY}) | ||
else() | ||
message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it") | ||
endif() | ||
if (CACHE_BINARY) | ||
message(STATUS "${CACHE_OPTION} found and enabled") | ||
set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BINARY}) | ||
else () | ||
message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it") | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
# This function will prevent in-source builds | ||
function(AssureOutOfSourceBuilds) | ||
# make sure the user doesn't play dirty with symlinks | ||
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) | ||
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) | ||
# make sure the user doesn't play dirty with symlinks | ||
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) | ||
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) | ||
|
||
# disallow in-source builds | ||
if("${srcdir}" STREQUAL "${bindir}") | ||
message("######################################################") | ||
message("Warning: in-source builds are disabled") | ||
message("Please create a separate build directory and run cmake from there") | ||
message("######################################################") | ||
message(FATAL_ERROR "Quitting configuration") | ||
endif() | ||
# disallow in-source builds | ||
if ("${srcdir}" STREQUAL "${bindir}") | ||
message("######################################################") | ||
message("Warning: in-source builds are disabled") | ||
message("Please create a separate build directory and run cmake from there") | ||
message("######################################################") | ||
message(FATAL_ERROR "Quitting configuration") | ||
endif () | ||
endfunction() | ||
|
||
assureoutofsourcebuilds() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,66 @@ | ||
function(enable_sanitizers project_name) | ||
|
||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") | ||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") | ||
|
||
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE) | ||
if (ENABLE_COVERAGE) | ||
target_compile_options(${project_name} INTERFACE --coverage -fprofile-arcs -ftest-coverage -O0 -g) | ||
target_link_libraries(${project_name} INTERFACE gcov --coverage) | ||
endif () | ||
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE) | ||
if (ENABLE_COVERAGE) | ||
target_compile_options(${project_name} INTERFACE --coverage -fprofile-arcs -ftest-coverage -O0 -g) | ||
target_link_libraries(${project_name} INTERFACE gcov --coverage) | ||
endif () | ||
|
||
set(SANITIZERS "") | ||
set(SANITIZERS "") | ||
|
||
option(ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" FALSE) | ||
if(ENABLE_SANITIZER_ADDRESS) | ||
list(APPEND SANITIZERS "address") | ||
endif() | ||
option(ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" FALSE) | ||
if (ENABLE_SANITIZER_ADDRESS) | ||
list(APPEND SANITIZERS "address") | ||
endif () | ||
|
||
option(ENABLE_SANITIZER_LEAK "Enable leak sanitizer" FALSE) | ||
if(ENABLE_SANITIZER_LEAK) | ||
list(APPEND SANITIZERS "leak") | ||
endif() | ||
option(ENABLE_SANITIZER_LEAK "Enable leak sanitizer" FALSE) | ||
if (ENABLE_SANITIZER_LEAK) | ||
list(APPEND SANITIZERS "leak") | ||
endif () | ||
|
||
option(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "Enable undefined behavior sanitizer" FALSE) | ||
if(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR) | ||
list(APPEND SANITIZERS "undefined") | ||
endif() | ||
option(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "Enable undefined behavior sanitizer" FALSE) | ||
if (ENABLE_SANITIZER_UNDEFINED_BEHAVIOR) | ||
list(APPEND SANITIZERS "undefined") | ||
endif () | ||
|
||
option(ENABLE_SANITIZER_THREAD "Enable thread sanitizer" FALSE) | ||
if(ENABLE_SANITIZER_THREAD) | ||
if("address" IN_LIST SANITIZERS OR "leak" IN_LIST SANITIZERS) | ||
message(WARNING "Thread sanitizer does not work with Address and Leak sanitizer enabled") | ||
else() | ||
list(APPEND SANITIZERS "thread") | ||
endif() | ||
endif() | ||
option(ENABLE_SANITIZER_THREAD "Enable thread sanitizer" FALSE) | ||
if (ENABLE_SANITIZER_THREAD) | ||
if ("address" IN_LIST SANITIZERS OR "leak" IN_LIST SANITIZERS) | ||
message(WARNING "Thread sanitizer does not work with Address and Leak sanitizer enabled") | ||
else () | ||
list(APPEND SANITIZERS "thread") | ||
endif () | ||
endif () | ||
|
||
option(ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" FALSE) | ||
if(ENABLE_SANITIZER_MEMORY AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") | ||
if("address" IN_LIST SANITIZERS | ||
OR "thread" IN_LIST SANITIZERS | ||
OR "leak" IN_LIST SANITIZERS) | ||
message(WARNING "Memory sanitizer does not work with Address, Thread and Leak sanitizer enabled") | ||
else() | ||
list(APPEND SANITIZERS "memory") | ||
endif() | ||
endif() | ||
option(ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" FALSE) | ||
if (ENABLE_SANITIZER_MEMORY AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") | ||
if ("address" IN_LIST SANITIZERS | ||
OR "thread" IN_LIST SANITIZERS | ||
OR "leak" IN_LIST SANITIZERS) | ||
message(WARNING "Memory sanitizer does not work with Address, Thread and Leak sanitizer enabled") | ||
else () | ||
list(APPEND SANITIZERS "memory") | ||
endif () | ||
endif () | ||
|
||
list( | ||
JOIN | ||
SANITIZERS | ||
"," | ||
LIST_OF_SANITIZERS) | ||
list( | ||
JOIN | ||
SANITIZERS | ||
"," | ||
LIST_OF_SANITIZERS) | ||
|
||
endif() | ||
endif () | ||
|
||
if(LIST_OF_SANITIZERS) | ||
if(NOT | ||
"${LIST_OF_SANITIZERS}" | ||
STREQUAL | ||
"") | ||
target_compile_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) | ||
target_link_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) | ||
endif() | ||
endif() | ||
if (LIST_OF_SANITIZERS) | ||
if (NOT | ||
"${LIST_OF_SANITIZERS}" | ||
STREQUAL | ||
"") | ||
target_compile_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) | ||
target_link_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) | ||
endif () | ||
endif () | ||
|
||
endfunction() |
Oops, something went wrong.