-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
174 lines (140 loc) · 6.05 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#////////////////////////////////////////////////////////////////////////////////
#// Copyright (c) 2020-2021 Prashant K. Jha, Tobias Koeppl, Andreas Wagner
#//
#// Distributed under the Boost Software License, Version 1.0. (See accompanying
#// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#////////////////////////////////////////////////////////////////////////////////
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
# ****************************************************************************
# Project information
# ****************************************************************************
project(TumorModels LANGUAGES CXX)
set(CMAKE_PROJECT_DESCRIPTION "Collection of tumor growth models")
# version
set(VERSION_MAJOR 0)
set(VERSION_MINOR 1)
set(VERSION_UPDATE 0)
# ****************************************************************************
# Project setting
# ****************************************************************************
# cmake scripts to help search dependencies
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
# Create executible in main directory of build directory
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
# set default build type "Release"
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
# set flag for information dump during cmake build
set(Enable_CMAKE_Debug_Build TRUE CACHE BOOL "Output important information during cmake for isolating build issues")
# set flag for documentation
set(Enable_Documentation FALSE CACHE BOOL "Generate documentation")
# set flag that enables or disables tests
set(Enable_Tests FALSE CACHE BOOL "Build test executibles and perform tests")
# add flag which allows user to restrict building only specific models
set(LIBTG_BUILD_FLAG "Build_NetFVFE" CACHE STRING "Specify which if all or subset
of models to be built")
# ****************************************************************************
# Testing
# ****************************************************************************
enable_testing()
if (${Enable_CMAKE_Debug_Build})
message("Enable_Tests = ${Enable_Tests}")
endif()
# ****************************************************************************
# Package search
# ****************************************************************************
# **** bash ****#
find_program (BASH_PROGRAM bash REQUIRED)
# **** MPI ****#
find_package(MPI REQUIRED)
# add this line only when you are using openmpi which has a different c++ bindings
add_definitions(-DOMPI_SKIP_MPICXX)
# **** pthreads ****#
find_package(Threads REQUIRED)
# **** libmesh ****#
find_package(LibMesh REQUIRED)
# **** petsc ****#
# Note: -DPETSC_DIR should point to the same directory that libmesh was compiled with
find_package(Petsc REQUIRED)
# debug output flags
if (${Enable_CMAKE_Debug_Build})
message("LIBMESH_DEFINITIONS = ${PC_LIBMESH_CFLAGS_DEFS}")
message("LIBMESH_FLAGS = ${PC_LIBMESH_CFLAGS_FLAGS}")
message("LIBMESH_INCLUDE_DIRS = ${LIBMESH_INCLUDE_DIRS}")
message("LIBMESH_LIBRARIES = ${LIBMESH_LIBRARIES}")
message("PETSC_LIBRARIES = ${PETSC_LIBRARIES}")
endif()
# **** vtk ****#
find_package(VTK REQUIRED)
if (VTK_VERSION VERSION_LESS "6")
message(FATAL_ERROR "ERROR: Only VTK library 6+ supported")
endif ()
if (${Enable_CMAKE_Debug_Build})
message("VTK_DIR = ${VTK_DIR}")
message("VTK_LIBRARIES = ${VTK_LIBRARIES}")
message("VTK_INCLUDE_DIRS = ${VTK_INCLUDE_DIRS}")
endif()
# issue error and exit
if ((NOT MPI_FOUND) AND (NOT LIBMESH_FOUND))
message(FATAL_ERROR "ERROR: MPI and LIBMESH are required")
endif ()
# ****************************************************************************
# Build, compiler, linker flags
# ****************************************************************************
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG ")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -fPIC -L /usr/lib/libmesh-1.6.1/lib/libtimpi_opt.so.2")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBMESH_FLAGS} -xHost -std=c++14")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -std=c++11 -stdlib=libc++")
endif ()
if (${Enable_CMAKE_Debug_Build})
message("Build type: ${CMAKE_BUILD_TYPE}")
message("CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
message("CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
message("CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message("CMAKE_CXX_STANDARD = ${CMAKE_CXX_STANDARD}")
endif()
# ****************************************************************************
# Include directories
# ****************************************************************************
include_directories(${LIBMESH_INCLUDE_DIRS})
include_directories(${MPI_INCLUDE_PATH})
# ****************************************************************************
# Add subprojects
# ****************************************************************************
if (${Enable_CMAKE_Debug_Build})
message("LIBTG_BUILD_FLAG: ${LIBTG_BUILD_FLAG}")
endif()
if (${Enable_CMAKE_Debug_Build})
message("Gnerating build files for LibTG ")
endif()
add_subdirectory(models)
if(${Enable_Tests})
message("Gnerating build files for Test ")
add_subdirectory(tests)
endif()
# documentation
if(${Enable_Documentation})
if (${Enable_CMAKE_Debug_Build})
message("Adding Documentation ")
endif()
add_subdirectory(docs)
endif()
# ****************************************************************************
# Post build operations
# ****************************************************************************
# test directory
if(${Enable_Tests})
if (${Enable_CMAKE_Debug_Build})
message("Copying test data to build directory ")
endif()
add_custom_target("copydata" ALL)
add_custom_command(
TARGET "copydata" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/tests/test_data/
${PROJECT_BINARY_DIR}/tests/test_data/)
endif()