11# run by:
22# ctest -S setup.cmake
33
4+ # --- Project-specific -Doptions
5+ # these will be used if the project isn't already configured.
6+ set (_opts)
7+
8+ # --- boilerplate follows
9+ message (STATUS "CMake ${CMAKE_VERSION} " )
10+ if (CMAKE_VERSION VERSION_LESS 3.15)
11+ message (FATAL_ERROR "Please update CMake >= 3.15" )
12+ endif ()
13+
414# site is OS name
515if (NOT DEFINED CTEST_SITE)
616 set (CTEST_SITE ${CMAKE_SYSTEM_NAME} )
717endif ()
818
9- # if compiler specified, deduce its ID
19+ # test name is Fortran compiler in FC
20+ # Note: ctest scripts cannot read cache variables like CMAKE_Fortran_COMPILER
1021if (DEFINED ENV{FC})
11- set (FC $ENV{FC} )
12- endif ()
13- if (DEFINED CMAKE_Fortran_COMPILER)
14- set (FC ${CMAKE_Fortran_COMPILER} )
15- endif ()
16- if (DEFINED FC)
17- foreach (c gfortran ifort flang pgfortran nagfor xlf ftn)
18- string (FIND ${FC} ${c} i)
19- if (i GREATER_EQUAL 0)
20- if (c STREQUAL gfortran)
21- execute_process (COMMAND gfortran -dumpversion
22- RESULT_VARIABLE _ret
23- OUTPUT_VARIABLE _vers OUTPUT_STRIP_TRAILING_WHITESPACE)
24- if (_ret EQUAL 0)
25- string (APPEND c "-${_vers} " )
26- endif ()
27- endif ()
28- set (CTEST_BUILD_NAME ${c} )
29- break ()
30- endif ()
31- endforeach ()
22+ set (CTEST_BUILD_NAME $ENV{FC} )
3223endif ()
3324
3425if (NOT DEFINED CTEST_BUILD_CONFIGURATION)
@@ -40,19 +31,32 @@ if(NOT DEFINED CTEST_BINARY_DIRECTORY)
4031 set (CTEST_BINARY_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} /build )
4132endif ()
4233
34+ # CTEST_CMAKE_GENERATOR must be defined in any case here.
4335if (NOT DEFINED CTEST_CMAKE_GENERATOR)
4436 find_program (_gen NAMES ninja ninja-build samu)
4537 if (_gen)
4638 set (CTEST_CMAKE_GENERATOR "Ninja" )
4739 elseif (WIN32 )
4840 set (CTEST_CMAKE_GENERATOR "MinGW Makefiles" )
41+ set (CTEST_BUILD_FLAGS -j) # not --parallel as this goes to generator directly
4942 else ()
5043 set (CTEST_CMAKE_GENERATOR "Unix Makefiles" )
44+ set (CTEST_BUILD_FLAGS -j) # not --parallel as this goes to generator directly
5145 endif ()
5246endif ()
5347
5448ctest_start ("Experimental" ${CTEST_SOURCE_DIRECTORY} ${CTEST_BINARY_DIRECTORY} )
55- ctest_configure (BUILD ${CTEST_BINARY_DIRECTORY} SOURCE ${CTEST_SOURCE_DIRECTORY} )
49+ if (NOT EXISTS ${CTEST_BINARY_DIRECTORY} /CMakeCache.txt)
50+ ctest_configure (BUILD ${CTEST_BINARY_DIRECTORY} SOURCE ${CTEST_SOURCE_DIRECTORY} OPTIONS "${_opts} " )
51+ endif ()
5652ctest_build (BUILD ${CTEST_BINARY_DIRECTORY} CONFIGURATION ${CTEST_BUILD_CONFIGURATION} )
5753ctest_test (BUILD ${CTEST_BINARY_DIRECTORY} )
58- ctest_submit ()
54+
55+ # using ctest_submit makes error code 0 even if test(s) failed!
56+ if (DEFINED ENV{CI})
57+ set (CI $ENV{CI} )
58+ endif ()
59+
60+ if (NOT CI)
61+ ctest_submit ()
62+ endif ()
0 commit comments