Skip to content

Commit

Permalink
Add a prefix to all CMake options and deprecate non-prefixed one (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
offa committed Jun 15, 2023
1 parent dfc020b commit 3143e15
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
28 changes: 15 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ project(plug VERSION 1.4.3)
message(STATUS "~~~ ${PROJECT_NAME} v${PROJECT_VERSION} ~~~")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
option(UNITTEST "Build Unit Tests" ON)
message(STATUS "Unit Tests : ${UNITTEST}")
option(PLUG_UNITTEST "Build Unit Tests" ON)
message(STATUS "Unit Tests : ${PLUG_UNITTEST}")

option(COVERAGE "Enable Coverage" OFF)
message(STATUS "Coverage : ${COVERAGE}")
option(PLUG_COVERAGE "Enable Coverage" OFF)
message(STATUS "Coverage : ${PLUG_COVERAGE}")

option(LTO "Enable LTO" OFF)
message(STATUS "LTO : ${LTO}")
option(PLUG_LTO "Enable LTO" OFF)
message(STATUS "LTO : ${PLUG_LTO}")

option(SANITIZER_ASAN "Enable ASan" OFF)
message(STATUS "ASan : ${SANITIZER_ASAN}")
option(PLUG_SANITIZER_ASAN "Enable ASan" OFF)
message(STATUS "ASan : ${PLUG_SANITIZER_ASAN}")

option(SANITIZER_UBSAN "Enable UBSan" OFF)
message(STATUS "UBSan : ${SANITIZER_UBSAN}")
option(PLUG_SANITIZER_UBSAN "Enable UBSan" OFF)
message(STATUS "UBSan : ${PLUG_SANITIZER_UBSAN}")

include(DeprecatedOptions)


if( CMAKE_BUILD_TYPE )
Expand All @@ -28,11 +30,11 @@ endif()

include(GNUInstallDirs)

if( LTO )
if( PLUG_LTO )
include(LTO)
endif()

if( COVERAGE )
if( PLUG_COVERAGE )
include(Coverage)
endif()

Expand Down Expand Up @@ -65,7 +67,7 @@ include_directories("include")
add_subdirectory(src)


if( UNITTEST )
if( PLUG_UNITTEST )
enable_testing()
add_subdirectory("test")
endif()
Expand Down
15 changes: 15 additions & 0 deletions cmake/DeprecatedOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

function(deprecate_options)
foreach (arg IN LISTS ARGN)
if (DEFINED ${arg})
message(WARNING "Option ${arg} is deprecated, please use PLUG_${arg} instead, value will be ignored!")
endif()
endforeach()
endfunction()

deprecate_options(UNITTEST
COVERAGE
LTO
SANITIZER_ASAN
SANITIZER_UBSAN
)
4 changes: 2 additions & 2 deletions cmake/Sanitizer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ macro(enable_sanitizer san)
endmacro()


if( SANITIZER_ASAN )
if( PLUG_SANITIZER_ASAN )
enable_sanitizer(address)
endif()

if( SANITIZER_UBSAN )
if( PLUG_SANITIZER_UBSAN )
enable_sanitizer(undefined)
endif()

6 changes: 3 additions & 3 deletions script/ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ for arg in "$@"
do
case "${arg}" in
-asan)
BUILD_ARGS+=("-DSANITIZER_ASAN=ON")
BUILD_ARGS+=("-DPLUG_SANITIZER_ASAN=ON")
;;
-ubsan)
BUILD_ARGS+=("-DSANITIZER_UBSAN=ON")
BUILD_ARGS+=("-DPLUG_SANITIZER_UBSAN=ON")
;;
-cov)
BUILD_ARGS+=("-DCOVERAGE=ON")
BUILD_ARGS+=("-DPLUG_COVERAGE=ON")
COVERAGE=true;
BUILD_TYPE="Debug"
apt-get install -y --no-install-recommends python3-pip python3-pkg-resources python3-setuptools
Expand Down

0 comments on commit 3143e15

Please sign in to comment.