forked from SimVascular/svZeroDSolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
233 lines (199 loc) · 8.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
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
# Copyright (c) Stanford University, The Regents of the University of
# California, and others.
#
# All Rights Reserved.
#
# See Copyright-SimVascular.txt for additional details.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject
# to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required(VERSION 3.22)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
project(svZeroDSolver)
include(FetchContent)
# Enable code coverage
# -----------------------------------------------------------------------------
set(ENABLE_COVERAGE OFF CACHE BOOL "Enable code coverage")
# coverage
if(ENABLE_COVERAGE)
# set compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -coverage -g")
# find required tools
find_program(LCOV lcov REQUIRED)
find_program(GENHTML genhtml REQUIRED)
# add coverage target
add_custom_target(coverage
# gather data
COMMAND ${LCOV} --directory . --capture --output-file coverage.info --ignore-errors gcov --exclude '/usr/include/*' --exclude '/usr/lib/*' --exclude '*/_deps/*'
# generate report
COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
# -----------------------------------------------------------------------------
# Set the location to store the binaries and libraries created by this project.
# -----------------------------------------------------------------------------
#
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Need to add the -fPIC flag to build the interface shared library.
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
# -----------------------------------------------------------------------------
# Fetch Eigen
# -----------------------------------------------------------------------------
# Eigen is a header-only C++ template library for linear algebra.
#
FetchContent_Declare(
Eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
set(EIGEN_BUILD_DOC OFF)
set(BUILD_TESTING OFF)
set(EIGEN_BUILD_PKGCONFIG OFF)
set( OFF)
FetchContent_MakeAvailable(Eigen)
# -----------------------------------------------------------------------------
# Fetch pybind11
# -----------------------------------------------------------------------------
# pybind11 is a library used to create Python bindings of existing C++ code.
#
set(PYBIND11_PYTHON_VERSION 3.8 CACHE STRING "")
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG master
)
FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
FetchContent_Populate(pybind11)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()
# -----------------------------------------------------------------------------
# Fetch nlohmann/json
# -----------------------------------------------------------------------------
# This is a C++ header-only library for reading JSON files.
#
FetchContent_Declare(
json
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
)
FetchContent_MakeAvailable(json)
# -----------------------------------------------------------------------------
# Fetch pybind11_json
# -----------------------------------------------------------------------------
# pybind11_json is an nlohmann::json to pybind11 bridge that converts
# between nlohmann::json and py::object objects.
#
FetchContent_Declare(
pybind11_json
GIT_REPOSITORY https://github.com/pybind/pybind11_json.git
GIT_TAG master
)
FetchContent_MakeAvailable(pybind11_json)
# -----------------------------------------------------------------------------
# Set executables for each application.
# -----------------------------------------------------------------------------
# There are two executables
# 1) svzerodsolver
# 2) svzerodcalibrator
#
add_executable(svzerodsolver applications/svzerodsolver.cpp
$<TARGET_OBJECTS:svzero_algebra_library>
$<TARGET_OBJECTS:svzero_model_library>
$<TARGET_OBJECTS:svzero_solve_library>
)
add_executable(svzerodcalibrator applications/svzerodcalibrator.cpp
$<TARGET_OBJECTS:svzero_algebra_library>
$<TARGET_OBJECTS:svzero_optimize_library>
$<TARGET_OBJECTS:svzero_model_library>
)
# -----------------------------------------------------------------------------
# Setup building of the pysvzerod Python extension module.
# -----------------------------------------------------------------------------
# Replace EXCLUDE_FROM_ALL with SHARED to test building the Python
# shared library.
pybind11_add_module(pysvzerod EXCLUDE_FROM_ALL applications/pysvzerod.cpp)
# -----------------------------------------------------------------------------
# Add source sub-directories.
# -----------------------------------------------------------------------------
add_subdirectory("src/algebra")
add_subdirectory("src/interface")
add_subdirectory("src/model")
add_subdirectory("src/optimize")
add_subdirectory("src/solve")
# -----------------------------------------------------------------------------
# Set header file include directories.
# -----------------------------------------------------------------------------
#
target_include_directories(svzerodsolver PUBLIC
${CMAKE_SOURCE_DIR}/src/algebra
${CMAKE_SOURCE_DIR}/src/model
${CMAKE_SOURCE_DIR}/src/solve
)
target_include_directories(svzerodcalibrator PUBLIC
${CMAKE_SOURCE_DIR}/src/algebra
${CMAKE_SOURCE_DIR}/src/model
${CMAKE_SOURCE_DIR}/src/optimize
${CMAKE_SOURCE_DIR}/src/solve
)
target_include_directories(pysvzerod PUBLIC
${CMAKE_SOURCE_DIR}/src/algebra
${CMAKE_SOURCE_DIR}/src/model
${CMAKE_SOURCE_DIR}/src/optimize
${CMAKE_SOURCE_DIR}/src/solve
)
# -----------------------------------------------------------------------------
# Set the libraries each application needs to link to.
# -----------------------------------------------------------------------------
# These are needed only for the header-only applications.
#
target_link_libraries(svzerodsolver PRIVATE Eigen3::Eigen)
target_link_libraries(svzerodsolver PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(svzerodcalibrator PRIVATE Eigen3::Eigen)
target_link_libraries(svzerodcalibrator PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(pysvzerod PRIVATE Eigen3::Eigen)
target_link_libraries(pysvzerod PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(pysvzerod PRIVATE pybind11_json)
target_link_libraries(pysvzerod PRIVATE svzero_algebra_library)
target_link_libraries(pysvzerod PRIVATE svzero_model_library)
target_link_libraries(pysvzerod PRIVATE svzero_optimize_library)
target_link_libraries(pysvzerod PRIVATE svzero_solve_library)
# Create distribution
set(ENABLE_DISTRIBUTION OFF CACHE BOOL "Enable installer build")
add_subdirectory("distribution")
# -----------------------------------------------------------------------------
# Enforce and check code format
# -----------------------------------------------------------------------------
# set paths of files to format
set(SDIR ${PROJECT_SOURCE_DIR}/src/**/)
# format the code
add_custom_target(codeformat
COMMAND find ${SDIR}/*.h ${SDIR}/*.cpp | xargs clang-format -style=file:${PROJECT_SOURCE_DIR}/.clang-format -i)
# check code format
add_custom_target(codecheck
COMMAND find ${SDIR}/*.h ${SDIR}/*.cpp | xargs clang-format -style=file:${PROJECT_SOURCE_DIR}/.clang-format --dry-run --Werror)