Skip to content

Commit e9df502

Browse files
authored
Merge pull request #218 from Goddard-Fortran-Ecosystem/hotfix/cmake-fix-test-target
Fixes #216 - fixed support for "make test"
2 parents 019f780 + 819e98a commit e9df502

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

CMakeLists.txt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
cmake_minimum_required(VERSION 3.12)
2626

2727
project (PFUNIT
28-
VERSION 4.1.8
28+
VERSION 4.1.9
2929
LANGUAGES Fortran C)
3030

3131
enable_testing()
@@ -105,7 +105,6 @@ find_package(Python)
105105
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "")
106106
set(CMAKE_SKIP_RPATH ON)
107107

108-
add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND})
109108
set (dest "PFUNIT-${PFUNIT_VERSION_MAJOR}.${PFUNIT_VERSION_MINOR}")
110109

111110
# Code to silence warnings from RANLIB on OSX
@@ -115,11 +114,27 @@ if (APPLE)
115114
SET(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
116115
endif ()
117116

117+
add_custom_target(build-tests)
118+
119+
add_custom_target(tests
120+
COMMAND ${CMAKE_CTEST_COMMAND}
121+
EXCLUDE_FROM_ALL)
122+
add_dependencies(tests build-tests)
123+
124+
118125
add_subdirectory (extern)
119126
add_subdirectory (src)
120-
add_subdirectory (tests)
121127
add_subdirectory (include)
122128
add_subdirectory (bin)
129+
add_subdirectory (tests EXCLUDE_FROM_ALL)
130+
131+
# The following forces tests to be built when using "make ctest" even if some targets
132+
# are EXCLUDE_FROM_ALL
133+
# From https://stackoverflow.com/questions/733475/cmake-ctest-make-test-doesnt-build-tests/56448477#56448477
134+
build_command(CTEST_CUSTOM_PRE_TEST TARGET build-tests)
135+
string(CONFIGURE \"@CTEST_CUSTOM_PRE_TEST@\" CTEST_CUSTOM_PRE_TEST_QUOTED ESCAPE_QUOTES)
136+
file(WRITE "${CMAKE_BINARY_DIR}/CTestCustom.cmake" "set(CTEST_CUSTOM_PRE_TEST ${CTEST_CUSTOM_PRE_TEST_QUOTED})" "\n")
137+
123138
124139
125140

ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

66
## [Unreleased]
7+
8+
## [4.1.9] - 2020-05-29
9+
10+
### Fixed
11+
- Changed internal cmake dependencies so that "make test" will now build
12+
tests. The tests and test executables are intentionally EXCLUDE_FROM_OLL
13+
which interferes with some canonical ways of driving cmake projects.
14+
"make tests" will continue to work as before.
15+
716

817
## [4.1.8] - 2020-05-12
918

tests/fhamcrest/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ set(pf_tests
2323
set(test_srcs)
2424
add_pfunit_sources (test_srcs ${pf_tests})
2525

26-
add_library(fhamcrest_tests EXCLUDE_FROM_ALL ${test_srcs})
26+
add_library(fhamcrest_tests ${test_srcs})
2727
target_link_libraries(fhamcrest_tests funit)
2828

2929
configure_file(${CMAKE_SOURCE_DIR}/include/driver.F90 driver.F90)
30-
add_executable (fhamcrest_tests.x EXCLUDE_FROM_ALL driver.F90)
30+
add_executable (fhamcrest_tests.x driver.F90)
3131
set_source_files_properties(driver.F90 PROPERTIES COMPILE_DEFINITIONS _TEST_SUITES="testSuites.inc")
3232
set_source_files_properties(driver.F90 PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/testSuites.inc)
3333
target_link_libraries(fhamcrest_tests.x fhamcrest_tests)
@@ -38,7 +38,7 @@ add_test(NAME fhamcrest_tests
3838
COMMAND fhamcrest_tests.x
3939
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
4040
)
41-
add_dependencies(tests fhamcrest_tests.x)
41+
add_dependencies(build-tests fhamcrest_tests.x)
4242
set_property (TEST fhamcrest_tests
4343
PROPERTY FAIL_REGULAR_EXPRESSION "Encountered 1 or more failures/errors during testing"
4444
)

tests/funit-core/CMakeLists.txt

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ if (OPENMP_FORTRAN_FOUND)
7676
endif ()
7777

7878

79-
add_library (funit_tests EXCLUDE_FROM_ALL STATIC ${test_srcs})
79+
add_library (funit_tests STATIC ${test_srcs})
8080
target_link_libraries(funit_tests other_shared)
8181

8282
#add_pfunit_sources (new_test_srcs ${pf_tests})
@@ -94,10 +94,17 @@ if (NOT SKIP_ROBUST)
9494
target_compile_definitions(funit_tests.x PRIVATE Robust)
9595
endif ()
9696

97+
add_test(NAME old_tests
98+
COMMAND funit_tests.x
99+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
100+
)
101+
add_dependencies(build-tests funit_tests.x)
102+
97103
if (NOT SKIP_ROBUST)
98104
set (REMOTE_EXE remote.x)
99105
add_executable (${REMOTE_EXE} EXCLUDE_FROM_ALL serialRemoteProgram.F90)
100106
target_link_libraries(${REMOTE_EXE} funit funit_tests)
107+
add_dependencies(funit_tests.x ${REMOTE_EXE})
101108
add_dependencies(tests ${REMOTE_EXE})
102109
endif ()
103110

@@ -107,22 +114,8 @@ add_pfunit_ctest (new_tests.x
107114
LINK_LIBRARIES other_shared
108115
REGISTRY testSuites.inc
109116
)
110-
#add_test(NAME new_tests
111-
# COMMAND new_tests.x
112-
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
113-
# )
114-
115-
add_dependencies(tests new_tests.x)
116-
#set_property (TEST new_tests.x
117-
# PROPERTY FAIL_REGULAR_EXPRESSION "Encountered 1 or more failures/errors during testing"
118-
# )
119-
120-
add_test(NAME old_tests
121-
COMMAND funit_tests.x
122-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
123-
)
124-
add_dependencies(tests funit_tests.x)
125117

118+
add_dependencies(build-tests new_tests.x)
126119
set_property (TEST old_tests
127120
PROPERTY FAIL_REGULAR_EXPRESSION "Encountered 1 or more failures/errors during testing"
128121
)

tests/pfunit/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ add_test(NAME mpi-tests
6363
COMMAND ${MPIEXEC} ${MPIEXEC_PREFLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 ./parallel_tests.x
6464
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
6565
)
66-
add_dependencies(tests parallel_tests.x)
66+
add_dependencies(build-tests parallel_tests.x)
6767

6868
add_test(NAME new_ptests
6969
COMMAND ${MPIEXEC} ${MPIEXEC_PREFLAGS} ${MPIEXEC_NUMPROC_FLAG} 4 ./new_ptests.x
@@ -72,5 +72,4 @@ add_test(NAME new_ptests
7272
set_property (TEST new_ptests
7373
PROPERTY FAIL_REGULAR_EXPRESSION "Encountered 1 or more failures/errors during testing"
7474
)
75-
76-
add_dependencies(tests new_ptests.x)
75+
add_dependencies(build-tests new_ptests.x)

0 commit comments

Comments
 (0)