diff --git a/modules/build_info.cmake b/modules/build_info.cmake index 4aa117a..4cd4e39 100644 --- a/modules/build_info.cmake +++ b/modules/build_info.cmake @@ -1,7 +1,12 @@ #.rst: # -# Generates source code that echoes configuration and build +# Generates source code that echoes configuration, version, and build # information to the program output. +# +# Example autocmake.cfg entry:: +# +# [build_info] +# source: https://github.com/scisoft/autocmake/raw/master/modules/build_info.cmake find_package(PythonInterp REQUIRED) diff --git a/modules/mpi.cmake b/modules/mpi.cmake index 285fd63..a214b33 100644 --- a/modules/mpi.cmake +++ b/modules/mpi.cmake @@ -1,10 +1,32 @@ +#.rst: +# +# Enables MPI support. +# +# Variables used:: +# +# ENABLE_MPI +# MPI_FOUND +# +# Variables modified (provided the corresponding language is enabled):: +# +# CMAKE_Fortran_FLAGS +# +# Example autocmake.cfg entry:: +# +# [mpi] +# source: https://github.com/scisoft/autocmake/raw/master/modules/mpi.cmake +# docopt: --mpi Enable MPI parallelization [default: False]. +# define: '-DENABLE_MPI=%s' % arguments['--mpi'] + option(ENABLE_MPI "Enable MPI parallelization" OFF) # on Cray configure with -D MPI_FOUND=1 if(ENABLE_MPI AND NOT MPI_FOUND) find_package(MPI) if(MPI_FOUND) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${MPI_COMPILE_FLAGS}") + if(DEFINED CMAKE_Fortran_COMPILER_ID) + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${MPI_COMPILE_FLAGS}") + endif() include_directories(${MPI_INCLUDE_PATH}) else() message(FATAL_ERROR "-- You asked for MPI, but CMake could not find any MPI installation, check $PATH") diff --git a/modules/omp.cmake b/modules/omp.cmake index df16146..58f8e43 100644 --- a/modules/omp.cmake +++ b/modules/omp.cmake @@ -1,9 +1,38 @@ +#.rst: +# +# Enables OpenMP support. +# +# Variables used:: +# +# ENABLE_OPENMP +# OPENMP_FOUND +# +# Variables modified (provided the corresponding language is enabled):: +# +# CMAKE_Fortran_FLAGS +# CMAKE_C_FLAGS +# CMAKE_CXX_FLAGS +# +# Example autocmake.cfg entry:: +# +# [omp] +# source: https://github.com/scisoft/autocmake/raw/master/modules/omp.cmake +# docopt: --omp Enable OpenMP parallelization [default: False]. +# define: '-DENABLE_OPENMP=%s' % arguments['--omp'] + option(ENABLE_OPENMP "Enable OpenMP parallelization" OFF) if(ENABLE_OPENMP) find_package(OpenMP) if(OPENMP_FOUND) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_C_FLAGS}") + if(DEFINED CMAKE_Fortran_COMPILER_ID) + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_C_FLAGS}") + endif() + if(DEFINED CMAKE_C_COMPILER_ID) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + endif() + if(DEFINED CMAKE_CXX_COMPILER_ID) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + endif() endif() endif() diff --git a/modules/preprocessing.cmake b/modules/preprocessing.cmake deleted file mode 100644 index 6c0d998..0000000 --- a/modules/preprocessing.cmake +++ /dev/null @@ -1,7 +0,0 @@ -set(CPP) - -# forward preprocessing directly to the code -if(NOT "${CPP}" STREQUAL "") - add_definitions(${CPP}) -endif() - diff --git a/modules/python.cmake b/modules/python.cmake index c499b48..976aa59 100644 --- a/modules/python.cmake +++ b/modules/python.cmake @@ -1 +1,14 @@ +#.rst: +# +# Detects Python interpreter. +# +# Variables set:: +# +# PYTHON_EXECUTABLE +# +# Example autocmake.cfg entry:: +# +# [python] +# source: https://github.com/scisoft/autocmake/raw/master/modules/python.cmake + find_package(PythonInterp REQUIRED) diff --git a/modules/safeguards.cmake b/modules/safeguards.cmake index a354892..d7a83fe 100644 --- a/modules/safeguards.cmake +++ b/modules/safeguards.cmake @@ -20,8 +20,8 @@ endif() string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower) string(TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_toupper) -if( NOT cmake_build_type_tolower STREQUAL "debug" - AND NOT cmake_build_type_tolower STREQUAL "release" - AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo") +if(NOT cmake_build_type_tolower STREQUAL "debug" AND + NOT cmake_build_type_tolower STREQUAL "release" AND + NOT cmake_build_type_tolower STREQUAL "relwithdebinfo") message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).") endif() diff --git a/modules/src.cmake b/modules/src.cmake index 1abaddf..8df35d2 100644 --- a/modules/src.cmake +++ b/modules/src.cmake @@ -1,5 +1,10 @@ #.rst: # # Adds ${PROJECT_SOURCE_DIR}/src as subdirectory containing CMakeLists.txt. +# +# Example autocmake.cfg entry:: +# +# [src] +# source: https://github.com/scisoft/autocmake/raw/master/modules/src.cmake add_subdirectory(${PROJECT_SOURCE_DIR}/src) diff --git a/modules/version.cmake b/modules/version.cmake index 518cfab..28fb4a8 100644 --- a/modules/version.cmake +++ b/modules/version.cmake @@ -9,6 +9,11 @@ # Variables defined:: # # PROGRAM_VERSION +# +# Example autocmake.cfg entry:: +# +# [version] +# source: https://github.com/scisoft/autocmake/raw/master/modules/version.cmake if(EXISTS "${PROJECT_SOURCE_DIR}/VERSION") file(READ "${PROJECT_SOURCE_DIR}/VERSION" PROGRAM_VERSION)