forked from davidscn/matrix-free-dealii-precice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
145 lines (123 loc) · 4.35 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Set the name of the project and target:
SET(TARGET "matrix-free-dealii-precice")
SET(SOLVER1 "solid")
SET(SOLVER2 "heat")
CMAKE_MINIMUM_REQUIRED(VERSION 3.10.2)
# Disable in-source compilation
IF (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
MESSAGE(FATAL_ERROR "In-source builds are disabled. Please change to a seperate
build directory and run cmake again.
")
ENDIF()
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/include
)
SET(CLEAN_UP_FILES
# a custom list of globs, e.g. *.log *.vtk
*.vtu
)
# Assume a debug build if not specified
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "DEBUG")
MESSAGE(STATUS "No build type specified. Building in debug mode.")
ENDIF()
# Print the current build type
MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
FIND_PACKAGE(deal.II 9.3
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
)
IF(NOT ${deal.II_FOUND})
MESSAGE(FATAL_ERROR "\n"
"*** Could not locate a (sufficiently recent) version of deal.II. ***\n\n"
"You may want to either pass a flag -DDEAL_II_DIR=/path/to/deal.II to cmake\n"
"or set an environment variable \"DEAL_II_DIR\" that contains this path."
)
ENDIF()
#
# Are all dependencies fulfilled?
#
IF(NOT DEAL_II_WITH_P4EST) # keep in one line
MESSAGE(FATAL_ERROR "
Error! This tutorial requires a deal.II library that was configured with the following options:
DEAL_II_WITH_P4EST = ON
However, the deal.II library found at ${DEAL_II_PATH} was configured with these options
DEAL_II_WITH_P4EST = ${DEAL_II_WITH_P4EST}
which conflict with the requirements."
)
ENDIF()
DEAL_II_INITIALIZE_CACHED_VARIABLES()
# Run macro to get Git info:
DEAL_II_QUERY_GIT_INFORMATION()
# If we could not get the tag from Git, get it from VERSION file
IF(NOT GIT_TAG)
FILE(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" GIT_TAG LIMIT_COUNT 1)
ENDIF()
MESSAGE(STATUS "Code version ${GIT_TAG}")
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/src/version.cc.in
${CMAKE_CURRENT_BINARY_DIR}/version.cc)
PROJECT(${TARGET} LANGUAGES CXX)
# This project requires c++17
IF(NOT ${DEAL_II_WITH_CXX17})
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_EXTENSIONS OFF)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
ENDIF()
# Build the version specific object
ADD_LIBRARY(version OBJECT ${CMAKE_CURRENT_BINARY_DIR}/version.cc)
# Build the executables
ADD_EXECUTABLE(${SOLVER1}
src/${SOLVER1}.cc
)
ADD_EXECUTABLE(${SOLVER2}
src/${SOLVER2}.cc
)
# Setup targets
DEAL_II_SETUP_TARGET(${SOLVER1})
DEAL_II_SETUP_TARGET(${SOLVER2})
# the environment variable precice_DIR is searched by default
FIND_PACKAGE(precice 3.0
HINTS ${precice_DIR} ${PRECICE_DIR} $ENV{PRECICE_DIR}
)
IF(NOT ${precice_FOUND})
MESSAGE(FATAL_ERROR "\n"
"*** Could not locate a (sufficiently recent) version of preCICE. ***\n\n"
"You may want to either pass a flag -Dprecice_DIR=/path/to/precice to cmake\n"
"(where the path points to the installation prefix or the build directory)\n"
" or set an environment variable \"precice_DIR\" that contains this path."
)
ENDIF()
MESSAGE(STATUS "Found preCICE version ${precice_VERSION} at ${precice_DIR}")
# Link targets to preCICE
TARGET_LINK_LIBRARIES(${SOLVER1} version precice::precice)
TARGET_LINK_LIBRARIES(${SOLVER2} version precice::precice)
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/include)
# Some take over from deal.II's autopilot
IF(CMAKE_GENERATOR MATCHES "Ninja")
SET(_make_command "$ ninja")
ELSE()
SET(_make_command " $ make")
ENDIF()
INSTALL(TARGETS ${SOLVER1} ${SOLVER2} DESTINATION bin)
#
# Custom "debug" and "release" make targets:
#
IF(${DEAL_II_BUILD_TYPE} MATCHES "Debug")
ADD_CUSTOM_TARGET(debug
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMAND ${CMAKE_COMMAND} -E echo "*** Switched to Debug mode. Now recompile with: ${_make_command}"
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMENT "Switching CMAKE_BUILD_TYPE to Debug"
VERBATIM
)
ENDIF()
IF(${DEAL_II_BUILD_TYPE} MATCHES "Release")
ADD_CUSTOM_TARGET(release
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMAND ${CMAKE_COMMAND} -E echo "*** Switched to Release mode. Now recompile with: ${_make_command}"
COMMAND ${CMAKE_COMMAND} -E echo "***"
COMMENT "Switching CMAKE_BUILD_TYPE to Release"
VERBATIM
)
ENDIF()