forked from reaktoro/reaktoro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
169 lines (133 loc) · 5.98 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
# Set cmake version requirement
cmake_minimum_required(VERSION 3.9)
# Set the cmake module path of the project
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Use ccache to speed up repeated compilations
include(CCache)
# Set the name of the project
project(Reaktoro VERSION 1.2.2 LANGUAGES CXX)
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
# Check if a conda environment is active
include(CondaAware)
# Include this module to enable testing with CTest and dashboard submissions to CDash
include(CTest)
# Include the cmake variables with values for installation directories
include(GNUInstallDirs)
# Set the output directories of the built libraries and binaries
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
# Define which components of Reaktoro to build
option(REAKTORO_BUILD_ALL "Build everything." OFF)
option(REAKTORO_BUILD_DEMOS "Build demos." OFF)
option(REAKTORO_BUILD_DOCS "Build documentation." OFF)
option(REAKTORO_BUILD_INTERPRETER "Build the interpreter executable reaktoro." ON)
option(REAKTORO_BUILD_PYTHON "Build the python wrappers and python package reaktoro." ON)
option(REAKTORO_BUILD_TESTS "Build tests." OFF)
# Modify the REAKTORO_BUILD_* variables accordingly to BUILD_ALL
if(REAKTORO_BUILD_ALL MATCHES ON)
set(REAKTORO_BUILD_DEMOS ON)
set(REAKTORO_BUILD_DOCS ON)
set(REAKTORO_BUILD_INTERPRETER ON)
set(REAKTORO_BUILD_PYTHON ON)
set(REAKTORO_BUILD_TESTS ON)
endif()
# Set the CTest option BUILD_TESTING to the value of BUILD_TESTS
set(BUILD_TESTING BUILD_TEST)
# Define if Reaktoro should be built linking against openlibm instead of system's default libm
# Note: Ensure this option is ON when updating regression test data! Otherwise CI may fail.
option(REAKTORO_USE_OPENLIBM "Build linking with openlibm." OFF)
# Define if shared library should be build instead of static.
option(BUILD_SHARED_LIBS "Build shared libraries." ON)
# Define custom options
option(ENABLE_TESTING "Enable testing." on)
# Set the default build type to Release
if(NOT CMAKE_BUILD_TYPE)
# The build type selection for the project
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the build type for ${PROJECT_NAME}." FORCE)
# The build type options for the project
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)
endif()
# Set the list of compiler flags for MSVC compiler
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
add_compile_options(
/D_SCL_SECURE_NO_WARNINGS
/D_CRT_SECURE_NO_WARNINGS=1
/MP4
/EHsc
/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
/DNOMINMAX
/Zc:__cplusplus # This is needed to ensure __cplusplus is replaced with a correct value (e.g. 201703L) instead of fixed 199711L (see more on https://docs.microsoft.com/bs-cyrl-ba/cpp/build/reference/zc-cplusplus?view=vs-2019)
)
endif()
# Set the local directory where the third-party libraries are installed
set(REAKTORO_THIRDPARTY_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/thirdparty/install)
# Set path variables for the include and lib directories of the installed dependencies
set(REAKTORO_THIRDPARTY_INCLUDE_PATH ${REAKTORO_THIRDPARTY_INSTALL_PREFIX}/include)
set(REAKTORO_THIRDPARTY_LIBRARY_PATH ${REAKTORO_THIRDPARTY_INSTALL_PREFIX}/lib)
# Find all Reaktoro dependencies
include(ReaktoroFindDeps)
# Build the third-party libraries
add_subdirectory(thirdparty)
# Build the C++ library Reaktoro
add_subdirectory(Reaktoro)
# Build the Python extension module PyReaktoro and the Python packages reaktoro
if(REAKTORO_BUILD_PYTHON)
add_subdirectory(python)
endif()
# Build the Python package ireaktoro, the Reaktoro interpreter
if(REAKTORO_BUILD_INTERPRETER)
add_subdirectory(interpreter)
endif()
# Build the demonstration applications
if(REAKTORO_BUILD_DEMOS)
add_subdirectory(demos)
else()
add_subdirectory(demos EXCLUDE_FROM_ALL)
endif()
# Build the project documentation
if(REAKTORO_BUILD_DOCS)
add_subdirectory(docs)
else()
add_subdirectory(docs EXCLUDE_FROM_ALL)
endif()
# Build the tests
if(REAKTORO_BUILD_TESTS)
add_subdirectory(tests)
else()
add_subdirectory(tests EXCLUDE_FROM_ALL)
endif()
# Build the utilities
add_subdirectory(utilities EXCLUDE_FROM_ALL)
# Add target "python" for manual building of python wrappers, as `make python`, if REAKTORO_BUILD_PYTHON is OFF
add_custom_target(python
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/python")
# Add target "interpreter" for manual building of interpreter, as `make interpreter`, if REAKTORO_BUILD_INTERPRETER is OFF
add_custom_target(interpreter
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY "${CURRENT_BINARY_DIR}/interpreter")
# Add target "demos" for manual building of demos, as `make demos`, if REAKTORO_BUILD_DEMOS is OFF
add_custom_target(demos
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/demos")
# Add target "tests" for manual building of tests, as `make tests`, if REAKTORO_BUILD_TESTS is OFF
add_custom_target(tests
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests")
# Add target "utilities" for manual building of utilities, as `make utilities`, if REAKTORO_BUILD_UTILITIES is OFF
add_custom_target(utilities
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/utilities")
# Copy database files to binary directory
add_custom_target(databases ALL COMMENT "Copy database files to binary directory")
add_custom_command(
TARGET databases POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/databases
${CMAKE_BINARY_DIR}/databases)
# Package Reaktoro
include(PackageReaktoro)
# Install the cmake config files that permit users to use find_package(Reaktoro)
include(ReaktoroInstallCMakeConfigFiles)