-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
executable file
·229 lines (190 loc) · 6.97 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# -------------------------------------------
# Copyright (c) 2021 - 2024 Prashant K. Jha
# -------------------------------------------
# PeriDEM https://github.com/prashjha/PeriDEM
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE)
cmake_minimum_required(VERSION 3.10)
#----------------------------------#
#<<<<<<<<<< Project name >>>>>>>>>>#
#----------------------------------#
project(PeriDEM LANGUAGES CXX C)
set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/prashjha/PeriDEM")
set(CMAKE_PROJECT_DESCRIPTION "PeriDEM -- Peridynamics-based high-fidelity model for granular media")
# version
set(VERSION_MAJOR 0)
set(VERSION_MINOR 2)
set(VERSION_UPDATE 0)
#----------------------------------#
#<<<<<<<<<< Project setting >>>>>>>>>>#
#----------------------------------#
# config files
configure_file("${PROJECT_SOURCE_DIR}/PeriDEMConfig.h.in"
"${PROJECT_SOURCE_DIR}/src/PeriDEMConfig.h")
# executable directory
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin")
# set the common library directory
get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
if("${LIB64}" STREQUAL "TRUE")
set(LIBSUFFIX 64)
else()
set(LIBSUFFIX "")
endif()
set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib${LIBSUFFIX}")
# postfix for debug
set(CMAKE_DEBUG_POSTFIX d)
# cmake scripts to help search dependencies
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
# set default build type "Release"
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
# cmake policy <-- check if it is still needed
#cmake_policy(SET CMP0023 OLD)
#----------------------------------#
#<<<<<<<<<< Compiler flags >>>>>>>>>>#
#----------------------------------#
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -fPIC")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif ()
# set standard to 17
set(CMAKE_CXX_STANDARD 20)
if (${Enable_CMAKE_Debug_Build})
message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_CXX_STANDARD = ${CMAKE_CXX_STANDARD}")
endif()
#----------------------------------#
#<<<<<<<<<< New CMAKE variables >>>>>>>>>>#
#----------------------------------#
set(Enable_CMAKE_Debug_Build TRUE CACHE BOOL "Output important information during cmake")
set(Enable_Documentation FALSE CACHE BOOL "Generate documentation if ON")
set(Enable_Tests FALSE CACHE BOOL "Build test executables and perform tests if ON")
set(Enable_High_Load_Tests FALSE CACHE BOOL "Perform high load tests if ON")
set(Disable_Docker_MPI_Tests TRUE CACHE BOOL "Disable (ON) or enable (OFF) MPI tests inside docker")
set(Enable_Apps FALSE CACHE BOOL "Build applications if ON")
set(Test_Exec_Path "${CMAKE_CURRENT_BINARY_DIR}/test/bin")
set(Test_Data_Path "${CMAKE_CURRENT_BINARY_DIR}/test/test_data/")
set(Apps_Path "${CMAKE_CURRENT_BINARY_DIR}/apps/")
#----------------------------------#
#<<<<<<<<<< Rpath setting >>>>>>>>>>#
#----------------------------------#
# source: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
#----------------------------------#
#<<<<<<<<<< Testing >>>>>>>>>>#
#----------------------------------#
if (${Enable_CMAKE_Debug_Build})
message(STATUS "Enable_Tests = ${Enable_Tests}")
message(STATUS "Enable_High_Load_Tests = ${Enable_High_Load_Tests}")
message(STATUS "Disable_Docker_MPI_Tests = ${Disable_Docker_MPI_Tests}")
message(STATUS "Test_Exec_Path = ${Test_Exec_Path}")
message(STATUS "Test_Data_Path = ${Test_Data_Path}")
endif()
enable_testing()
#----------------------------------#
#<<<<<<<<<< Dependencies >>>>>>>>>>#
#----------------------------------#
find_program (BASH_PROGRAM bash REQUIRED)
if (${Enable_CMAKE_Debug_Build})
message(STATUS "BASH_PROGRAM = ${BASH_PROGRAM}")
endif()
# #<<<<<<<<<< MPI >>>>>>>>>>#
find_package(MPI REQUIRED)
if (${Enable_CMAKE_Debug_Build})
message(STATUS "MPI_INCLUDE_PATH = ${MPI_INCLUDE_PATH}")
endif()
# #<<<<<<<<<< Threads >>>>>>>>>>#
find_package(Threads REQUIRED)
# #<<<<<<<<<< YAML >>>>>>>>>>#
find_package(YamlCpp REQUIRED)
# #<<<<<<<<<< VTK >>>>>>>>>>#
#find_package(VTK REQUIRED)
find_package(VTK COMPONENTS CommonCore CommonDataModel IOXML)
if (VTK_VERSION VERSION_LESS "6")
message(FATAL_ERROR "ERROR: Requires VTK above version 6")
endif ()
if (${Enable_CMAKE_Debug_Build})
message(STATUS "VTK_MAJOR_VERSION = ${VTK_MAJOR_VERSION}")
message(STATUS "VTK_DIR = ${VTK_DIR}")
message(STATUS "VTK_LIBRARIES = ${VTK_LIBRARIES}")
endif()
# #<<<<<<<<<< BLAS+LAPACK >>>>>>>>>>#
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
# #<<<<<<<<<< Metis >>>>>>>>>>#
find_package(Metis REQUIRED)
# #<<<<<<<<<< Doxygen >>>>>>>>>>#
if(${Enable_Documentation})
find_package(Doxygen)
endif()
#----------------------------------#
#<<<<<<<<<< Include directories >>>>>>>>>>#
#----------------------------------#
if (${Enable_CMAKE_Debug_Build})
message(STATUS "Including key directories")
endif()
include_directories(SYSTEM external)
include_directories(${MPI_INCLUDE_PATH})
include_directories(src)
#----------------------------------#
#<<<<<<<<<< Subdirectories >>>>>>>>>>#
#----------------------------------#
# external libraries
add_subdirectory(external/)
# PeriDEM sub-directories
add_subdirectory(src/util)
add_subdirectory(src/rw)
add_subdirectory(src/inp)
add_subdirectory(src/material)
add_subdirectory(src/loading)
add_subdirectory(src/geometry)
add_subdirectory(src/fe)
add_subdirectory(src/particle)
add_subdirectory(src/nsearch)
add_subdirectory(src/model)
# test directory
if(${Enable_Tests})
if (${Enable_CMAKE_Debug_Build})
message(STATUS "Building test")
endif()
add_subdirectory(test)
endif()
# documentation
if(${Enable_Documentation})
if (${Enable_CMAKE_Debug_Build})
message(STATUS "Building documentation")
endif()
add_subdirectory(docs)
endif()
#----------------------------------#
#<<<<<<<<<< Applications >>>>>>>>>>#
#----------------------------------#
if(${Enable_Apps})
if (${Enable_CMAKE_Debug_Build})
message(STATUS "Building apps")
endif()
add_subdirectory(apps)
endif()
#----------------------------------#
#<<<<<<<<<< PeriDEM executable >>>>>>>>>>#
#----------------------------------#
add_executable(PeriDEM src/main.cpp)
target_link_libraries(PeriDEM PUBLIC Model)
#----------------------------------#
#<<<<<<<<<< Post build operations >>>>>>>>>>#
#----------------------------------#
# test directory
if(${Enable_Tests})
if (${Enable_CMAKE_Debug_Build})
message(STATUS "Copying test directory to build directory")
endif()
file(COPY
${CMAKE_SOURCE_DIR}/test/test_data/
DESTINATION
${PROJECT_BINARY_DIR}/test/test_data/)
endif()