-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
93 lines (74 loc) · 3.66 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
CMAKE_MINIMUM_REQUIRED(VERSION 3.3.0)
cmake_policy (SET CMP0045 OLD)
cmake_policy (SET CMP0046 OLD)
# Folder for custom CMake source files
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
INCLUDE(ExternalProject)
INCLUDE(CMakeDependentOption)
# =========================================================================
# Project definitions and output paths
# =========================================================================
PROJECT(PIDTS)
ENABLE_LANGUAGE(Fortran)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
SET(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
IF (NOT CMAKE_BUILD_TYPE)
SET (CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: Debug Release Profile."
FORCE)
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release Profile)
ENDIF (NOT CMAKE_BUILD_TYPE)
# FFLAGS depend on the compiler
GET_FILENAME_COMPONENT (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
IF (CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
# set Flags
SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fbackslash -ffree-line-length-0 -DGNU")
SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS} -O3 ${PIDTS_INSTRUCTION} -finline-functions -fstack-arrays")
SET (CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS} -pg -O3 ${PIDTS_INSTRUCTION} -finline-functions -fstack-arrays")
SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS} -g -O0 -ggdb3 -ffpe-trap=invalid -fbounds-check -finit-real=snan -fbacktrace -Wall")
# add flags only for compiling not linking!
SET (PIDTS_COMPILE_FLAGS "-xf95-cpp-input -fPIC")
ELSE()
MESSAGE(SEND_ERROR "Unknown compiler")
ENDIF()
# =========================================================================
# MPI
# =========================================================================
FIND_PACKAGE(MPI REQUIRED)
IF (NOT MPI_Fortran_NO_INTERROGATE)
FOREACH(DIR ${MPI_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${DIR})
ENDFOREACH()
FOREACH(DIR ${MPI_Fortran_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${DIR})
ENDFOREACH()
LIST(APPEND linkedlibs ${MPI_Fortran_LIBRARIES})
ENDIF()
MARK_AS_ADVANCED(MPI_LIBRARY MPI_EXTRA_LIBRARY) # don't show these ones
MESSAGE(STATUS "Building PIDTS with MPI")
MESSAGE(STATUS "MPI Compiler: " ${MPI_Fortran_COMPILER})
# =========================================================================
# PIDTS sources & targets
# =========================================================================
function(add_exec target)
ADD_EXECUTABLE(${target} ${ARGN})
TARGET_LINK_LIBRARIES(${target} PIDTSlibs ${linkedlibs})
SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${PIDTS_COMPILE_FLAGS})
SET_TARGET_PROPERTIES(${target} PROPERTIES LINKER_LANGUAGE Fortran)
INSTALL(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target} DESTINATION bin)
STRING(TOUPPER ${target} TARGETUP)
ADD_CUSTOM_COMMAND(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan "SUCCESS: ${TARGETUP} BUILD COMPLETE!")
endfunction()
# collect all F90 files needed for PIDTSlib, except the extra files below
FILE(GLOB_RECURSE src ./SRC/PIDTS/*.f90
./SRC/PIDTS/*.f
./SRC/Implicit_Solver/*.f90
./SRC/Implicit_Solver/*.f)
# define libs
ADD_LIBRARY(PIDTSobjs OBJECT ${src})
SET_TARGET_PROPERTIES(PIDTSobjs PROPERTIES COMPILE_FLAGS ${PIDTS_COMPILE_FLAGS})
ADD_LIBRARY(PIDTSlibs STATIC $<TARGET_OBJECTS:PIDTSobjs>)
add_exec(PIDTS ./SRC/main.f90)
ADD_DEPENDENCIES(PIDTS PIDTSlibs)