-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
280 lines (213 loc) · 7.02 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#--------------------------------------------------------------
# CMake file for HydroChrono library and its demos
# Eventually will add SWIG and python lines to generate python
# library from C++ code
#--------------------------------------------------------------
cmake_minimum_required(VERSION 3.18.2)
# guard against in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ")
endif()
# Default build type to use if none was specified
if(NOT DEFINED HYDROCHRONO_DEFAULT_BUILD_TYPE)
set(HYDROCHRONO_DEFAULT_BUILD_TYPE "Release")
endif()
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${HYDROCHRONO_DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE ${HYDROCHRONO_DEFAULT_BUILD_TYPE}
CACHE STRING "Choose the type of build." FORCE)
mark_as_advanced(CMAKE_BUILD_TYPE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
#--------------------------------------------------------------
# Modify the project name if you want:
#--------------------------------------------------------------
project(HydroChrono
VERSION 0.2.2
DESCRIPTION "A hydrodynamic library for use with Project Chrono."
LANGUAGES CXX
)
# Add the cmake folder so the FindSphinx module is found
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# ===================
# OPTIONS
# ===================
option (HYDROCHRONO_ENABLE_TESTS "Enable tests" ON)
option (HYDROCHRONO_ENABLE_IRRLICHT "Enable irrlicht visualization library" ON)
option (HYDROCHRONO_ENABLE_DEMOS "Enable demo executables" ON)
option (HYDROCHRONO_ENABLE_USER_DOC "User's documentation" OFF)
option (HYDROCHRONO_ENABLE_PROG_DOC "Programmer's documentation" OFF)
# find required packages and libraries to make HydroChrono library
set (LIB_TYPE STATIC) # or SHARED
string(TOLOWER ${LIB_TYPE} SEARCH_TYPE)
if(HYDROCHRONO_ENABLE_IRRLICHT)
# If irrlicht is required chrono library must be compiled with irrlicht
find_package(Chrono COMPONENTS Irrlicht CONFIG REQUIRED)
add_compile_definitions(HYDROCHRONO_HAVE_IRRLICHT=1)
else(HYDROCHRONO_ENABLE_IRRLICHT)
find_package(Chrono CONFIG REQUIRED)
endif(HYDROCHRONO_ENABLE_IRRLICHT)
find_package(HDF5 NAMES hdf5 COMPONENTS CXX ${SEARCH_TYPE})
#-----------------------------------------------------------------------------
# Fix for VS 2017 15.8 and newer to handle alignment specification with Eigen
#-----------------------------------------------------------------------------
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(MSVC AND ${MSVC_VERSION} GREATER_EQUAL 1915)
add_compile_definitions( "ENABLE_EXTENDED_ALIGNED_STORAGE" )
endif()
endif()
#--------------------------------------------------------------
# Tweaks to disable some warnings with MSVC
#--------------------------------------------------------------
if(MSVC)
# avoids deprecation warnings
add_definitions(
-D_CRT_SECURE_NO_DEPRECATE
-D_SCL_SECURE_NO_DEPRECATE
-DNOMINMAX
)
add_compile_options(/wd4275) # disable warnings triggered by Irrlicht
add_compile_options(/wd4251) # class needs to have dll-interface
endif()
# =======================
# HydroChrono Library
# =======================
set(HYDROCHRONO_SOURCES
src/h5fileinfo.cpp
src/chloadaddedmass.cpp
src/hydro_forces.cpp
src/helper.cpp
src/wave_types.cpp
)
add_library(HydroChrono STATIC ${HYDROCHRONO_SOURCES} )
target_compile_features(HydroChrono PUBLIC cxx_std_17)
target_include_directories(
HydroChrono
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${CHRONO_INCLUDE_DIRS}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_compile_definitions(HydroChrono
PUBLIC
PRIVATE
CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\"
)
target_compile_options(HydroChrono BEFORE
PUBLIC
${CHRONO_CXX_FLAGS}
)
target_link_options(HydroChrono BEFORE
PUBLIC
${CHRONO_LINKER_FLAGS}
)
set_target_properties(HydroChrono
PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
# temporary hack
# seems there is no namespace target hdf5:: on linux
# for HDF5 version 1.10 to 1.14 ?
if(NOT TARGET hdf5::hdf5_cpp-static)
add_library(hdf5::hdf5_cpp-static ALIAS hdf5_cpp-static)
endif()
target_link_libraries(HydroChrono
PUBLIC
${CHRONO_LIBRARIES}
PRIVATE
hdf5::hdf5_cpp-static
)
# ====================
# Irrlicht GUI helper
# ====================
add_library(HydroChronoGUI)
target_sources(
HydroChronoGUI
PUBLIC
src/gui/guihelper.cpp
)
target_compile_features(HydroChronoGUI PUBLIC cxx_std_17)
target_include_directories(
HydroChronoGUI
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${CHRONO_INCLUDE_DIRS}
)
if(HYDROCHRONO_ENABLE_IRRLICHT)
endif(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_options(HydroChronoGUI BEFORE
PUBLIC
${CHRONO_CXX_FLAGS}
)
target_link_options(HydroChronoGUI BEFORE
PUBLIC
${CHRONO_LINKER_FLAGS}
)
target_link_libraries(HydroChronoGUI
PRIVATE
${CHRONO_LIBRARIES}
)
# ====================
# DEMOS
# ====================
if(HYDROCHRONO_ENABLE_DEMOS)
add_subdirectory(demos)
endif(HYDROCHRONO_ENABLE_DEMOS)
# ====================
# TESTS
# ====================
if(HYDROCHRONO_ENABLE_TESTS)
if(DEFINED ENV{HYDROCHRONO_DATA_DIR})
# Override DATA_DIR by environement variable
set(HYDROCHRONO_DATA_DIR $ENV{HYDROCHRONO_DATA_DIR})
else()
set(HYDROCHRONO_DATA_DIR "${PROJECT_SOURCE_DIR}/demos")
endif()
include(CTest)
enable_testing()
add_subdirectory(tests)
endif(HYDROCHRONO_ENABLE_TESTS)
# Not a good idea to copy DLLs
# dosen't work on Linux
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
#add_DLL_copy_command("${CHRONO_DLLS}")
include(GNUInstallDirs)
# Export to include as external library in other projects
install(TARGETS HydroChrono
EXPORT HydroChronoTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
EXPORT HydroChronoTargets
FILE HydroChronoTargets.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/HydroChrono/cmake"
NAMESPACE HydroChrono::
)
install(
DIRECTORY include/hydroc
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/HydroChronoConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/HydroChronoConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/HydroChrono/cmake"
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/HydroChronoConfig.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/HydroChrono/cmake"
)
export(
EXPORT HydroChronoTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/HydroChronoTargets.cmake"
NAMESPACE HydroChrono::
)