Skip to content

Commit

Permalink
cmake template
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Dec 21, 2020
1 parent 8721190 commit f04ded9
Showing 1 changed file with 23 additions and 42 deletions.
65 changes: 23 additions & 42 deletions src/iri2016/setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,12 @@ set(_opts)

# --- boilerplate follows
message(STATUS "CMake ${CMAKE_VERSION}")
if(CMAKE_VERSION VERSION_LESS 3.13)
message(FATAL_ERROR "Please update CMake >= 3.13.
if(CMAKE_VERSION VERSION_LESS 3.15)
message(FATAL_ERROR "Please update CMake >= 3.15.
Try 'pip install -U cmake' or https://cmake.org/download/")
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.
# CTEST_CMAKE_GENERATOR must always be defined
if(NOT DEFINED CTEST_CMAKE_GENERATOR AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
find_program(_gen NAMES ninja ninja-build samu)
if(_gen)
Expand All @@ -64,15 +27,33 @@ if(NOT DEFINED CTEST_CMAKE_GENERATOR AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.1
endif(_gen)
endif()
if(NOT DEFINED CTEST_CMAKE_GENERATOR)
set(CTEST_BUILD_FLAGS -j) # not --parallel as this goes to generator directly
if(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()

# 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")

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()

# -- build and test
ctest_start("Experimental" ${CTEST_SOURCE_DIRECTORY} ${CTEST_BINARY_DIRECTORY})

Expand Down

0 comments on commit f04ded9

Please sign in to comment.