Skip to content

Commit 94e3e9e

Browse files
committed
review cmake tests
1 parent 555ba46 commit 94e3e9e

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

CMakeLists.txt

+14-11
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,39 @@
88
#
99
# the config file is generatet in the build and install directories
1010

11-
cmake_minimum_required(VERSION 3.10...3.13)
11+
cmake_minimum_required(VERSION 3.10...3.15)
1212
project(PENF VERSION 1.2.1 LANGUAGES Fortran)
1313

1414
# seach path for additional cmake modules
1515
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules)
1616

17-
1817
# set export variables needed for building
1918
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}-targets")
2019
set(NAMESPACE "${PROJECT_NAME}::")
2120

22-
2321
# generate the library and install instructions
2422
add_subdirectory(src/lib)
2523

2624
# testing
2725
if(${PROJECT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
2826
set(main_project TRUE)
27+
enable_testing()
28+
option(BUILD_TESTING "Build the testing tree." ON)
29+
#include(CTest)
2930
else()
3031
set(main_project FALSE)
31-
endif()
3232

33-
include(CMakeDependentOption)
34-
cmake_dependent_option(BUILD_TESTING_${PROJECT_NAME}
35-
"Build the testing tree for project ${PROJECT_NAME}." OFF
36-
"BUILD_TESTING;NOT main_project" OFF
37-
)
33+
# if this is not the main project but BUILD_TESTIG is set to TRUE
34+
# the tests for this project can be enabled by also setting
35+
# BUILD_TESTING_${PROJECT_NAME} to TRUE
36+
include(CMakeDependentOption)
37+
cmake_dependent_option(BUILD_TESTING_${PROJECT_NAME}
38+
"Build the testing tree for project ${PROJECT_NAME}." OFF
39+
"BUILD_TESTING;NOT main_project" OFF
40+
)
41+
endif()
3842

39-
if((main_project AND BUILD_TESTING) OR BUILD_TESTING_${PROJECT_NAME})
40-
enable_testing()
43+
if((main_project OR BUILD_TESTING_${PROJECT_NAME}) AND BUILD_TESTING)
4144
add_subdirectory(src/tests)
4245
endif()
4346

src/tests/CMakeLists.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ function(add_penf_doctest test_src libraries)
77
get_filename_component(test_dir ${test_src} DIRECTORY)
88
set(result_src "${test_dir}/${test_name}.result")
99

10-
add_executable(${test_name} ${test_src})
10+
add_executable(${test_name} ${test_src}) # EXCLUDE_FROM_ALL ${test_src})
1111
foreach(lib IN LISTS libraries)
1212
target_link_libraries(${test_name} ${lib})
1313
endforeach()
1414
add_test(NAME ${test_name} COMMAND ${test_name})
1515

16+
# # if excluding the tests from the ALL target, build them when running the tests
17+
# add_test(${test_name}_build "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config $<CONFIG> --target ${test_name})
18+
# set_tests_properties(${test_name}_build PROPERTIES FIXTURES_SETUP ${test_name}_fixture)
19+
# set_tests_properties(${test_name} PROPERTIES FIXTURES_REQUIRED ${test_name}_fixture)
20+
1621
file(STRINGS ${result_src} result_raw)
1722
string(REGEX REPLACE "([+.])([^+.]*)" "\\\\\\1\\2" result ${result_raw})
1823

0 commit comments

Comments
 (0)