2021-10-16 01:46:47 +05:30
|
|
|
cmake_minimum_required(VERSION 3.12.0)
|
|
|
|
include(FindPkgConfig REQUIRED)
|
2020-12-18 19:49:04 +05:30
|
|
|
|
2021-10-16 01:46:47 +05:30
|
|
|
if(DEFINED ENV{PETSC_DIR})
|
|
|
|
message("PETSC_DIR:\n$ENV{PETSC_DIR}\n")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "PETSc location (PETSC_DIR) is not defined")
|
|
|
|
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
|
2021-10-16 01:46:47 +05:30
|
|
|
project(Prerequisites LANGUAGES)
|
2022-04-10 00:40:15 +05:30
|
|
|
set(ENV{PKG_CONFIG_PATH} "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
|
2022-04-03 21:26:17 +05:30
|
|
|
pkg_check_modules(PETSC_MIN REQUIRED PETSc>=3.12.0 QUIET) #CMake does not support version range
|
2023-10-08 13:18:53 +05:30
|
|
|
pkg_check_modules(PETSC REQUIRED PETSc<3.21.0)
|
2022-04-03 21:26:17 +05:30
|
|
|
|
2021-10-16 01:46:47 +05:30
|
|
|
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)
|
2021-10-16 01:46:47 +05:30
|
|
|
if(DAMASK_SOLVER STREQUAL "GRID")
|
|
|
|
project(damask-grid HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C)
|
|
|
|
elseif(DAMASK_SOLVER STREQUAL "MESH")
|
|
|
|
project(damask-mesh HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C)
|
2023-02-25 02:57:56 +05:30
|
|
|
elseif(DAMASK_SOLVER STREQUAL "TEST")
|
|
|
|
project(damask-test HOMEPAGE_URL https://damask.mpie.de LANGUAGES Fortran C)
|
2021-10-16 01:46:47 +05:30
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Invalid solver: DAMASK_SOLVER=${DAMASK_SOLVER}")
|
|
|
|
endif()
|
|
|
|
add_definitions("-D${DAMASK_SOLVER}")
|
|
|
|
|
2022-04-10 00:40:15 +05:30
|
|
|
# EXPERIMENTAL: This might help to detect HDF5 and FFTW3 in the future if PETSc is not aware of them
|
|
|
|
set(ENV{PKG_CONFIG_PATH} "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/externalpackages:$ENV{PKG_CONFIG_PATH}")
|
|
|
|
pkg_check_modules(HDF5 hdf5)
|
|
|
|
pkg_check_modules(FFTW3 fftw3)
|
2022-04-13 00:32:09 +05:30
|
|
|
pkg_check_modules(fYAML libfyaml)
|
2022-04-13 09:25:34 +05:30
|
|
|
pkg_check_modules(zlib zlib)
|
2022-04-10 00:40:15 +05:30
|
|
|
|
2021-10-16 01:46:47 +05:30
|
|
|
file(STRINGS ${PROJECT_SOURCE_DIR}/VERSION DAMASK_VERSION)
|
|
|
|
|
|
|
|
message("\nBuilding ${CMAKE_PROJECT_NAME} ${DAMASK_VERSION}\n")
|
|
|
|
|
|
|
|
add_definitions(-DPETSC)
|
|
|
|
add_definitions(-DDAMASKVERSION="${DAMASK_VERSION}")
|
|
|
|
add_definitions(-DCMAKE_SYSTEM="${CMAKE_SYSTEM}")
|
2022-05-06 16:04:32 +05:30
|
|
|
if(PETSC_VERSION VERSION_EQUAL 3.17.0)
|
2022-04-03 21:26:17 +05:30
|
|
|
add_definitions("-DCHKERRQ=PetscCall")
|
|
|
|
endif()
|
2021-10-16 01:46:47 +05:30
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "")
|
|
|
|
set(CMAKE_BUILD_TYPE "RELEASE")
|
|
|
|
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
|
2021-10-16 01:46:47 +05:30
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "SYNTAXONLY")
|
|
|
|
set(DEBUG_FLAGS "${DEBUG_FLAGS} -DDEBUG")
|
|
|
|
set(PARALLEL "OFF")
|
2022-02-05 22:54:24 +05:30
|
|
|
set(OPTI "DEBUG")
|
2021-10-16 01:46:47 +05:30
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
|
|
|
set(PARALLEL "ON")
|
|
|
|
set(OPTI "DEFENSIVE")
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL "DEBUGRELEASE")
|
|
|
|
set(DEBUG_FLAGS "${DEBUG_FLAGS} -DDEBUG")
|
|
|
|
set(PARALLEL "ON")
|
|
|
|
set(OPTI "DEFENSIVE")
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL "PERFORMANCE")
|
|
|
|
set(PARALLEL "ON")
|
|
|
|
set(OPTI "AGGRESSIVE")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Invalid build type: CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
|
|
|
|
endif()
|
2017-03-16 03:10:44 +05:30
|
|
|
|
|
|
|
# $OPTIMIZATION takes precedence over $BUILD_TYPE defaults
|
2021-10-16 01:46:47 +05:30
|
|
|
if(OPTIMIZATION STREQUAL "" OR NOT DEFINED OPTIMIZATION)
|
|
|
|
set(OPTIMIZATION "${OPTI}")
|
|
|
|
else()
|
|
|
|
set(OPTIMIZATION "${OPTIMIZATION}")
|
|
|
|
endif()
|
2017-03-16 03:10:44 +05:30
|
|
|
|
|
|
|
# $OPENMP takes precedence over $BUILD_TYPE defaults
|
2021-10-16 01:46:47 +05:30
|
|
|
if(OPENMP STREQUAL "" OR NOT DEFINED OPENMP)
|
|
|
|
set(OPENMP "${PARALLEL}")
|
|
|
|
else()
|
2017-02-04 05:31:42 +05:30
|
|
|
set(OPENMP "${OPENMP}")
|
2021-10-16 01:46:47 +05:30
|
|
|
endif()
|
2017-04-18 10:44:55 +05:30
|
|
|
|
2021-10-16 01:46:47 +05:30
|
|
|
# syntax check only(mainly for pre-receive hook)
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "SYNTAXONLY")
|
|
|
|
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)
|
2022-12-17 19:22:41 +05:30
|
|
|
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
2021-10-16 01:46:47 +05:30
|
|
|
include(Compiler-GNU)
|
2022-12-17 19:22:41 +05:30
|
|
|
set(Fortran_COMPILER_VERSION_MIN 9.1)
|
|
|
|
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
|
|
|
|
include(Compiler-Intel)
|
|
|
|
set(Fortran_COMPILER_VERSION_MIN 19)
|
2021-12-25 23:03:54 +05:30
|
|
|
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
|
|
|
|
include(Compiler-IntelLLVM)
|
2022-12-17 19:22:41 +05:30
|
|
|
set(Fortran_COMPILER_VERSION_MIN 19)
|
2021-10-16 01:46:47 +05:30
|
|
|
else()
|
2022-12-17 19:22:41 +05:30
|
|
|
message(FATAL_ERROR "Compiler '${CMAKE_Fortran_COMPILER_ID}' not supported")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS Fortran_COMPILER_VERSION_MIN)
|
|
|
|
message(FATAL_ERROR "Version '${CMAKE_Fortran_COMPILER_VERSION}' of '${CMAKE_Fortran_COMPILER_ID}' is not supported")
|
2021-10-16 01:46:47 +05:30
|
|
|
endif()
|
|
|
|
|
2022-01-10 16:25:37 +05:30
|
|
|
file(STRINGS "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/petsc/conf/petscvariables" PETSC_EXTERNAL_LIB REGEX "PETSC_EXTERNAL_LIB_BASIC = .*$?")
|
|
|
|
string(REPLACE "PETSC_EXTERNAL_LIB_BASIC = " "" PETSC_EXTERNAL_LIB "${PETSC_EXTERNAL_LIB}")
|
2021-10-16 01:46:47 +05:30
|
|
|
message("PETSC_EXTERNAL_LIB:\n${PETSC_EXTERNAL_LIB}\n")
|
|
|
|
|
|
|
|
file(STRINGS "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/petsc/conf/petscvariables" PETSC_INCLUDES REGEX "PETSC_FC_INCLUDES = .*$?")
|
2022-01-10 16:25:37 +05:30
|
|
|
string(REPLACE "PETSC_FC_INCLUDES = " "" PETSC_INCLUDES "${PETSC_INCLUDES}")
|
2021-10-16 01:46:47 +05:30
|
|
|
message("PETSC_INCLUDES:\n${PETSC_INCLUDES}\n")
|
|
|
|
|
2022-06-27 14:07:41 +05:30
|
|
|
set(CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE} "${BUILDCMD_PRE} ${OPENMP_FLAGS} ${STANDARD_CHECK} ${OPTIMIZATION_FLAGS} ${COMPILE_FLAGS}")
|
2021-10-16 01:46:47 +05:30
|
|
|
set(CMAKE_Fortran_LINK_EXECUTABLE "${BUILDCMD_PRE} ${CMAKE_Fortran_COMPILER} ${OPENMP_FLAGS} ${OPTIMIZATION_FLAGS} ${LINKER_FLAGS}")
|
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
|
|
|
|
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}")
|
|
|
|
endif()
|
|
|
|
|
2022-04-13 01:44:04 +05:30
|
|
|
set(CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE} "${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}} ${PETSC_INCLUDES} ${BUILDCMD_POST}")
|
|
|
|
|
|
|
|
set(CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -L${PETSC_LIBRARY_DIRS} -lpetsc ${PETSC_EXTERNAL_LIB} -lz")
|
2022-04-13 09:25:34 +05:30
|
|
|
|
2022-04-13 01:44:04 +05:30
|
|
|
if(fYAML_FOUND STREQUAL "1")
|
2023-10-16 18:24:52 +05:30
|
|
|
set(CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} -L${fYAML_LIBRARY_DIRS}")
|
|
|
|
foreach(fYAML_LIBRARY ${fYAML_LIBRARIES})
|
|
|
|
set(CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} -L${fYAML_LIBRARY_DIRS} -l${fYAML_LIBRARY}")
|
|
|
|
endforeach()
|
2022-04-13 01:44:04 +05:30
|
|
|
add_definitions(-DFYAML)
|
2022-04-13 09:25:34 +05:30
|
|
|
pkg_get_variable(fYAML_INCLUDE_DIR libfyaml includedir) # fYAML_INCLUDE_DIRS and fYAML_CFLAGS are not working
|
|
|
|
set(CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE} "${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}} -I${fYAML_INCLUDE_DIR}")
|
2022-04-13 01:44:04 +05:30
|
|
|
endif()
|
2022-04-13 09:25:34 +05:30
|
|
|
|
2022-04-13 01:44:04 +05:30
|
|
|
set(CMAKE_Fortran_LINK_EXECUTABLE "${CMAKE_Fortran_LINK_EXECUTABLE} ${BUILDCMD_POST}")
|
2021-10-16 01:46:47 +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
|
2021-10-16 01:46:47 +05:30
|
|
|
add_subdirectory(src)
|