Skip to content

Commit

Permalink
Fix up ctest
Browse files Browse the repository at this point in the history
  • Loading branch information
mathomp4 committed Jul 8, 2024
1 parent b652e9c commit c2a7c05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
/mpi_pFUnit.x
/nag
*.zip
build/
build/
Testing/
43 changes: 23 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ if (APPLE)
SET(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif ()

# Enable testing before adding subdirectories
# to catch any tests in the main project
if (ENABLE_TESTS)
enable_testing()
endif ()

include(build_submodule)
# Find fArgParse first so that gFTL and gFTL-shared are consistent
build_submodule(extern/fArgParse PROJECT FARGPARSE TARGET FARGPARSE::fargparse)
Expand All @@ -150,28 +156,25 @@ if (ENABLE_BUILD_DOXYGEN)
add_subdirectory(documentation)
endif()

if (ENABLE_TESTS)
enable_testing()
if (NOT TARGET build-tests)
add_custom_target(build-tests)
endif()

if (NOT TARGET tests)
add_custom_target(tests
COMMAND ${CMAKE_CTEST_COMMAND}
EXCLUDE_FROM_ALL)
endif ()
add_dependencies(tests build-tests)
add_subdirectory (tests EXCLUDE_FROM_ALL)

# The following forces tests to be built when using "make ctest" even if some targets
# are EXCLUDE_FROM_ALL
# From https://stackoverflow.com/questions/733475/cmake-ctest-make-test-doesnt-build-tests/56448477#56448477
build_command(CTEST_CUSTOM_PRE_TEST TARGET build-tests)
string(CONFIGURE \"@CTEST_CUSTOM_PRE_TEST@\" CTEST_CUSTOM_PRE_TEST_QUOTED ESCAPE_QUOTES)
file(WRITE "${CMAKE_BINARY_DIR}/CTestCustom.cmake" "set(CTEST_CUSTOM_PRE_TEST ${CTEST_CUSTOM_PRE_TEST_QUOTED})" "\n")
if (NOT TARGET build-tests)
add_custom_target(build-tests)
endif()

if (NOT TARGET tests)
add_custom_target(tests
COMMAND ${CMAKE_CTEST_COMMAND}
EXCLUDE_FROM_ALL)
endif ()
add_dependencies(tests build-tests)
add_subdirectory (tests EXCLUDE_FROM_ALL)

# The following forces tests to be built when using "make ctest" even if some targets
# are EXCLUDE_FROM_ALL
# From https://stackoverflow.com/questions/733475/cmake-ctest-make-test-doesnt-build-tests/56448477#56448477
build_command(CTEST_CUSTOM_PRE_TEST TARGET build-tests)
string(CONFIGURE \"@CTEST_CUSTOM_PRE_TEST@\" CTEST_CUSTOM_PRE_TEST_QUOTED ESCAPE_QUOTES)
file(WRITE "${CMAKE_BINARY_DIR}/CTestCustom.cmake" "set(CTEST_CUSTOM_PRE_TEST ${CTEST_CUSTOM_PRE_TEST_QUOTED})" "\n")

# The following is needed for external projects using *nix make when
# parent project builds pFUnit as a subproject.
set (top_dir PFUNIT-${PFUNIT_VERSION_MAJOR}.${PFUNIT_VERSION_MINOR})
Expand Down

0 comments on commit c2a7c05

Please sign in to comment.