-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
181 lines (161 loc) · 4.59 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
# min cmake version
cmake_minimum_required(VERSION 3.14.0)
# project description
project(
chem_tools
VERSION 1.0.0
DESCRIPTION "ChemTools"
LANGUAGES CXX
)
# default build type
set(default_build_type "Release")
# executable
add_executable(${PROJECT_NAME})
# sources
target_sources(
${PROJECT_NAME}
PRIVATE
src/main.cpp
src/input_parser.cpp
src/sundials/cvode/interface.cpp
src/results/csv_writer.cpp
src/results/hdf5_writer.cpp
src/results/console_logger.cpp
src/embedded_python_functions.cpp
src/applications/reactors/base.cpp
src/applications/reactors/reactors.cpp
)
# includes
target_include_directories(
${PROJECT_NAME}
PRIVATE
include
)
# c++ standard
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
# extra compiler options
target_compile_options(${PROJECT_NAME} PRIVATE -pedantic -Wall -Wextra -Werror)
# path to dependencies
if(NOT DEFINED LIB_PATH)
message(FATAL_ERROR
"Path to dependencies must be specified."
" All dependencies must be available in the same directory."
" Use -DLIB_PATH=/path/to/dependencies to set this path."
)
else()
list(APPEND CMAKE_PREFIX_PATH ${LIB_PATH})
endif()
# -- Dependency: fmt
find_package(fmt REQUIRED)
if(fmt_FOUND)
target_link_libraries(${PROJECT_NAME} fmt::fmt)
else()
message(FATAL_ERROR "Dependency fmt not found")
endif()
#-- Dependency: Cantera
find_library(
CANTERA_LIBRARY
NAMES cantera
HINTS ${CMAKE_PREFIX_PATH}/cantera/lib
NO_DEFAULT_PATH
)
if(CANTERA_LIBRARY)
target_link_libraries(${PROJECT_NAME} ${CANTERA_LIBRARY})
else()
message(FATAL_ERROR "Dependency: Cantera library not found")
endif()
find_path(
CANTERA_INCLUDE_DIR
NAMES thermo.h transport.h kinetics.h core.h
PATHS ${CMAKE_PREFIX_PATH}/cantera/include NO_DEFAULT_PATH
PATH_SUFFIXES cantera
)
if(CANTERA_INCLUDE_DIR)
string( REPLACE "include/cantera" "include" CANTERA_INCLUDE_DIR ${CANTERA_INCLUDE_DIR} )
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${CANTERA_INCLUDE_DIR})
else()
message(FATAL_ERROR "Dependency: Cantera includes not found")
endif()
# -- Dependency: Threads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(Threads_FOUND)
target_link_libraries(${PROJECT_NAME} Threads::Threads)
else()
message(FATAL_ERROR "Dependency: Threads not found")
endif()
# -- Dependency: Sundials - CVODE
set(SUNDIALS_REQUIRED_COMPONENTS sundials_cvode sundials_nvecserial)
foreach(SUNDIALS_COMPONENT ${SUNDIALS_REQUIRED_COMPONENTS})
find_library(
SUNDIALS_LIBRARY
NAMES "lib${SUNDIALS_COMPONENT}.so"
HINTS ${CMAKE_PREFIX_PATH}/sundials/lib
NO_DEFAULT_PATH
)
if(SUNDIALS_LIBRARY)
target_link_libraries(${PROJECT_NAME} ${SUNDIALS_LIBRARY})
else()
message(FATAL_ERROR "Dependency: Sundials component library ${SUNDIALS_COMPONENT} not found")
endif()
endforeach()
set(SUNDIALS_INCLUDE_DIR ${CMAKE_PREFIX_PATH}/sundials/include)
if(EXISTS ${SUNDIALS_INCLUDE_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${SUNDIALS_INCLUDE_DIR})
else()
message(FATAL_ERROR "Dependency: Sundials includes not found")
endif()
# -- Dependency: yaml-cpp
find_package(yaml-cpp REQUIRED)
if(yaml-cpp_FOUND)
target_link_libraries(${PROJECT_NAME} yaml-cpp)
else()
message(FATAL_ERROR "Dependency yaml-cpp not found")
endif()
# -- Dependency: Boost components
find_package(
Boost
COMPONENTS system filesystem
REQUIRED
)
if(Boost_FOUND)
target_link_libraries(
${PROJECT_NAME}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
)
else()
message(FATAL_ERROR "Dependency Boost not found")
endif()
# -- Dependency: units
find_package(units REQUIRED)
if(units_FOUND)
target_link_libraries(${PROJECT_NAME} units-static)
else()
message(FATAL_ERROR "Dependency units not found")
endif()
# -- Dependency: Eigen3
find_package(Eigen3 REQUIRED)
if(Eigen3_FOUND)
target_link_libraries(${PROJECT_NAME} Eigen3::Eigen)
else()
message(FATAL_ERROR "Dependency Eigen3 not found")
endif()
#-- Dependency: HDF5
set(HDF5_USE_STATIC_LIBRARIES ON)
find_package(HDF5 REQUIRED COMPONENTS CXX HL)
if(HDF5_FOUND)
target_include_directories(${PROJECT_NAME} PRIVATE ${HDF5_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${HDF5_CXX_LIBRARIES} ${HDF5_CXX_HL_LIBRARIES})
else()
message(FATAL_ERROR "Dependency HDF5 not found")
endif()
#-- Dependency: Python
# Look preferably for version 3. If not found, version 2.
find_package(Python COMPONENTS Development)
if(Python_FOUND)
target_include_directories(${PROJECT_NAME} PRIVATE ${Python_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${Python_LIBRARIES})
else()
message(FATAL_ERROR "Dependency Python not found")
endif()