2016-02-26 03:03:21 +05:30
########################################################################################
2017-02-04 03:53:55 +05:30
# Compiler options for building DAMASK
2016-05-25 01:05:16 +05:30
cmake_minimum_required ( VERSION 2.8.8 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 } )
2016-04-20 00:22:36 +05:30
if ( "${PETSC_DIR}" STREQUAL "" )
2017-02-04 03:53:55 +05:30
message ( FATAL_ERROR "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
2017-03-16 03:10:44 +05:30
# This file will be deleted
# once the settings from PETSc are parsed into CMake
2016-05-18 12:24:16 +05:30
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
" $ { p e t s c _ c o n f i g _ m a k e f i l e } "
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
S H E L L = / b i n / s h
2016-03-01 21:06:48 +05:30
i n c l u d e $ { p e t s c _ c o n f _ r u l e s }
i n c l u d e $ { p e t s c _ c o n f _ v a r i a b l e s }
2016-03-06 20:00:16 +05:30
I N C L U D E _ D I R S : = \ $ { P E T S C _ F C _ I N C L U D E S }
L I B R A R I E S : = \ $ { P E T S C _ W I T H _ E X T E R N A L _ L I B }
2016-05-21 18:36:01 +05:30
C O M P I L E R F : = \ $ { F C }
C O M P I L E R C : = \ $ { C C }
L I N K E R N A M E : = \ $ { F L I N K E R }
2016-03-01 23:53:47 +05:30
i n c l u d e s :
\ t @ e c h o \ $ { I N C L U D E _ D I R S }
e x t l i b s :
\ t @ e c h o \ $ { L I B R A R I E S }
2016-03-06 20:00:16 +05:30
c o m p i l e r f :
\ t @ e c h o \ $ { C O M P I L E R F }
c o m p i l e r c :
\ t @ e c h o \ $ { C O M P I L E R C }
2016-03-01 23:53:47 +05:30
l i n k e r :
2016-05-18 12:24:16 +05:30
\ t @ e c h o \ $ { L I N K E R N A M E }
" )
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.
find_program ( MAKE_EXECUTABLE NAMES make gmake )
# 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"
R E S U L T _ V A R I A B L E P E T S C _ I N C L U D E S _ R E T U R N
O U T P U T _ V A R I A B L E p e t s c _ i n c l u d e s
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
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"
R E S U L T _ V A R I A B L E P E T S C _ E X T E R N A L _ L I B _ R E T U R N
O U T P U T _ V A R I A B L E p e t s c _ e x t e r n a l _ l i b
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
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"
R E S U L T _ V A R I A B L E P E T S C _ M P I F C _ R E T U R N
O U T P U T _ V A R I A B L E P E T S C _ M P I F C
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
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"
R E S U L T _ V A R I A B L E P E T S C _ M P I C C _ R E T U R N
O U T P U T _ V A R I A B L E P E T S C _ M P I C C
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
2016-03-06 20:00:16 +05:30
# PETSc specified linker (MPIF90 + PETSc linking flags)
2017-03-16 03:10:44 +05:30
execute_process ( COMMAND ${ MAKE_EXECUTABLE } --no-print-directory -f ${ petsc_config_makefile } "linker"
R E S U L T _ V A R I A B L E P E T S C _ L I N K E R _ R E T U R N
O U T P U T _ V A R I A B L E P E T S C _ L I N K E R
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
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([^\" ]+ ) " T M P _ L I S T " $ { p e t s c _ i n c l u d e s } " )
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]([^\" ]+ ) " T M P _ L I S T " $ { p e t s c _ e x t e r n a l _ l i b } " )
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
2016-05-21 20:21:12 +05:30
if ( "${DAMASK_SOLVER}" STREQUAL "SPECTRAL" )
2017-03-16 03:10:44 +05:30
project ( DAMASK_spectral Fortran C )
add_definitions ( -DSpectral )
message ( "Building Spectral Solver\n" )
2016-05-21 20:21:12 +05:30
elseif ( "${DAMASK_SOLVER}" STREQUAL "FEM" )
2017-03-16 03:10:44 +05:30
project ( DAMASK_FEM Fortran C )
add_definitions ( -DFEM )
message ( "Building FEM Solver\n" )
2017-03-16 03:35:58 +05:30
endif ( )
2016-05-21 18:36:01 +05:30
2017-05-01 03:00:27 +05:30
# set linker commands (needs to be done after defining the project)
set ( CMAKE_LINKER "${PETSC_LINKER}" )
2017-04-25 16:05:19 +05:30
if ( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
set ( CMAKE_BUILD_TYPE "RELEASE" )
endif ( )
2017-02-04 05:31:42 +05:30
# Predefined sets for OPTIMIZATION/OPENMP based on BUILD_TYPE
2017-03-16 03:10:44 +05:30
if ( "${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG" OR "${CMAKE_BUILD_TYPE}" STREQUAL "SYNTAXONLY" )
2017-09-30 04:00:53 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -DDEBUG" )
2017-02-04 05:31:42 +05:30
set ( PARALLEL "OFF" )
set ( OPTI "OFF" )
2017-03-16 03:10:44 +05:30
elseif ( "${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE" )
2017-02-04 05:31:42 +05:30
set ( PARALLEL "ON" )
set ( OPTI "DEFENSIVE" )
2017-03-16 03:10:44 +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
if ( "${OPTIMIZATION}" STREQUAL "" )
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
if ( "${OPENMP}" STREQUAL "" )
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)
if ( "${CMAKE_BUILD_TYPE}" STREQUAL "SYNTAXONLY" )
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_BIN from CONFIG file
2017-03-16 03:10:44 +05:30
file ( READ "CONFIG" CONFIGFILE )
string ( REGEX REPLACE ";" "\\\\;" CONFIGFILE "${CONFIGFILE}" )
string ( REGEX REPLACE "\n" ";" CONFIGFILE "${CONFIGFILE}" )
foreach ( item ${ CONFIGFILE } )
string ( REGEX MATCH ".+DAMASK_BIN.+" item ${ item } )
if ( item )
string ( REGEX REPLACE "set" "" item "${item}" )
string ( REGEX REPLACE "=" " " item "${item}" )
string ( REGEX REPLACE "\\\${DAMASK_ROOT}" "${PROJECT_SOURCE_DIR}" item "${item}" )
string ( REPLACE "DAMASK_BIN" ";" STRING_LIST ${ item } )
list ( GET STRING_LIST 1 item )
string ( STRIP "${item}" CMAKE_INSTALL_PREFIX )
2017-03-16 03:35:58 +05:30
endif ( )
2017-03-16 03:10:44 +05:30
endforeach ( item ${ CONFIGFILE } )
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
R E S U L T _ V A R I A B L E D A M A S K _ V E R S I O N _ R E T U R N
O U T P U T _ V A R I A B L E D A M A S K _ V
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
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 )
add_definitions ( -DFLOAT=8 )
add_definitions ( -DINT=4 )
2016-03-06 13:58:20 +05:30
2017-03-16 03:10:44 +05:30
set ( DAMASK_INCLUDE_FLAGS "${DAMASK_INCLUDE_FLAGS} ${PETSC_INCLUDES}" )
2016-02-24 03:30:41 +05:30
2016-05-18 12:24:16 +05:30
###################################################################################################
# Intel Compiler
###################################################################################################
2017-03-16 03:10:44 +05:30
if ( ${ CMAKE_Fortran_COMPILER_ID } STREQUAL "Intel" )
2016-02-26 03:03:21 +05:30
2016-05-18 12:24:16 +05:30
if ( OPENMP )
2017-02-04 03:53:55 +05:30
set ( OPENMP_FLAGS "-qopenmp -parallel" )
2017-03-16 03:35:58 +05:30
endif ( )
2016-02-26 03:03:21 +05:30
2016-05-18 12:24:16 +05:30
if ( "${OPTIMIZATION}" STREQUAL "OFF" )
2016-05-20 11:54:53 +05:30
set ( OPTIMIZATION_FLAGS "-O0 -no-ip" )
2017-03-16 03:10:44 +05:30
elseif ( "${OPTIMIZATION}" STREQUAL "DEFENSIVE" )
2016-05-20 11:54:53 +05:30
set ( OPTIMIZATION_FLAGS "-O2" )
2016-05-18 12:24:16 +05:30
elseif ( "${OPTIMIZATION}" STREQUAL "AGGRESSIVE" )
2017-03-16 03:10:44 +05:30
set ( OPTIMIZATION_FLAGS "-ipo -O3 -no-prec-div -fp-model fast=2 -xHost" )
2017-02-04 03:53:55 +05:30
# -fast = -ipo, -O3, -no-prec-div, -static, -fp-model fast=2, and -xHost"
2017-03-16 03:35:58 +05:30
endif ( )
2016-05-18 12:24:16 +05:30
set ( STANDARD_CHECK "-stand f08 -standard-semantics" )
2017-02-04 03:53:55 +05:30
set ( LINKER_FLAGS "${LINKER_FLAGS} -shared-intel" )
# Link against shared Intel libraries instead of static ones
2016-05-18 12:24:16 +05:30
#------------------------------------------------------------------------------------------------
2017-02-04 03:53:55 +05:30
# Fine tuning compilation options
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -fpp" )
# preprocessor
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -ftz" )
2017-03-16 03:10:44 +05:30
# flush underflow to zero, automatically set if -O[1,2,3]
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -assume" )
2017-03-16 03:10:44 +05:30
# assume ...
set ( COMPILE_FLAGS "${COMPILE_FLAGS} byterecl" )
# ... record length is given in bytes (also set by -standard-semantics)
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS},fpe_summary" )
2017-03-16 03:10:44 +05:30
# ... print list of floating point exceptions occured during execution
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -diag-disable" )
2017-03-16 03:10:44 +05:30
# disables warnings ...
set ( COMPILE_FLAGS "${COMPILE_FLAGS} 5268" )
# ... the text exceeds right hand column allowed on the line (we have only comments there)
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -warn" )
2017-03-16 03:10:44 +05:30
# enables warnings ...
set ( COMPILE_FLAGS "${COMPILE_FLAGS} declarations" )
# ... any undeclared names (alternative name: -implicitnone)
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS},general" )
2017-03-16 03:10:44 +05:30
# ... warning messages and informational messages are issued by the compiler
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS},usage" )
2017-03-16 03:10:44 +05:30
# ... questionable programming practices
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS},interfaces" )
2017-03-16 03:10:44 +05:30
# ... checks the interfaces of all SUBROUTINEs called and FUNCTIONs invoked in your compilation against an external set of interface blocks
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS},ignore_loc" )
2017-03-16 03:10:44 +05:30
# ... %LOC is stripped from an actual argument
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS},alignments" )
2017-03-16 03:10:44 +05:30
# ... data that is not naturally aligned
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS},unused" )
2017-03-16 03:10:44 +05:30
# ... declared variables that are never used
2017-02-04 03:53:55 +05:30
# Additional options
# -warn: enables warnings, where
# truncated_source: Determines whether warnings occur when source exceeds the maximum column width in fixed-format files.
# (too many warnings because we have comments beyond character 132)
# uncalled: Determines whether warnings occur when a statement function is never called
# all:
# -name as_is: case sensitive Fortran!
2016-05-18 12:24:16 +05:30
#------------------------------------------------------------------------------------------------
2017-02-04 03:53:55 +05:30
# Runtime debugging
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -g" )
# Generate symbolic debugging information in the object file
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -traceback" )
2017-03-16 03:10:44 +05:30
# Generate extra information in the object file to provide source file traceback information when a severe error occurs at run time
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -gen-interfaces" )
# Generate an interface block for each routine. http://software.intel.com/en-us/blogs/2012/01/05/doctor-fortran-gets-explicit-again/
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -fp-stack-check" )
2017-03-16 03:10:44 +05:30
# Generate extra code after every function call to ensure that the floating-point (FP) stack is in the expected state
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -fp-model strict" )
# Trap uninitalized variables
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -check" )
2017-03-16 03:10:44 +05:30
# Checks at runtime ...
set ( DEBUG_FLAGS "${DEBUG_FLAGS} bounds" )
# ... if an array index is too small (<1) or too large!
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS},format" )
2017-03-16 03:10:44 +05:30
# ... for the data type of an item being formatted for output.
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS},output_conversion" )
2017-03-16 03:10:44 +05:30
# ... for the fit of data items within a designated format descriptor field.
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS},pointers" )
2017-03-16 03:10:44 +05:30
# ... for certain disassociated or uninitialized pointers or unallocated allocatable objects.
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS},uninit" )
2017-03-16 03:10:44 +05:30
# ... for uninitialized variables.
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -ftrapuv" )
2017-03-16 03:10:44 +05:30
# ... initializes stack local variables to an unusual value to aid error detection
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -fpe-all0" )
2017-03-16 03:10:44 +05:30
# ... capture all floating-point exceptions, sets -ftz automatically
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -warn" )
2017-03-16 03:10:44 +05:30
# enables warnings ...
set ( DEBUG_FLAGS "${DEBUG_FLAGS} errors" )
# ... warnings are changed to errors
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS},stderrors" )
2017-03-16 03:10:44 +05:30
# ... warnings about Fortran standard violations are changed to errors
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -debug-parameters all" )
2017-02-04 03:53:55 +05:30
# generate debug information for parameters
# Additional options
# -heap-arrays: Should not be done for OpenMP, but set "ulimit -s unlimited" on shell. Probably it helps also to unlimit other limits
# -check: Checks at runtime, where
# arg_temp_created: will cause a lot of warnings because we create a bunch of temporary arrays (performance?)
# stack:
2016-03-08 04:30:12 +05:30
2016-05-18 12:24:16 +05:30
#------------------------------------------------------------------------------------------------
2017-02-04 03:53:55 +05:30
# precision settings
set ( PRECISION_FLAGS "${PRECISION_FLAGS} -real-size 64" )
2017-03-16 03:10:44 +05:30
# set precision for standard real to 32 | 64 | 128 (= 4 | 8 | 16 bytes, type pReal is always 8 bytes)
2017-02-04 03:53:55 +05:30
set ( PRECISION_FLAGS "${PRECISION_FLAGS} -integer-size 32" )
2017-03-16 03:10:44 +05:30
# set precision for standard int to 16 | 32 | 64 (= 2 | 4 | 8 bytes, type pInt is always 4 bytes)
2016-05-18 12:24:16 +05:30
2016-02-26 03:03:21 +05:30
###################################################################################################
2016-05-18 12:24:16 +05:30
# GNU Compiler
###################################################################################################
elseif ( ${ CMAKE_Fortran_COMPILER_ID } STREQUAL "GNU" )
if ( OPENMP )
2016-05-20 11:54:53 +05:30
set ( OPENMP_FLAGS "-fopenmp" )
2017-03-16 03:35:58 +05:30
endif ( )
2016-05-18 12:24:16 +05:30
if ( "${OPTIMIZATION}" STREQUAL "OFF" )
2016-05-20 11:54:53 +05:30
set ( OPTIMIZATION_FLAGS "-O0" )
2016-05-18 12:24:16 +05:30
elseif ( "${OPTIMIZATION}" STREQUAL "DEFENSIVE" )
2016-05-20 11:54:53 +05:30
set ( OPTIMIZATION_FLAGS "-O2" )
2016-05-18 12:24:16 +05:30
elseif ( "${OPTIMIZATION}" STREQUAL "AGGRESSIVE" )
2016-05-20 11:54:53 +05:30
set ( OPTIMIZATION_FLAGS "-O3 -ffast-math -funroll-loops -ftree-vectorize" )
2017-03-16 03:35:58 +05:30
endif ( )
2016-05-18 12:24:16 +05:30
set ( STANDARD_CHECK "-std=f2008ts -pedantic-errors" )
2017-02-04 03:53:55 +05:30
set ( LINKER_FLAGS "${LINKER_FLAGS} -Wl" )
# options parsed directly to the linker
2017-03-16 03:35:58 +05:30
set ( LINKER_FLAGS "${LINKER_FLAGS},-undefined,dynamic_lookup" )
2017-02-04 03:53:55 +05:30
# ensure to link against dynamic libraries
2016-05-18 12:24:16 +05:30
#------------------------------------------------------------------------------------------------
2017-02-04 03:53:55 +05:30
# Fine tuning compilation options
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -xf95-cpp-input" )
# preprocessor
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -ffree-line-length-132" )
# restrict line length to the standard 132 characters (lattice.f90 require more characters)
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -fimplicit-none" )
# assume "implicit none" even if not present in source
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -fmodule-private" )
# assume "private" even if not present in source
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -Wall" )
# sets the following Fortran options:
# -Waliasing: warn about possible aliasing of dummy arguments. Specifically, it warns if the same actual argument is associated with a dummy argument with "INTENT(IN)" and a dummy argument with "INTENT(OUT)" in a call with an explicit interface.
# -Wampersand: checks if a character expression is continued proberly by an ampersand at the end of the line and at the beginning of the new line
# -Warray-bounds: checks if array reference is out of bounds at compile time. use -fcheck-bounds to also check during runtime
# -Wconversion: warn about implicit conversions between different type
# -Wsurprising: warn when "suspicious" code constructs are encountered. While technically legal these usually indicate that an error has been made.
# -Wc-binding-type:
# -Wintrinsics-std: only standard intrisics are available, e.g. "call flush(6)" will cause an error
# -Wno-tabs: do not allow tabs in source
# -Wintrinsic-shadow: warn if a user-defined procedure or module procedure has the same name as an intrinsic
# -Wline-truncation:
# -Wtarget-lifetime:
# -Wreal-q-constant: warn about real-literal-constants with 'q' exponent-letter
# -Wunused: a number of unused-xxx warnings
# and sets the general (non-Fortran options) options:
# -Waddress
# -Warray-bounds (only with -O2)
# -Wc++11-compat
# -Wchar-subscripts
# -Wcomment
# -Wformat
# -Wmaybe-uninitialized
# -Wnonnull
# -Wparentheses
# -Wpointer-sign
# -Wreorder
# -Wreturn-type
# -Wsequence-point
# -Wstrict-aliasing
# -Wstrict-overflow=1
# -Wswitch
# -Wtrigraphs
# -Wuninitialized
# -Wunknown-pragmas
# -Wunused-function
# -Wunused-label
# -Wunused-value
# -Wunused-variable
# -Wvolatile-register-var
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -Wextra" )
# sets the following Fortran options:
# -Wunuses-parameter:
# -Wcompare-reals:
# and sets the general (non-Fortran options) options:
# -Wclobbered
# -Wempty-body
# -Wignored-qualifiers
# -Wmissing-field-initializers
# -Woverride-init
# -Wsign-compare
# -Wtype-limits
# -Wuninitialized
# -Wunused-but-set-parameter (only with -Wunused or -Wall)
# -Wno-globals
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -Wcharacter-truncation" )
# warn if character expressions (strings) are truncated
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -Wunderflow" )
# produce a warning when numerical constant expressions are encountered, which yield an UNDERFLOW during compilation
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -Wsuggest-attribute=pure" )
2016-03-08 04:30:12 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -Wsuggest-attribute=noreturn" )
2017-02-04 03:53:55 +05:30
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -Wconversion-extra" )
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -Wimplicit-procedure" )
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-unused-parameter" )
set ( COMPILE_FLAGS "${COMPILE_FLAGS} -ffpe-summary=all" )
# print summary of floating point exeptions (invalid,zero,overflow,underflow,inexact,denormal)
2016-05-21 20:21:12 +05:30
2017-02-04 03:53:55 +05:30
# Additional options
# -Warray-temporarieswarnings: because we have many temporary arrays (performance issue?):
# -Wimplicit-interface: no interfaces for lapack/MPI routines
# -Wunsafe-loop-optimizations: warn if the loop cannot be optimized due to nontrivial assumptions.
2016-03-08 04:30:12 +05:30
2016-05-18 12:24:16 +05:30
#------------------------------------------------------------------------------------------------
2017-02-04 03:53:55 +05:30
# Runtime debugging
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -ffpe-trap=invalid,zero,overflow" )
# stop execution if floating point exception is detected (NaN is silent)
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -g" )
# Generate symbolic debugging information in the object file
2017-03-16 03:10:44 +05:30
2017-02-04 05:31:42 +05:30
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -fbacktrace" )
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -fdump-core" )
set ( DEBUG_FLAGS "${DEBUG_FLAGS} -fcheck=all" )
2017-02-04 03:53:55 +05:30
# checks for (array-temps,bounds,do,mem,pointer,recursion)
2016-02-26 21:38:25 +05:30
2017-02-04 03:53:55 +05:30
# Additional options
# -ffpe-trap=precision,denormal,underflow
2016-05-18 12:24:16 +05:30
#------------------------------------------------------------------------------------------------
2017-02-04 03:53:55 +05:30
# precision settings
set ( PRECISION_FLAGS "${PRECISION_FLAGS} -fdefault-real-8" )
# set precision to 8 bytes for standard real (=8 for pReal). Will set size of double to 16 bytes as long as -fdefault-double-8 is not set
2017-03-16 03:10:44 +05:30
2017-02-04 03:53:55 +05:30
set ( PRECISION_FLAGS "${PRECISION_FLAGS} -fdefault-double-8" )
# set precision to 8 bytes for double real, would be 16 bytes if -fdefault-real-8 is used
# Additional options
# -fdefault-integer-8: Use it to set precision to 8 bytes for integer, don't use it for the standard case of pInt=4 (there is no -fdefault-integer-4)
2017-03-16 03:35:58 +05:30
endif ( )
2016-03-08 04:30:12 +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}" )
set ( CMAKE_Fortran_LINK_EXECUTABLE "${BUILDCMD_PRE} ${CMAKE_LINKER} ${OPENMP_FLAGS} ${OPTIMIZATION_FLAGS} ${LINKER_FLAGS}" )
2016-05-21 18:36:01 +05:30
2017-04-25 16:05:19 +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
2017-04-26 13:10:45 +05:30
set ( CMAKE_Fortran_FLAGS_ ${ CMAKE_BUILD_TYPE } "${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}} ${DAMASK_INCLUDE_FLAGS} ${BUILDCMD_POST}" )
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 )
2016-03-04 03:15:15 +05:30
2016-03-05 01:12:55 +05:30
# INSTALL BUILT BINARIES
2017-04-18 11:08:36 +05:30
if ( "${CMAKE_BUILD_TYPE}" STREQUAL "SYNTAXONLY" )
2017-03-16 04:03:47 +05:30
exec_program ( mktemp ARGS -d OUTPUT_VARIABLE BLACK_HOLE )
install ( PROGRAMS ${ PROJECT_BINARY_DIR } /src/prec.mod
D E S T I N A T I O N $ { B L A C K _ H O L E } )
else ( )
2017-04-18 11:08:36 +05:30
if ( "${PROJECT_NAME}" STREQUAL "DAMASK_spectral" )
2017-03-16 03:10:44 +05:30
install ( PROGRAMS ${ PROJECT_BINARY_DIR } /src/DAMASK_spectral
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ P R E F I X } )
2017-04-18 11:08:36 +05:30
elseif ( "${PROJECT_NAME}" STREQUAL "DAMASK_FEM" )
2017-03-16 03:10:44 +05:30
install ( PROGRAMS ${ PROJECT_BINARY_DIR } /src/DAMASK_FEM
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ P R E F I X } )
2017-03-16 03:35:58 +05:30
endif ( )
endif ( )