reorder the CMake configuration and add more comments
This commit is contained in:
parent
939e0e372e
commit
a4225de91d
149
CMakeLists.txt
149
CMakeLists.txt
|
@ -2,6 +2,9 @@
|
||||||
# CMAKE for build the Material subroutine for BVP solution
|
# CMAKE for build the Material subroutine for BVP solution
|
||||||
########################################################################################
|
########################################################################################
|
||||||
cmake_minimum_required (VERSION 2.8.0 FATAL_ERROR)
|
cmake_minimum_required (VERSION 2.8.0 FATAL_ERROR)
|
||||||
|
# PROJECT DEFINITION HAS TO BE ON TOP
|
||||||
|
# //The rest of the script relies on it to figure out relative position
|
||||||
|
project (DAMASK Fortran C)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------------
|
||||||
# Find PETSc because the entire build will rely on it
|
# Find PETSc because the entire build will rely on it
|
||||||
|
@ -14,8 +17,10 @@ endif (NOT DEFINED PETSC_DIR)
|
||||||
# https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake
|
# https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake
|
||||||
set(petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables")
|
set(petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables")
|
||||||
set(petsc_conf_rules "${PETSC_DIR}/lib/petsc/conf/rules" )
|
set(petsc_conf_rules "${PETSC_DIR}/lib/petsc/conf/rules" )
|
||||||
# A temporary makefile to probe the PETSc configuration
|
# Generate a temporary makerfile to probe the PETSc configuration
|
||||||
set (petsc_config_makefile "/home/m/DAMASK/build/Makefile.petsc") #MD: don't know how get the path here
|
# This file will be deleted once the setting from PETSc is parsed
|
||||||
|
# into CMake
|
||||||
|
set (petsc_config_makefile "${PROJECT_SOURCE_DIR}/Makefile.petsc")
|
||||||
file (WRITE "${petsc_config_makefile}"
|
file (WRITE "${petsc_config_makefile}"
|
||||||
"## This file was auto generated by CMake
|
"## This file was auto generated by CMake
|
||||||
# PETSC_DIR = ${PETSC_DIR}
|
# PETSC_DIR = ${PETSC_DIR}
|
||||||
|
@ -23,10 +28,11 @@ file (WRITE "${petsc_config_makefile}"
|
||||||
SHELL = /bin/sh
|
SHELL = /bin/sh
|
||||||
include ${petsc_conf_rules}
|
include ${petsc_conf_rules}
|
||||||
include ${petsc_conf_variables}
|
include ${petsc_conf_variables}
|
||||||
INCLUDE_DIRS := \${PETSC_FC_INCLUDES}
|
INCLUDE_DIRS := \${PETSC_FC_INCLUDES}
|
||||||
LIBRARIES := \${PETSC_WITH_EXTERNAL_LIB}
|
LIBRARIES := \${PETSC_WITH_EXTERNAL_LIB}
|
||||||
COMPILERNAME ?= \${FC}
|
COMPILERF ?= \${FC}
|
||||||
LINKERNAME ?= \${FLINKER}
|
LINKERNAME ?= \${FLINKER}
|
||||||
|
COMPILERC ?= \${CC}
|
||||||
|
|
||||||
includes:
|
includes:
|
||||||
\t@echo \${INCLUDE_DIRS}
|
\t@echo \${INCLUDE_DIRS}
|
||||||
|
@ -34,16 +40,84 @@ includes:
|
||||||
extlibs:
|
extlibs:
|
||||||
\t@echo \${LIBRARIES}
|
\t@echo \${LIBRARIES}
|
||||||
|
|
||||||
compiler:
|
compilerf:
|
||||||
\t@echo \${COMPILERNAME}
|
\t@echo \${COMPILERF}
|
||||||
|
|
||||||
|
compilerc:
|
||||||
|
\t@echo \${COMPILERC}
|
||||||
|
|
||||||
linker:
|
linker:
|
||||||
\t@echo \${LINKERNAME}
|
\t@echo \${LINKERNAME}")
|
||||||
|
|
||||||
")
|
# CMake will execute each target in the ${petsc_config_makefile}
|
||||||
# https://cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F
|
# to acquire corresponding PETSc Variables.
|
||||||
set(CMAKE_Fortran_COMPILER "/opt/petsc/gfortran/bin/mpif90") #MD: https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake might help
|
# The include path and linking libraries in PETSc usually contains
|
||||||
set(CMAKE_C_COMPILER "/opt/petsc/gfortran/bin/mpicc") #MD: https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake might help
|
# duplicated entries, which is cleaned up later using CMake list.
|
||||||
|
find_program (MAKE_EXECUTABLE NAMES make gmake)
|
||||||
|
# Find the PETSc includes directory settings
|
||||||
|
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "includes"
|
||||||
|
RESULT_VARIABLE PETSC_INCLUDES_RETURN
|
||||||
|
OUTPUT_VARIABLE petsc_includes
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
# Find the PETSc external linking directory settings
|
||||||
|
# //required for final linking, must be appended after the executable
|
||||||
|
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "extlibs"
|
||||||
|
RESULT_VARIABLE PETSC_EXTERNAL_LIB_RETURN
|
||||||
|
OUTPUT_VARIABLE petsc_external_lib
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
# The MPI compiler specified in PETSc
|
||||||
|
# //its version information is used to identify whether it is INTEL FORTRAN
|
||||||
|
# //or GNU FORTRAN,
|
||||||
|
# //e.g. for PETSc configured with INTEL FORTRAN compiler
|
||||||
|
# // >>${MPIEXEC} -v
|
||||||
|
# // ifort version 14.0.3 --> This line is captured and parsed by CMake
|
||||||
|
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "compilerf"
|
||||||
|
RESULT_VARIABLE MPIEXEC_RETURN
|
||||||
|
OUTPUT_VARIABLE MPIEXEC
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
# The option OUTPUT_QUIET sometimes fails to suppress the output from
|
||||||
|
# ${MPIEXEC} -v, thus the MPIF90 version information may show up in the terminal.
|
||||||
|
execute_process(COMMAND ${MPIEXEC} --version OUTPUT_QUIET
|
||||||
|
RESULT_VARIABLE MPINAME_RETURN
|
||||||
|
OUTPUT_VARIABLE MPINAME
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
# PETSc specified linker (MPIF90 + PETSc linking flags)
|
||||||
|
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "linker"
|
||||||
|
RESULT_VARIABLE PETSC_LINKER_RETURN
|
||||||
|
OUTPUT_VARIABLE PETSC_LINKER
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
# Get MPI C compiler name from PETSc
|
||||||
|
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "compilerc"
|
||||||
|
RESULT_VARIABLE CMPIEXEC_RETURN
|
||||||
|
OUTPUT_VARIABLE CMPIEXEC
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
# Remove temporary makefile, no need to keep it anymore.
|
||||||
|
file (REMOVE ${petsc_config_makefile})
|
||||||
|
|
||||||
|
# REMOVE DUPLICATE FLAGS FOR COMPILER AND LINKING
|
||||||
|
string( REGEX MATCHALL "-I([^\" ]+)" TMP_LIST "${petsc_includes}")
|
||||||
|
list(REMOVE_DUPLICATES TMP_LIST)
|
||||||
|
foreach (dir ${TMP_LIST})
|
||||||
|
set(PETSC_INCLUDES "${PETSC_INCLUDES} ${dir}")
|
||||||
|
endforeach(dir)
|
||||||
|
string( REGEX MATCHALL "-[lLW]([^\" ]+)" TMP_LIST "${petsc_external_lib}")
|
||||||
|
list(REMOVE_DUPLICATES TMP_LIST)
|
||||||
|
foreach (exlib ${TMP_LIST})
|
||||||
|
set(PETSC_EXTERNAL_LIB "${PETSC_EXTERNAL_LIB} ${exlib}")
|
||||||
|
endforeach(exlib)
|
||||||
|
|
||||||
|
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 FORTRAN MPI COMPILER:\n${MPIEXEC}\n" )
|
||||||
|
message("***Found C MPI COMPILER:\n${CMPIEXEC}\n" )
|
||||||
|
|
||||||
|
set (CMAKE_Fortran_COMPILER "${MPIEXEC}" )
|
||||||
|
set (CMAKE_C_COMPILER "${CMPIEXEC}")
|
||||||
|
# # https://cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F
|
||||||
|
# set(CMAKE_Fortran_COMPILER "/opt/petsc/gfortran/bin/mpif90") #MD: https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake might help
|
||||||
|
# set(CMAKE_C_COMPILER "/opt/petsc/gfortran/bin/mpicc") #MD: https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake might help
|
||||||
#---------------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------------
|
||||||
# Now start to care about DAMASK
|
# Now start to care about DAMASK
|
||||||
|
|
||||||
|
@ -51,8 +125,6 @@ set(CMAKE_C_COMPILER "/opt/petsc/gfortran/bin/mpicc") #MD:
|
||||||
set (DAMASK_VERSION_MAJOR 1)
|
set (DAMASK_VERSION_MAJOR 1)
|
||||||
set (DAMASK_VERSION_MINOR ${DAMASK_V})
|
set (DAMASK_VERSION_MINOR ${DAMASK_V})
|
||||||
|
|
||||||
project (DAMASK Fortran C)
|
|
||||||
|
|
||||||
# COMPILE VARIABLES
|
# COMPILE VARIABLES
|
||||||
add_definitions(-DDAMASKVERSION="${DAMASK_V}")
|
add_definitions(-DDAMASKVERSION="${DAMASK_V}")
|
||||||
add_definitions(-DPETSc)
|
add_definitions(-DPETSc)
|
||||||
|
@ -80,50 +152,6 @@ if ("${DAMASK_DRIVER}" STREQUAL "FEM")
|
||||||
add_definitions(-DFEM)
|
add_definitions(-DFEM)
|
||||||
endif("${DAMASK_DRIVER}" STREQUAL "FEM")
|
endif("${DAMASK_DRIVER}" STREQUAL "FEM")
|
||||||
|
|
||||||
|
|
||||||
find_program (MAKE_EXECUTABLE NAMES make gmake)
|
|
||||||
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "includes"
|
|
||||||
RESULT_VARIABLE PETSC_INCLUDES_RETURN
|
|
||||||
OUTPUT_VARIABLE petsc_includes
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "extlibs"
|
|
||||||
RESULT_VARIABLE PETSC_EXTERNAL_LIB_RETURN
|
|
||||||
OUTPUT_VARIABLE petsc_external_lib
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "linker"
|
|
||||||
RESULT_VARIABLE PETSC_LINKER_RETURN
|
|
||||||
OUTPUT_VARIABLE PETSC_LINKER
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
execute_process(COMMAND ${MAKE_EXECUTABLE} -f ${petsc_config_makefile} "compiler"
|
|
||||||
RESULT_VARIABLE MPIEXEC_RETURN
|
|
||||||
OUTPUT_VARIABLE MPIEXEC
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
execute_process(COMMAND ${MPIEXEC} -v OUTPUT_QUIET
|
|
||||||
RESULT_VARIABLE MPINAME_RETURN
|
|
||||||
OUTPUT_VARIABLE MPINAME
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
file (REMOVE ${petsc_config_makefile})
|
|
||||||
|
|
||||||
# REMOVE DUPLICATE FLAGS FOR COMPILER AND LINKING
|
|
||||||
string( REGEX MATCHALL "-I([^\" ]+)" TMP_LIST "${petsc_includes}")
|
|
||||||
list(REMOVE_DUPLICATES TMP_LIST)
|
|
||||||
foreach (dir ${TMP_LIST})
|
|
||||||
set(PETSC_INCLUDES "${PETSC_INCLUDES} ${dir}")
|
|
||||||
endforeach(dir)
|
|
||||||
string( REGEX MATCHALL "-[lLW]([^\" ]+)" TMP_LIST "${petsc_external_lib}")
|
|
||||||
list(REMOVE_DUPLICATES TMP_LIST)
|
|
||||||
foreach (exlib ${TMP_LIST})
|
|
||||||
set(PETSC_EXTERNAL_LIB "${PETSC_EXTERNAL_LIB} ${exlib}")
|
|
||||||
endforeach(exlib)
|
|
||||||
|
|
||||||
|
|
||||||
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 PETSC_MPIEXEC:\n${MPIEXEC}\n")
|
|
||||||
|
|
||||||
|
|
||||||
set (DAMASK_INCLUDE_FLAGS "${DAMASK_INCLUDE_FLAGS} ${PETSC_INCLUDES}" )
|
set (DAMASK_INCLUDE_FLAGS "${DAMASK_INCLUDE_FLAGS} ${PETSC_INCLUDES}" )
|
||||||
set (DAMASK_INCLUDE_FLAGS "${DAMASK_INCLUDE_FLAGS} -I${PROJECT_SOURCE_DIR}/lib")
|
set (DAMASK_INCLUDE_FLAGS "${DAMASK_INCLUDE_FLAGS} -I${PROJECT_SOURCE_DIR}/lib")
|
||||||
|
|
||||||
|
@ -386,7 +414,7 @@ if (MPINAME MATCHES "(^ifort)*")
|
||||||
|
|
||||||
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${DEBUG_OPTIONS_ifort}" )
|
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${DEBUG_OPTIONS_ifort}" )
|
||||||
#
|
#
|
||||||
elseif (MPINAME MATCHES "(^gfortran)*")
|
elseif (MPINAME MATCHES "(^GNU)*")
|
||||||
message("GNU fortran used for MPIF90\n")
|
message("GNU fortran used for MPIF90\n")
|
||||||
set (GNU_FORTRAN ON)
|
set (GNU_FORTRAN ON)
|
||||||
# for RELEASE
|
# for RELEASE
|
||||||
|
@ -413,7 +441,6 @@ else (MPINAME MATCHES "(^ifort)*")
|
||||||
endif (MPINAME MATCHES "(^ifort)*")
|
endif (MPINAME MATCHES "(^ifort)*")
|
||||||
|
|
||||||
# Finalizing
|
# Finalizing
|
||||||
set (CMAKE_Fortran_COMPILER "${MPIEXEC}")
|
|
||||||
set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${DAMASK_INCLUDE_FLAGS}")
|
set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} ${DAMASK_INCLUDE_FLAGS}")
|
||||||
set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${DAMASK_INCLUDE_FLAGS}")
|
set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${DAMASK_INCLUDE_FLAGS}")
|
||||||
set (CMAKE_LINKER "${PETSC_LINKER}")
|
set (CMAKE_LINKER "${PETSC_LINKER}")
|
||||||
|
|
Loading…
Reference in New Issue