Skip to content

Commit

Permalink
Try #356:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Aug 8, 2022
2 parents 2c0b8be + c82f8c9 commit c8f9aee
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 140 deletions.
85 changes: 34 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,74 +288,57 @@ pika_option(
)
pika_option(
PIKA_WITH_TESTS_BENCHMARKS BOOL "Build benchmark tests (default: ON)" ON
CATEGORY "Build Targets"
DEPENDS "PIKA_WITH_TESTS" CATEGORY "Build Targets"
)
pika_option(
PIKA_WITH_TESTS_REGRESSIONS BOOL "Build regression tests (default: ON)" ON
CATEGORY "Build Targets"
DEPENDS "PIKA_WITH_TESTS" CATEGORY "Build Targets"
)
pika_option(
PIKA_WITH_TESTS_UNIT BOOL "Build unit tests (default: ON)" ON
CATEGORY "Build Targets"
PIKA_WITH_TESTS_UNIT BOOL "Build unit tests (default: ON)" ON DEPENDS
"PIKA_WITH_TESTS" CATEGORY "Build Targets"
)
pika_option(
PIKA_WITH_TESTS_HEADERS BOOL "Build header tests (default: ON)" ON ADVANCED
PIKA_WITH_TESTS_HEADERS
BOOL
"Build header tests (default: ON)"
ON
ADVANCED
DEPENDS
"PIKA_WITH_TESTS"
CATEGORY "Build Targets"
)
pika_option(
PIKA_WITH_TESTS_EXTERNAL_BUILD BOOL
"Build external CMake build tests (default: ON)" ON ADVANCED
PIKA_WITH_TESTS_EXTERNAL_BUILD
BOOL
"Build external CMake build tests (default: ON)"
ON
ADVANCED
DEPENDS
"PIKA_WITH_TESTS"
CATEGORY "Build Targets"
)
pika_option(
PIKA_WITH_TESTS_EXAMPLES BOOL "Add examples as tests (default: ON)" ON
ADVANCED CATEGORY "Build Targets"
PIKA_WITH_TESTS_EXAMPLES
BOOL
"Add examples as tests (default: ON)"
ON
DEPENDS
"PIKA_WITH_TESTS;PIKA_WITH_EXAMPLES"
ADVANCED
CATEGORY "Build Targets"
)
pika_option(
PIKA_WITH_COMPILE_ONLY_TESTS BOOL
"Create build system support for compile time only tests (default: ON)" ON
CATEGORY "Build Targets"
DEPENDS "PIKA_WITH_TESTS" CATEGORY "Build Targets"
)
pika_option(
PIKA_WITH_FAIL_COMPILE_TESTS BOOL
"Create build system support for fail compile tests (default: ON)" ON
CATEGORY "Build Targets"
"Create build system support for fail compile tests (default: ON)" ON DEPENDS
"PIKA_WITH_TESTS" CATEGORY "Build Targets"
)

# disable all tests if PIKA_WITH_TESTS=OFF
if(NOT PIKA_WITH_TESTS)
pika_set_option(
PIKA_WITH_TESTS_BENCHMARKS
VALUE OFF
FORCE
)
pika_set_option(
PIKA_WITH_TESTS_REGRESSIONS
VALUE OFF
FORCE
)
pika_set_option(
PIKA_WITH_TESTS_UNIT
VALUE OFF
FORCE
)
pika_set_option(
PIKA_WITH_TESTS_HEADERS
VALUE OFF
FORCE
)
pika_set_option(
PIKA_WITH_TESTS_EXTERNAL_BUILD
VALUE OFF
FORCE
)
pika_set_option(
PIKA_WITH_TESTS_EXAMPLES
VALUE OFF
FORCE
)
endif()

pika_option(
PIKA_WITH_TOOLS BOOL "Build tools (default: OFF)" OFF ADVANCED
CATEGORY "Build Targets"
Expand Down Expand Up @@ -789,7 +772,7 @@ endif()
pika_option(
PIKA_WITH_EXAMPLES_OPENMP BOOL
"Enable examples requiring OpenMP support (default: OFF)." OFF
CATEGORY "Build Targets"
CATEGORY "Build Targets" DEPENDS "PIKA_WITH_EXAMPLES"
ADVANCED
)
if(PIKA_WITH_EXAMPLES_OPENMP)
Expand All @@ -798,7 +781,7 @@ endif()
pika_option(
PIKA_WITH_EXAMPLES_TBB BOOL
"Enable examples requiring TBB support (default: OFF)." OFF
CATEGORY "Build Targets"
CATEGORY "Build Targets" DEPENDS "PIKA_WITH_EXAMPLES"
ADVANCED
)
if(PIKA_WITH_EXAMPLES_TBB)
Expand All @@ -810,7 +793,7 @@ endif()
pika_option(
PIKA_WITH_EXAMPLES_QTHREADS BOOL
"Enable examples requiring QThreads support (default: OFF)." OFF
CATEGORY "Build Targets"
CATEGORY "Build Targets" DEPENDS "PIKA_WITH_EXAMPLES"
ADVANCED
)
if(PIKA_WITH_EXAMPLES_QTHREADS)
Expand All @@ -822,7 +805,7 @@ endif()
pika_option(
PIKA_WITH_EXAMPLES_HDF5 BOOL
"Enable examples requiring HDF5 support (default: OFF)." OFF
CATEGORY "Build Targets"
CATEGORY "Build Targets" DEPENDS "PIKA_WITH_EXAMPLES"
ADVANCED
)
if(PIKA_WITH_EXAMPLES_HDF5)
Expand All @@ -837,7 +820,7 @@ if(NOT "${PIKA_PLATFORM_UC}" STREQUAL "BLUEGENEQ")
pika_option(
PIKA_WITH_EXAMPLES_QT4 BOOL
"Enable examples requiring Qt4 support (default: OFF)." OFF
CATEGORY "Build Targets"
CATEGORY "Build Targets" DEPENDS "PIKA_WITH_EXAMPLES"
ADVANCED
)
if(PIKA_WITH_EXAMPLES_QT4)
Expand Down
142 changes: 53 additions & 89 deletions cmake/pika_option.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,82 @@
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

include(CMakeDependentOption)
include(CMakeParseArguments)

set(PIKA_OPTION_CATEGORIES "Generic" "Build Targets" "Thread Manager"
"Profiling" "Debugging" "Modules"
)

function(pika_option option type description default)
macro(pika_option option type description default)
set(options ADVANCED)
set(one_value_args CATEGORY MODULE)
set(one_value_args CATEGORY DEPENDS MODULE)
set(multi_value_args STRINGS)
cmake_parse_arguments(
PIKA_OPTION "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}
)

if(NOT DEFINED ${option})
set(${option}
${default}
CACHE ${type} "${description}" FORCE
)
if(PIKA_OPTION_ADVANCED)
mark_as_advanced(${option})
if("${type}" STREQUAL "BOOL")
# Use regular CMake options for booleans
if(NOT PIKA_OPTION_DEPENDS)
option("${option}" "${description}" "${default}")
else()
cmake_dependent_option(
"${option}" "${description}" "${default}" "${PIKA_OPTION_DEPENDS}" OFF
)
endif()
else()
# make sure that dependent projects can overwrite any of the pika options
unset(${option} PARENT_SCOPE)

get_property(
_option_is_cache_property
CACHE "${option}"
PROPERTY TYPE
SET
)
if(NOT _option_is_cache_property)
if(PIKA_OPTION_DEPENDS)
message(
FATAL_ERROR
"pika_option DEPENDS keyword can only be used with BOOL options"
)
endif()
# Use custom cache variables for other types
if(NOT DEFINED ${option})
set(${option}
${default}
CACHE ${type} "${description}" FORCE
)
if(PIKA_OPTION_ADVANCED)
mark_as_advanced(${option})
endif()
else()
set_property(CACHE "${option}" PROPERTY HELPSTRING "${description}")
set_property(CACHE "${option}" PROPERTY TYPE "${type}")
get_property(
_option_is_cache_property
CACHE "${option}"
PROPERTY TYPE
SET
)
if(NOT _option_is_cache_property)
set(${option}
${default}
CACHE ${type} "${description}" FORCE
)
if(PIKA_OPTION_ADVANCED)
mark_as_advanced(${option})
endif()
else()
set_property(CACHE "${option}" PROPERTY HELPSTRING "${description}")
set_property(CACHE "${option}" PROPERTY TYPE "${type}")
endif()
endif()
endif()

if(PIKA_OPTION_STRINGS)
if("${type}" STREQUAL "STRING")
set_property(CACHE "${option}" PROPERTY STRINGS "${PIKA_OPTION_STRINGS}")
else()
message(
FATAL_ERROR
"pika_option(): STRINGS can only be used if type is STRING !"
)
if(PIKA_OPTION_STRINGS)
if("${type}" STREQUAL "STRING")
set_property(
CACHE "${option}" PROPERTY STRINGS "${PIKA_OPTION_STRINGS}"
)
else()
message(
FATAL_ERROR
"pika_option(): STRINGS can only be used if type is STRING !"
)
endif()
endif()
endif()

if(PIKA_OPTION_ADVANCED)
mark_as_advanced(${option})
endif()

if(PIKA_OPTION_MODULE)
string(TOUPPER ${PIKA_OPTION_MODULE} module_uc)
set(varname_uc PIKA_MODULE_CONFIG_${module_uc})
Expand All @@ -78,59 +97,4 @@ function(pika_option option type description default)
${_category}
CACHE INTERNAL ""
)
endfunction()

# simplify setting an option in cache
function(pika_set_option option)
set(options FORCE)
set(one_value_args VALUE TYPE HELPSTRING)
set(multi_value_args)
cmake_parse_arguments(
PIKA_SET_OPTION "${options}" "${one_value_args}" "${multi_value_args}"
${ARGN}
)

if(NOT DEFINED ${option})
pika_error("attempting to set an undefined option: ${option}")
endif()

set(${option}_force)
if(PIKA_SET_OPTION_FORCE)
set(${option}_force FORCE)
endif()

if(PIKA_SET_OPTION_HELPSTRING)
set(${option}_description ${PIKA_SET_OPTION_HELPSTRING})
else()
get_property(
${option}_description
CACHE "${option}"
PROPERTY HELPSTRING
)
endif()

if(PIKA_SET_OPTION_TYPE)
set(${option}_type ${PIKA_SET_OPTION_TYPE})
else()
get_property(
${option}_type
CACHE "${option}"
PROPERTY TYPE
)
endif()

if(DEFINED PIKA_SET_OPTION_VALUE)
set(${option}_value ${PIKA_SET_OPTION_VALUE})
else()
get_property(
${option}_value
CACHE "${option}"
PROPERTY VALUE
)
endif()

set(${option}
${${option}_value}
CACHE ${${option}_type} "${${option}_description}" ${${option}_force}
)
endfunction()
endmacro()

0 comments on commit c8f9aee

Please sign in to comment.