2016-02-26 03:03:21 +05:30
|
|
|
########################################################################################
|
2017-02-04 03:53:55 +05:30
|
|
|
# Compiler options for building DAMASK
|
2019-10-19 00:21:15 +05:30
|
|
|
cmake_minimum_required (VERSION 3.10.0 FATAL_ERROR)
|
2016-02-26 03:03:21 +05:30
|
|
|
|
2016-03-06 13:58:20 +05:30
|
|
|
#---------------------------------------------------------------------------------------
|
2016-04-20 00:22:36 +05:30
|
|
|
# Find PETSc from system environment
|
2016-04-19 04:02:08 +05:30
|
|
|
set(PETSC_DIR $ENV{PETSC_DIR})
|
2018-05-24 10:43:12 +05:30
|
|
|
if (PETSC_DIR STREQUAL "")
|
2018-05-24 11:27:10 +05:30
|
|
|
message (FATAL_ERROR "PETSc location (PETSC_DIR) is not defined")
|
2017-03-16 03:35:58 +05:30
|
|
|
endif ()
|
2017-03-16 03:10:44 +05:30
|
|
|
|
|
|
|
set (petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables")
|
|
|
|
set (petsc_conf_rules "${PETSC_DIR}/lib/petsc/conf/rules" )
|
2016-04-19 04:02:08 +05:30
|
|
|
|
2017-02-04 03:53:55 +05:30
|
|
|
# Use existing variables from PETSc
|
2016-03-01 21:06:48 +05:30
|
|
|
# https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake
|
2016-04-20 00:22:36 +05:30
|
|
|
|
2016-05-18 12:24:16 +05:30
|
|
|
# Generate a temporary makefile to probe the PETSc configuration
|
2020-01-26 19:40:27 +05:30
|
|
|
# This file will be deleted once the settings from PETSc are parsed into CMake
|
2017-03-16 03:10:44 +05:30
|
|
|
exec_program (mktemp ARGS -d OUTPUT_VARIABLE TEMPDIR)
|
|
|
|
set (petsc_config_makefile "${TEMPDIR}/Makefile.petsc")
|
2016-05-18 12:24:16 +05:30
|
|
|
file (WRITE
|
|
|
|
"${petsc_config_makefile}"
|
2016-03-03 02:09:31 +05:30
|
|
|
"## This file was auto generated by CMake
|
2016-03-01 21:06:48 +05:30
|
|
|
# PETSC_DIR = ${PETSC_DIR}
|
2016-03-01 23:53:47 +05:30
|
|
|
SHELL = /bin/sh
|
2016-03-01 21:06:48 +05:30
|
|
|
include ${petsc_conf_rules}
|
|
|
|
include ${petsc_conf_variables}
|
2016-03-06 20:00:16 +05:30
|
|
|
INCLUDE_DIRS := \${PETSC_FC_INCLUDES}
|
|
|
|
LIBRARIES := \${PETSC_WITH_EXTERNAL_LIB}
|
2016-05-21 18:36:01 +05:30
|
|
|
COMPILERF := \${FC}
|
|
|
|
COMPILERC := \${CC}
|
|
|
|
LINKERNAME := \${FLINKER}
|
2016-03-01 23:53:47 +05:30
|
|
|
includes:
|
|
|
|
\t@echo \${INCLUDE_DIRS}
|
|
|
|
extlibs:
|
|
|
|
\t@echo \${LIBRARIES}
|
2016-03-06 20:00:16 +05:30
|
|
|
compilerf:
|
|
|
|
\t@echo \${COMPILERF}
|
|
|
|
compilerc:
|
|
|
|
\t@echo \${COMPILERC}
|
2016-03-01 23:53:47 +05:30
|
|
|
linker:
|
2016-05-18 12:24:16 +05:30
|
|
|
\t@echo \${LINKERNAME}
|
|
|
|
")
|
2016-03-06 04:05:34 +05:30
|
|
|
|
2016-03-06 20:00:16 +05:30
|
|
|
# CMake will execute each target in the ${petsc_config_makefile}
|
|
|
|
# to acquire corresponding PETSc Variables.
|
2018-11-24 19:31:28 +05:30
|
|
|
find_program (MAKE_EXECUTABLE NAMES gmake make)
|
2016-03-06 20:00:16 +05:30
|
|
|
# Find the PETSc includes directory settings
|
2017-03-16 03:10:44 +05:30
|
|
|
execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} "includes"
|
|
|
|
RESULT_VARIABLE PETSC_INCLUDES_RETURN
|
|
|
|
OUTPUT_VARIABLE petsc_includes
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2016-03-06 20:00:16 +05:30
|
|
|
# Find the PETSc external linking directory settings
|
2017-04-25 16:05:19 +05:30
|
|
|
# required for final linking, must be appended after the executable
|
2017-03-16 03:10:44 +05:30
|
|
|
execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} "extlibs"
|
|
|
|
RESULT_VARIABLE PETSC_EXTERNAL_LIB_RETURN
|
|
|
|
OUTPUT_VARIABLE petsc_external_lib
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2016-05-21 18:36:01 +05:30
|
|
|
# PETSc specified fortran compiler
|
2017-03-16 03:10:44 +05:30
|
|
|
execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} "compilerf"
|
|
|
|
RESULT_VARIABLE PETSC_MPIFC_RETURN
|
|
|
|
OUTPUT_VARIABLE PETSC_MPIFC
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2016-05-21 18:36:01 +05:30
|
|
|
# PETSc specified C compiler
|
2017-03-16 03:10:44 +05:30
|
|
|
execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} "compilerc"
|
|
|
|
RESULT_VARIABLE PETSC_MPICC_RETURN
|
|
|
|
OUTPUT_VARIABLE PETSC_MPICC
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2020-01-26 19:40:27 +05:30
|
|
|
# PETSc specified linker (Fortran compiler + PETSc linking flags)
|
2017-03-16 03:10:44 +05:30
|
|
|
execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} "linker"
|
|
|
|
RESULT_VARIABLE PETSC_LINKER_RETURN
|
|
|
|
OUTPUT_VARIABLE PETSC_LINKER
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2016-03-06 20:00:16 +05:30
|
|
|
# Remove temporary makefile, no need to keep it anymore.
|
2017-03-16 03:10:44 +05:30
|
|
|
file (REMOVE_RECURSE ${TEMPDIR})
|
2016-03-06 20:00:16 +05:30
|
|
|
|
2017-02-04 03:53:55 +05:30
|
|
|
# Remove duplicate compiler and linker flags
|
2017-03-16 03:10:44 +05:30
|
|
|
string (REGEX MATCHALL "-I([^\" ]+)" TMP_LIST "${petsc_includes}")
|
|
|
|
list (REMOVE_DUPLICATES TMP_LIST)
|
2016-03-06 20:00:16 +05:30
|
|
|
foreach (dir ${TMP_LIST})
|
2017-03-16 03:10:44 +05:30
|
|
|
set (PETSC_INCLUDES "${PETSC_INCLUDES} ${dir}")
|
|
|
|
endforeach (dir)
|
|
|
|
string (REGEX MATCHALL "-[lLW]([^\" ]+)" TMP_LIST "${petsc_external_lib}")
|
|
|
|
list (REMOVE_DUPLICATES TMP_LIST)
|
2016-03-06 20:00:16 +05:30
|
|
|
foreach (exlib ${TMP_LIST})
|
2017-03-16 03:10:44 +05:30
|
|
|
set (PETSC_EXTERNAL_LIB "${PETSC_EXTERNAL_LIB} ${exlib}")
|
|
|
|
endforeach (exlib)
|
2016-03-06 20:00:16 +05:30
|
|
|
|
2017-03-16 03:10:44 +05:30
|
|
|
message ("Found PETSC_DIR:\n${PETSC_DIR}\n" )
|
|
|
|
message ("Found PETSC_INCLUDES:\n${PETSC_INCLUDES}\n" )
|
|
|
|
message ("Found PETSC_EXTERNAL_LIB:\n${PETSC_EXTERNAL_LIB}\n")
|
|
|
|
message ("Found PETSC_LINKER:\n${PETSC_LINKER}\n" )
|
|
|
|
message ("Found MPI Fortran Compiler:\n${PETSC_MPIFC}\n" )
|
|
|
|
message ("Found MPI C Compiler:\n${PETSC_MPICC}\n" )
|
2016-03-07 22:24:36 +05:30
|
|
|
|
2017-05-01 03:00:27 +05:30
|
|
|
# set compiler commands to match PETSc (needs to be done before defining the project)
|
|
|
|
# https://cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F
|
|
|
|
set (CMAKE_Fortran_COMPILER "${PETSC_MPIFC}")
|
|
|
|
set (CMAKE_C_COMPILER "${PETSC_MPICC}")
|
|
|
|
|
2016-03-06 13:58:20 +05:30
|
|
|
#---------------------------------------------------------------------------------------
|
|
|
|
# Now start to care about DAMASK
|
|
|
|
|
2017-03-16 03:10:44 +05:30
|
|
|
# DAMASK solver defines project to build
|
2019-04-28 16:24:59 +05:30
|
|
|
string(TOLOWER ${DAMASK_SOLVER} DAMASK_SOLVER)
|
|
|
|
if (DAMASK_SOLVER STREQUAL "grid")
|
2019-04-25 10:38:32 +05:30
|
|
|
project (damask-grid Fortran C)
|
2019-03-23 13:57:58 +05:30
|
|
|
add_definitions (-DGrid)
|
2019-04-03 23:53:46 +05:30
|
|
|
message ("Building Grid Solver\n")
|
2019-04-28 16:24:59 +05:30
|
|
|
elseif (DAMASK_SOLVER STREQUAL "fem" OR DAMASK_SOLVER STREQUAL "mesh")
|
2019-04-25 10:38:32 +05:30
|
|
|
project (damask-mesh Fortran C)
|
2017-03-16 03:10:44 +05:30
|
|
|
add_definitions (-DFEM)
|
2020-01-03 02:12:28 +05:30
|
|
|
message ("Building Mesh Solver\n")
|
2018-05-23 23:21:11 +05:30
|
|
|
else ()
|
2018-05-24 11:27:10 +05:30
|
|
|
message (FATAL_ERROR "Build target (DAMASK_SOLVER) is not defined")
|
2017-03-16 03:35:58 +05:30
|
|
|
endif ()
|
2020-01-04 19:07:09 +05:30
|
|
|
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
2017-05-01 03:00:27 +05:30
|
|
|
|
2018-05-24 10:43:12 +05:30
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "")
|
2017-04-25 16:05:19 +05:30
|
|
|
set (CMAKE_BUILD_TYPE "RELEASE")
|
|
|
|
endif ()
|
|
|
|
|
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")
|
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")
|
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
|
|
|
|
|
|
|
# syntax check only (mainly for pre-receive hook, works only with gfortran)
|
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
|
|
|
|
2017-02-04 03:53:55 +05:30
|
|
|
# Parse DAMASK version from VERSION file
|
2016-05-21 18:36:01 +05:30
|
|
|
find_program (CAT_EXECUTABLE NAMES cat)
|
2017-03-16 03:10:44 +05:30
|
|
|
execute_process (COMMAND ${CAT_EXECUTABLE} ${PROJECT_SOURCE_DIR}/VERSION
|
|
|
|
RESULT_VARIABLE DAMASK_VERSION_RETURN
|
|
|
|
OUTPUT_VARIABLE DAMASK_V
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
add_definitions (-DDAMASKVERSION="${DAMASK_V}")
|
2016-05-21 18:36:01 +05:30
|
|
|
|
|
|
|
# definition of other macros
|
2017-03-16 03:10:44 +05:30
|
|
|
add_definitions (-DPETSc)
|
2016-03-06 13:58:20 +05:30
|
|
|
|
2020-01-26 19:40:27 +05:30
|
|
|
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
|
2019-04-27 13:49:11 +05:30
|
|
|
include(Compiler-Intel)
|
2018-05-24 10:43:12 +05:30
|
|
|
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
2019-04-27 11:26:52 +05:30
|
|
|
include(Compiler-GNU)
|
2019-02-09 20:32:07 +05:30
|
|
|
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
|
2019-04-27 11:26:52 +05:30
|
|
|
include(Compiler-PGI)
|
2018-05-24 11:27:10 +05:30
|
|
|
else ()
|
|
|
|
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
|
|
|
|
2018-05-24 11:27:10 +05:30
|
|
|
|
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-01-04 19:07:09 +05:30
|
|
|
set (CMAKE_Fortran_LINK_EXECUTABLE "${BUILDCMD_PRE} ${PETSC_LINKER} ${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")
|
2017-04-26 13:10:45 +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}")
|
2017-04-26 13:10:45 +05:30
|
|
|
set (CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} <OBJECTS> -o <TARGET> <LINK_LIBRARIES> ${PETSC_EXTERNAL_LIB} ${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)
|