-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
141 lines (116 loc) · 4.71 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
# Require a certain version of cmake
cmake_minimum_required(VERSION 3.9)
# Set the name of the project
project(ChemicalFun VERSION 0.1.10 LANGUAGES CXX)
# Set the cmake module path of the project
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
# Use ccache to speed up repeated compilations
include(CCache)
# Define variables with the GNU standard installation directories
include(GNUInstallDirs)
# Modify the TFUN_BUILD_* variables accordingly to BUILD_ALL
if(CHEMICALFUN_BUILD_ALL MATCHES ON)
set(CHEMICALFUN_BUILD_SHARED_LIBS ON)
set(CHEMICALFUN_BUILD_STATIC_LIBS ON)
set(CHEMICALFUN_BUILD_TESTS ON)
set(CHEMICALFUN_BUILD_EXAMPLES ON)
set(CHEMICALFUN_BUILD_PYTHON ON)
endif()
if (CHEMICALFUN_WASM MATCHES ON)
# Define which types of libraries to build
option(CHEMICALFUN_BUILD_STATIC_LIBS "Build static libraries." ON)
set(CHEMICALFUN_BUILD_PYTHON ON)
# Set the list of compiler flags for Clang compiler
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options(-std=c++11 -Wall -Wno-ignored-attributes -Wno-pedantic -Wno-variadic-macros -Wno-deprecated -fcxx-exceptions -frtti)
endif()
else()
# Ensure proper configuration if in a conda environment
include(CondaAware)
option(CHEMICALFUN_BUILD_SHARED_LIBS "Build shared libraries." ON)
option(CHEMICALFUN_BUILD_STATIC_LIBS "Build static libraries." ON)
option(CHEMICALFUN_BUILD_EXAMPLES "Build examples." OFF)
option(CHEMICALFUN_BUILD_TESTS "Build tests." ON)
option(CHEMICALFUN_BUILD_PYTHON "Build the python wrappers and python package." ON)
# Define if shared library should be build instead of static.
option(BUILD_SHARED_LIBS "Build shared libraries." ON)
# Set libraries to be compiled with position independent code mode (i.e., fPIC option in GNU compilers)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
# Used into conda only
if(DEFINED ENV{CONDA_PREFIX})
option(USE_SPDLOG_PRECOMPILED "Use spdlog in compiled version" ON)
else()
option(USE_SPDLOG_PRECOMPILED "Use spdlog in compiled version" OFF)
endif()
# 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 C++ standard
set(CMAKE_CXX_STANDARD 17)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 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
)
endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options(-Wall -Wno-ignored-attributes -Wno-pedantic -Wno-variadic-macros -Wno-deprecated)
endif()
# test thread safe
#set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread")
#set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=thread")
# Find Eigen library and include its directory
#find_package(Eigen3 3.3.7 REQUIRED)
#message(STATUS "Found Eigen3 v${Eigen3_VERSION}: ${Eigen3_INCLUDE_DIRS}")
# Find the Python interpreter
if(CHEMICALFUN_BUILD_PYTHON)
find_package(pybind11 2.2.0 REQUIRED)
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
if(NOT pybind11_FOUND)
set(CHEMICALFUN_BUILD_PYTHON OFF)
message(WARNING "pybind11 has not been found. "
"Cannot build python bindings for chemicalfun")
endif()
endif()
# Set the thermofun source directory path
set(CHEMICALFUN_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
# Set the include directories
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
include_directories("/usr/local/include")
link_directories("/usr/local/lib")
endif()
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
include_directories("c:/usr/local/include")
link_directories("c:/usr/local/lib")
endif()
include_directories(${CHEMICALFUN_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
# Find all Reaktoro dependencies
include(ChemicalFunFindDeps)
# Build ChemicalFun library
add_subdirectory(src)
# Build the tests
if(CHEMICALFUN_BUILD_TESTS)
add_subdirectory(tests)
endif()
# Build the examples
if(CHEMICALFUN_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Build python wraper
if(CHEMICALFUN_BUILD_PYTHON)
add_subdirectory(python)
endif()
# Install the cmake config files that permit users to use find_package(ChemicalFun)
include(ChemicalFunInstallCMakeConfigFiles)