-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
182 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: ci_cmake | ||
|
||
on: | ||
push: | ||
paths: | ||
- "**/*.f90" | ||
- "**/CMakeLists.txt" | ||
- ".github/workflows/ci_cmake.yml" | ||
|
||
jobs: | ||
|
||
linux: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- run: ctest -S setup.cmake -VV | ||
env: | ||
FC: gfortran-9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release CACHE STRING "default build type") | ||
endif() | ||
project(LunarLander1969 | ||
LANGUAGES Fortran) | ||
enable_testing() | ||
|
||
add_executable(lunar-lander lunar.f90) | ||
|
||
find_package(Python3 COMPONENTS Interpreter) | ||
|
||
if(Python3_FOUND) | ||
add_test(NAME basic COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_stdin.py $<TARGET_FILE:lunar-lander> ${CMAKE_CURRENT_SOURCE_DIR}/good.asc --args='-f\ 16000') | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# run by: | ||
# ctest -S setup.cmake | ||
|
||
# --- Project-specific -Doptions | ||
# these will be used if the project isn't already configured. | ||
set(_opts) | ||
|
||
# --- boilerplate follows | ||
message(STATUS "CMake ${CMAKE_VERSION}") | ||
if(CMAKE_VERSION VERSION_LESS 3.14) | ||
message(FATAL_ERROR "Please update CMake >= 3.14") | ||
endif() | ||
|
||
# site is OS name | ||
if(NOT DEFINED CTEST_SITE) | ||
set(CTEST_SITE ${CMAKE_SYSTEM_NAME}) | ||
endif() | ||
|
||
# parallel test--use ctest_test(PARALLEL_LEVEL ${Ncpu} as setting CTEST_PARALLEL_LEVEL has no effect | ||
include(ProcessorCount) | ||
ProcessorCount(Ncpu) | ||
message(STATUS "${Ncpu} CPU cores detected") | ||
|
||
# test name is Fortran compiler in FC | ||
# Note: ctest scripts cannot read cache variables like CMAKE_Fortran_COMPILER | ||
if(DEFINED ENV{FC}) | ||
set(FC $ENV{FC}) | ||
set(CTEST_BUILD_NAME ${FC}) | ||
|
||
if(NOT DEFINED ENV{CC}) | ||
# use same compiler for C and Fortran, which CMake might not do itself | ||
if(FC STREQUAL ifort) | ||
if(WIN32) | ||
set(ENV{CC} icl) | ||
else() | ||
set(ENV{CC} icc) | ||
endif() | ||
endif() | ||
endif() | ||
endif() | ||
|
||
if(NOT DEFINED CTEST_BUILD_CONFIGURATION) | ||
set(CTEST_BUILD_CONFIGURATION "Release") | ||
endif() | ||
|
||
set(CTEST_SOURCE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) | ||
if(NOT DEFINED CTEST_BINARY_DIRECTORY) | ||
set(CTEST_BINARY_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/build) | ||
endif() | ||
|
||
# CTEST_CMAKE_GENERATOR must be defined in any case here. | ||
if(NOT DEFINED CTEST_CMAKE_GENERATOR) | ||
find_program(_gen NAMES ninja ninja-build samu) | ||
if(_gen) | ||
set(CTEST_CMAKE_GENERATOR "Ninja") | ||
elseif(WIN32) | ||
set(CTEST_CMAKE_GENERATOR "MinGW Makefiles") | ||
set(CTEST_BUILD_FLAGS -j) # not --parallel as this goes to generator directly | ||
else() | ||
set(CTEST_CMAKE_GENERATOR "Unix Makefiles") | ||
set(CTEST_BUILD_FLAGS -j) # not --parallel as this goes to generator directly | ||
endif() | ||
endif() | ||
|
||
# -- build and test | ||
ctest_start("Experimental" ${CTEST_SOURCE_DIRECTORY} ${CTEST_BINARY_DIRECTORY}) | ||
|
||
ctest_configure( | ||
BUILD ${CTEST_BINARY_DIRECTORY} | ||
SOURCE ${CTEST_SOURCE_DIRECTORY} | ||
OPTIONS "${_opts}" | ||
RETURN_VALUE return_code | ||
CAPTURE_CMAKE_ERROR cmake_err) | ||
|
||
# if it's a generator or compiler mismatch, delete cache and try again | ||
if(NOT cmake_err EQUAL 0) | ||
file(REMOVE ${CTEST_BINARY_DIRECTORY}/CMakeCache.txt) | ||
|
||
ctest_configure( | ||
BUILD ${CTEST_BINARY_DIRECTORY} | ||
SOURCE ${CTEST_SOURCE_DIRECTORY} | ||
OPTIONS "${_opts}" | ||
RETURN_VALUE return_code | ||
CAPTURE_CMAKE_ERROR cmake_err) | ||
endif() | ||
|
||
if(return_code EQUAL 0 AND cmake_err EQUAL 0) | ||
ctest_build( | ||
BUILD ${CTEST_BINARY_DIRECTORY} | ||
CONFIGURATION ${CTEST_BUILD_CONFIGURATION} | ||
RETURN_VALUE return_code | ||
NUMBER_ERRORS Nerror | ||
CAPTURE_CMAKE_ERROR cmake_err | ||
) | ||
else() | ||
message(STATUS "SKIP: ctest_build(): returncode: ${return_code}; CMake error code: ${cmake_err}") | ||
endif() | ||
|
||
if(return_code EQUAL 0 AND Nerror EQUAL 0 AND cmake_err EQUAL 0) | ||
ctest_test( | ||
BUILD ${CTEST_BINARY_DIRECTORY} | ||
RETURN_VALUE return_code | ||
CAPTURE_CMAKE_ERROR ctest_err | ||
PARALLEL_LEVEL ${Ncpu} | ||
) | ||
else() | ||
message(STATUS "SKIP: ctest_test(): returncode: ${return_code}; CMake error code: ${cmake_err}") | ||
endif() | ||
|
||
# ctest_submit() | ||
|
||
if(NOT (return_code EQUAL 0 AND Nerror EQUAL 0 AND cmake_err EQUAL 0 AND ctest_err EQUAL 0)) | ||
message(FATAL_ERROR "Build and test failed.") | ||
endif() |