2020-12-18 19:49:04 +05:30
|
|
|
cmake_minimum_required (VERSION 3.10.0)
|
|
|
|
include (FindPkgConfig REQUIRED)
|
|
|
|
|
2021-05-19 22:52:06 +05:30
|
|
|
if (DEFINED ENV{PETSC_DIR})
|
|
|
|
message ("PETSC_DIR:\n$ENV{PETSC_DIR}\n")
|
|
|
|
else ()
|
2020-01-30 03:14:42 +05:30
|
|
|
message (FATAL_ERROR "PETSc location (PETSC_DIR) is not defined")
|
2017-03-16 03:35:58 +05:30
|
|
|
endif ()
|
2017-05-01 03:00:27 +05:30
|
|
|
|
2021-05-19 22:23:25 +05:30
|
|
|
# Dummy project to determine compiler names and version
|
|
|
|
project (Prerequisites LANGUAGES)
|
|
|
|
set(ENV{PKG_CONFIG_PATH} "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig")
|
|
|
|
pkg_check_modules (PETSC REQUIRED PETSc>=3.12.0 PETSc<3.16.0)
|
|
|
|
pkg_get_variable (CMAKE_Fortran_COMPILER PETSc fcompiler)
|
|
|
|
pkg_get_variable (CMAKE_C_COMPILER PETSc ccompiler)
|
2016-03-06 13:58:20 +05:30
|
|
|
|
2021-05-19 22:23:25 +05:30
|
|
|
# Solver determines name of project
|
2021-07-04 20:31:24 +05:30
|
|
|
string(TOUPPER "${DAMASK_SOLVER}" DAMASK_SOLVER)
|
|
|
|
if (DAMASK_SOLVER STREQUAL "GRID")
|
2020-12-18 19:49:04 +05:30
|
|
|
project (damask-grid HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C)
|
2021-07-04 20:31:24 +05:30
|
|
|
elseif (DAMASK_SOLVER STREQUAL "MESH")
|
2020-12-18 19:49:04 +05:30
|
|
|
project (damask-mesh HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C)
|
2018-05-23 23:21:11 +05:30
|
|
|
else ()
|
2021-07-06 10:18:02 +05:30
|
|
|
message (FATAL_ERROR "Invalid solver: DAMASK_SOLVER=${DAMASK_SOLVER}")
|
2017-03-16 03:35:58 +05:30
|
|
|
endif ()
|
2021-07-04 20:31:24 +05:30
|
|
|
add_definitions ("-D${DAMASK_SOLVER}")
|
2021-05-19 17:56:17 +05:30
|
|
|
|
2021-05-19 18:06:20 +05:30
|
|
|
file (STRINGS ${PROJECT_SOURCE_DIR}/VERSION DAMASK_VERSION)
|
2021-05-19 17:56:17 +05:30
|
|
|
|
2021-05-19 22:23:25 +05:30
|
|
|
message ("\nBuilding ${CMAKE_PROJECT_NAME} ${DAMASK_VERSION}\n")
|
2020-12-18 19:49:04 +05:30
|
|
|
|
2021-07-08 18:35:01 +05:30
|
|
|
add_definitions (-DPETSC)
|
2021-05-19 22:23:25 +05:30
|
|
|
add_definitions (-DDAMASKVERSION="${DAMASK_VERSION}")
|
2017-05-01 03:00:27 +05:30
|
|
|
|
2018-05-24 10:43:12 +05:30
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "")
|
2020-01-30 03:14:42 +05:30
|
|
|
set (CMAKE_BUILD_TYPE "RELEASE")
|
2017-04-25 16:05:19 +05:30
|
|
|
endif ()
|
2021-07-06 10:18:02 +05:30
|
|
|
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE)
|
2017-04-25 16:05:19 +05:30
|
|
|
|
2017-02-04 05:31:42 +05:30
|
|
|
# Predefined sets for OPTIMIZATION/OPENMP based on BUILD_TYPE
|
2018-05-24 10:43:12 +05:30
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "SYNTAXONLY")
|
2017-10-03 18:50:53 +05:30
|
|
|
set (DEBUG_FLAGS "${DEBUG_FLAGS} -DDEBUG")
|
2017-02-04 05:31:42 +05:30
|
|
|
set (PARALLEL "OFF")
|
|
|
|
set (OPTI "OFF")
|
2018-05-24 10:43:12 +05:30
|
|
|
elseif (CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
2017-02-04 05:31:42 +05:30
|
|
|
set (PARALLEL "ON")
|
|
|
|
set (OPTI "DEFENSIVE")
|
2021-07-06 10:18:02 +05:30
|
|
|
elseif (CMAKE_BUILD_TYPE STREQUAL "DEBUGRELEASE")
|
|
|
|
set (DEBUG_FLAGS "${DEBUG_FLAGS} -DDEBUG")
|
|
|
|
set (PARALLEL "ON")
|
|
|
|
set (OPTI "DEFENSIVE")
|
2018-05-24 10:43:12 +05:30
|
|
|
elseif (CMAKE_BUILD_TYPE STREQUAL "PERFORMANCE")
|
2017-02-04 05:31:42 +05:30
|
|
|
set (PARALLEL "ON")
|
|
|
|
set (OPTI "AGGRESSIVE")
|
2021-07-06 10:18:02 +05:30
|
|
|
else ()
|
|
|
|
message (FATAL_ERROR "Invalid build type: CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
|
2017-03-16 03:35:58 +05:30
|
|
|
endif ()
|
2017-03-16 03:10:44 +05:30
|
|
|
|
|
|
|
# $OPTIMIZATION takes precedence over $BUILD_TYPE defaults
|
2019-04-27 21:25:06 +05:30
|
|
|
if (OPTIMIZATION STREQUAL "" OR NOT DEFINED OPTIMIZATION)
|
2017-03-16 03:10:44 +05:30
|
|
|
set (OPTIMIZATION "${OPTI}")
|
2017-03-16 03:35:58 +05:30
|
|
|
else ()
|
2017-03-16 03:10:44 +05:30
|
|
|
set (OPTIMIZATION "${OPTIMIZATION}")
|
2017-03-16 03:35:58 +05:30
|
|
|
endif ()
|
2017-03-16 03:10:44 +05:30
|
|
|
|
|
|
|
# $OPENMP takes precedence over $BUILD_TYPE defaults
|
2019-04-27 21:25:06 +05:30
|
|
|
if (OPENMP STREQUAL "" OR NOT DEFINED OPENMP)
|
2017-03-16 03:10:44 +05:30
|
|
|
set (OPENMP "${PARALLEL}")
|
2017-03-16 03:35:58 +05:30
|
|
|
else ()
|
2017-02-04 05:31:42 +05:30
|
|
|
set(OPENMP "${OPENMP}")
|
2017-03-16 03:35:58 +05:30
|
|
|
endif ()
|
2017-04-18 10:44:55 +05:30
|
|
|
|
2020-03-29 22:36:17 +05:30
|
|
|
# syntax check only (mainly for pre-receive hook)
|
2018-05-24 10:43:12 +05:30
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "SYNTAXONLY")
|
2017-04-18 10:44:55 +05:30
|
|
|
set (BUILDCMD_POST "${BUILDCMD_POST} -fsyntax-only")
|
|
|
|
endif ()
|
2017-02-04 05:31:42 +05:30
|
|
|
|
2016-03-06 13:58:20 +05:30
|
|
|
|
2020-12-18 19:49:04 +05:30
|
|
|
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
2020-01-26 19:40:27 +05:30
|
|
|
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
|
2020-01-30 03:14:42 +05:30
|
|
|
include (Compiler-Intel)
|
2018-05-24 10:43:12 +05:30
|
|
|
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
2020-01-30 03:14:42 +05:30
|
|
|
include (Compiler-GNU)
|
2018-05-24 11:27:10 +05:30
|
|
|
else ()
|
2020-01-30 03:14:42 +05:30
|
|
|
message (FATAL_ERROR "Compiler type (CMAKE_Fortran_COMPILER_ID) not recognized")
|
2017-03-16 03:35:58 +05:30
|
|
|
endif ()
|
2016-03-08 04:30:12 +05:30
|
|
|
|
2021-05-19 22:52:06 +05:30
|
|
|
file (STRINGS "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/petsc/conf/petscvariables" PETSC_EXTERNAL_LIB REGEX "PETSC_WITH_EXTERNAL_LIB = .*$?")
|
2021-05-19 22:23:25 +05:30
|
|
|
string (REGEX MATCHALL "-[lLW]([^\" ]+)" PETSC_EXTERNAL_LIB "${PETSC_EXTERNAL_LIB}")
|
|
|
|
list (REMOVE_DUPLICATES PETSC_EXTERNAL_LIB)
|
|
|
|
string (REPLACE ";" " " PETSC_EXTERNAL_LIB "${PETSC_EXTERNAL_LIB}")
|
|
|
|
message ("PETSC_EXTERNAL_LIB:\n${PETSC_EXTERNAL_LIB}\n")
|
|
|
|
|
2021-05-19 22:52:06 +05:30
|
|
|
file (STRINGS "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/petsc/conf/petscvariables" PETSC_INCLUDES REGEX "PETSC_FC_INCLUDES = .*$?")
|
2021-05-19 22:23:25 +05:30
|
|
|
string (REGEX MATCHALL "-I([^\" ]+)" PETSC_INCLUDES "${PETSC_INCLUDES}")
|
|
|
|
list (REMOVE_DUPLICATES PETSC_INCLUDES)
|
|
|
|
string (REPLACE ";" " " PETSC_INCLUDES "${PETSC_INCLUDES}")
|
|
|
|
message ("PETSC_INCLUDES:\n${PETSC_INCLUDES}\n")
|
|
|
|
|
2017-04-26 13:10:45 +05:30
|
|
|
set (CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE} "${BUILDCMD_PRE} ${OPENMP_FLAGS} ${STANDARD_CHECK} ${OPTIMIZATION_FLAGS} ${COMPILE_FLAGS} ${PRECISION_FLAGS}")
|
2020-12-18 19:49:04 +05:30
|
|
|
set (CMAKE_Fortran_LINK_EXECUTABLE "${BUILDCMD_PRE} ${CMAKE_Fortran_COMPILER} ${OPENMP_FLAGS} ${OPTIMIZATION_FLAGS} ${LINKER_FLAGS}")
|
2016-05-21 18:36:01 +05:30
|
|
|
|
2018-05-24 10:43:12 +05:30
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
|
2020-01-30 03:14:42 +05:30
|
|
|
set (CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE} "${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}} ${DEBUG_FLAGS}")
|
|
|
|
set (CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} ${DEBUG_FLAGS}")
|
2017-03-16 03:35:58 +05:30
|
|
|
endif ()
|
2016-05-21 18:36:01 +05:30
|
|
|
|
2020-01-04 19:07:09 +05:30
|
|
|
set (CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE} "${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}} ${PETSC_INCLUDES} ${BUILDCMD_POST}")
|
2020-09-06 21:19:00 +05:30
|
|
|
set (CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} <OBJECTS> -o <TARGET> <LINK_LIBRARIES> ${PETSC_EXTERNAL_LIB} -lz ${BUILDCMD_POST}")
|
2016-03-02 20:07:12 +05:30
|
|
|
|
2017-04-26 13:10:45 +05:30
|
|
|
message ("Fortran Compiler Flags:\n${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}}\n")
|
|
|
|
message ("C Compiler Flags:\n${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}\n")
|
|
|
|
message ("Fortran Linker Command:\n${CMAKE_Fortran_LINK_EXECUTABLE}\n")
|
2016-02-26 23:00:57 +05:30
|
|
|
|
2017-02-04 03:53:55 +05:30
|
|
|
# location of code
|
2017-03-16 03:10:44 +05:30
|
|
|
add_subdirectory (src)
|