Skip to content

Commit

Permalink
Merge pull request #3744 from nilsleiffischer/cmake_testing
Browse files Browse the repository at this point in the history
Add standard CMake `BUILD_TESTING` option, document test targets
  • Loading branch information
kidder committed Jan 18, 2022
2 parents 4f85291 + 05bdf2d commit a93d399
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/Tests.yaml
Expand Up @@ -193,6 +193,9 @@ jobs:
git fetch upstream develop
- name: Configure with cmake
working-directory: /work
# Notes on the build configuration:
# - Set `BUILD_TESTING=OFF` to test a CMake configuration with tests
# turned off.
run: >
mkdir build && cd build
Expand All @@ -206,6 +209,7 @@ jobs:
-D USE_CCACHE=OFF
-D DEBUG_SYMBOLS=OFF
-D BUILD_PYTHON_BINDINGS=ON
-D BUILD_TESTING=OFF
$GITHUB_WORKSPACE
- name: Check clang-tidy
working-directory: /work/build
Expand Down
19 changes: 12 additions & 7 deletions CMakeLists.txt
Expand Up @@ -102,7 +102,6 @@ include(SetupLIBXSMM)

include(SetupBlaze)
include(SetupBrigand)
include(SetupCatch)
include(SetupGoogleBenchmark)
include(SetupGsl)
include(SetupHdf5)
Expand Down Expand Up @@ -137,12 +136,16 @@ include(CodeCoverageDetection)
include(SpectreAddLibraries)

include(SpectreSetupTesting)
if(BUILD_TESTING)
include(SetupCatch)
include(SetupPypp)
include(SpectreAddTestLibs)
include(SpectreAddCatchTests)
include(AddInputFileTests)
include(AddStandaloneTests)
endif()

include(SpectreSetupPythonPackage)
include(SetupPypp)
include(SpectreAddTestLibs)
include(SpectreAddCatchTests)
include(AddInputFileTests)
include(AddStandaloneTests)

include_directories(${CMAKE_SOURCE_DIR}/external)
include_directories(${CMAKE_SOURCE_DIR}/src)
Expand All @@ -155,7 +158,9 @@ spectre_include_directories(${CMAKE_BINARY_DIR}/src/Parallel)

add_subdirectory(external)
add_subdirectory(src)
add_subdirectory(tests)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()

include(PrintUsefulCMakeInfo)

Expand Down
4 changes: 3 additions & 1 deletion cmake/SpectreSetupPythonPackage.cmake
Expand Up @@ -196,7 +196,9 @@ function(SPECTRE_PYTHON_ADD_MODULE MODULE_NAME)
LINK_FLAGS "${PY_LIB_LINK_FLAGS}"
)
set(SPECTRE_PYTHON_MODULE_IMPORT "from ._${ARG_LIBRARY_NAME} import *")
add_dependencies(test-executables ${ARG_LIBRARY_NAME})
if(BUILD_TESTING)
add_dependencies(test-executables ${ARG_LIBRARY_NAME})
endif()
add_dependencies(all-pybindings ${ARG_LIBRARY_NAME})
endif(BUILD_PYTHON_BINDINGS AND NOT "${ARG_SOURCES}" STREQUAL "")

Expand Down
2 changes: 1 addition & 1 deletion cmake/SpectreSetupTesting.cmake
@@ -1,7 +1,7 @@
# Distributed under the MIT License.
# See LICENSE.txt for details.

enable_testing(true)
include(CTest)

set(SPECTRE_TEST_RUNNER "" CACHE STRING
"Run test executables through the given wrapper.")
Expand Down
10 changes: 10 additions & 0 deletions docs/DevGuide/BuildSystem.md
Expand Up @@ -166,6 +166,8 @@ cmake -D FLAG1=OPT1 ... -D FLAGN=OPTN <SPECTRE_ROOT>
- BUILD_SHARED_LIBS
- Whether shared libraries are built instead of static libraries
(default is `OFF`)
- BUILD_TESTING
- Enable building tests. (default is `ON`)
- CHARM_ROOT
- The path to the build directory of `Charm++`
- CMAKE_BUILD_TYPE
Expand Down Expand Up @@ -298,6 +300,14 @@ cmake -D FLAG1=OPT1 ... -D FLAGN=OPTN <SPECTRE_ROOT>
In addition to individual simulation executables, the following targets are
available to build with `make` or `ninja`:

- unit-tests
- Build unit tests, which you can run with `ctest -L unit`. Available if
`BUILD_TESTING` is `ON` (the default).
- test-executables
- Build all tests, including executables, so you can run all tests with
`ctest`. Available if `BUILD_TESTING` is `ON` (the default). To compile
`test-executables` you may have to reduce the number of cores you build on
in parallel to avoid running out of memory.
- all-pybindings
- Build Python bindings. See \ref spectre_using_python for details.
- install
Expand Down
4 changes: 3 additions & 1 deletion src/Executables/ReduceCceWorldtube/CMakeLists.txt
Expand Up @@ -26,4 +26,6 @@ set_target_properties(
PROPERTIES LINK_FLAGS "-nomain-module -nomain"
)

add_dependencies(test-executables ${EXECUTABLE})
if(BUILD_TESTING)
add_dependencies(test-executables ${EXECUTABLE})
endif()

0 comments on commit a93d399

Please sign in to comment.