forked from lballabio/QuantLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
185 lines (162 loc) · 6.89 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
cmake_minimum_required(VERSION 3.15.0)
# For MSVC RUNTIME LIBRARY, need CMP0091=NEW and cmake 3.15+
cmake_policy(SET CMP0091 NEW)
# Version info
set(QUANTLIB_VERSION_MAJOR 1)
set(QUANTLIB_VERSION_MINOR 24)
set(QUANTLIB_VERSION_PATCH 0)
set(QUANTLIB_VERSION ${QUANTLIB_VERSION_MAJOR}.${QUANTLIB_VERSION_MINOR}.${QUANTLIB_VERSION_PATCH})
# Project Info
set(PACKAGE_NAME "QuantLib")
set(PACKAGE_VERSION "${QUANTLIB_VERSION}-dev")
set(PACKAGE_VERSION_HEX "0x01240000")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "https://github.com/lballabio/QuantLib/issues/")
# Default build type for single-config generators (set this before project() command)
# For multi-config generators, such as Visual Studio, use: cmake --build . --config=<CONFIG>
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE
STRING "Build type for single-config generators" FORCE)
endif()
project(${PACKAGE_NAME} LANGUAGES CXX DESCRIPTION "The QuantLib C++ Library")
# Path for package-local cmake modules
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Installation directories
set(QL_INSTALL_BINDIR "bin" CACHE STRING "Installation directory for executables")
set(QL_INSTALL_LIBDIR "lib" CACHE STRING "Installation directory for libraries")
set(QL_INSTALL_INCLUDEDIR "include" CACHE STRING "Installation directory for headers")
set(QL_INSTALL_EXAMPLESDIR "lib/QuantLib/examples" CACHE STRING
"Installation directory for examples")
# Options
option(QL_BUILD_BENCHMARK "Build benchmark" ON)
option(QL_BUILD_EXAMPLES "Build examples" ON)
option(QL_BUILD_TEST_SUITE "Build test suite" ON)
option(QL_ENABLE_OPENMP "Detect and use OpenMP" OFF)
option(QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER "Enable the parallel unit test runner" OFF)
option(QL_ENABLE_SESSIONS "Singletons return different instances for different sessions" OFF)
option(QL_ENABLE_SINGLETON_THREAD_SAFE_INIT "Enable thread-safe singleton initialization" OFF)
option(QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN "Enable the thread-safe observer pattern" OFF)
option(QL_ENABLE_TRACING "Tracing messages should be allowed" OFF)
option(QL_ERROR_FUNCTIONS "Error messages should include current function information" OFF)
option(QL_ERROR_LINES "Error messages should include file and line information" OFF)
option(QL_EXTRA_SAFETY_CHECKS "Extra safety checks should be performed" OFF)
option(QL_HIGH_RESOLUTION_DATE "Enable date resolution down to microseconds" OFF)
option(QL_INSTALL_BENCHMARK "Install benchmark" ON)
option(QL_INSTALL_EXAMPLES "Install examples" ON)
option(QL_INSTALL_TEST_SUITE "Install test suite" ON)
option(QL_TAGGED_LAYOUT "Library names use layout tags" ${MSVC})
option(QL_USE_DISPOSABLE "Use the Disposable class template. Not needed for C++11" OFF)
option(QL_USE_INDEXED_COUPON "Use indexed coupons instead of par coupons" OFF)
option(QL_USE_STD_CLASSES "Enable all QL_USE_STD_ options" OFF)
option(QL_USE_STD_SHARED_PTR "Use standard smart pointers instead of Boost ones" OFF)
option(QL_USE_STD_UNIQUE_PTR "Use std::unique_ptr instead of std::auto_ptr" ON)
option(QL_USE_STD_FUNCTION "Use std::function and std::bind instead of Boost ones" OFF)
option(QL_USE_STD_TUPLE "Use std::tuple instead of boost::tuple" OFF)
# Convenience option to activate all STD options
if (QL_USE_STD_CLASSES)
set(QL_USE_STD_SHARED_PTR ON)
set(QL_USE_STD_UNIQUE_PTR ON)
set(QL_USE_STD_FUNCTION ON)
set(QL_USE_STD_TUPLE ON)
endif()
# Project shared libs ON for UNIX
if (NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ${UNIX})
endif()
# Boost static libs ON for MSVC
if (NOT DEFINED Boost_USE_STATIC_LIBS)
set(Boost_USE_STATIC_LIBS ${MSVC})
endif()
# Boost static runtime ON for MSVC
if (NOT DEFINED Boost_USE_STATIC_RUNTIME)
set(Boost_USE_STATIC_RUNTIME ${MSVC})
endif()
# Boost thread and unit_test_framework needed for tests and benchmark
find_package(Boost 1.58.0 REQUIRED COMPONENTS thread unit_test_framework)
# Avoid using Boost auto-linking
add_compile_definitions(BOOST_ALL_NO_LIB)
if (QL_ENABLE_OPENMP)
find_package(OpenMP REQUIRED)
endif()
# Parallel test runner needs library rt on *nix for shm_open, etc.
if (QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER AND UNIX AND NOT APPLE)
find_library(RT_LIBRARY rt REQUIRED)
endif()
# Require C++11 or higher
if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
elseif(CMAKE_CXX_STANDARD LESS 11)
message(FATAL_ERROR "Please specify CMAKE_CXX_STANDARD of 11 or higher")
endif()
if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
# Avoid use of compiler language extensions, i.e. -std=c++11 not -std=gnu++11
if (NOT DEFINED CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS FALSE)
endif()
# If available, use PIC for shared libs and PIE for executables
if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
if (CMAKE_POSITION_INDEPENDENT_CODE)
# cmake policy CMP0083: add PIE support if possible (need cmake 3.14)
include(CheckPIESupported)
check_pie_supported()
endif()
# Configure files
set(QL_HAVE_CONFIG_H ON)
set(QL_VERSION ${PACKAGE_VERSION})
set(QL_HEX_VERSION ${PACKAGE_VERSION_HEX})
configure_file(ql/config.hpp.cfg ql/config.hpp @ONLY)
configure_file(ql/qldefines.hpp.cfg ql/qldefines.hpp @ONLY)
configure_file(ql/version.hpp.cfg ql/version.hpp @ONLY)
# Check for library name layout tagging
if (QL_TAGGED_LAYOUT)
set(DEBUG_POSTFIX "-mt")
set(RELEASE_POSTFIX "-mt")
if (NOT BUILD_SHARED_LIBS)
set(DEBUG_POSTFIX ${DEBUG_POSTFIX}-sgd)
set(RELEASE_POSTFIX ${RELEASE_POSTFIX}-s)
else()
set(DEBUG_POSTFIX ${DEBUG_POSTFIX}-gd)
endif()
if (${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set(DEBUG_POSTFIX ${DEBUG_POSTFIX}-x64)
set(RELEASE_POSTFIX ${RELEASE_POSTFIX}-x64)
endif()
set(CMAKE_DEBUG_POSTFIX ${DEBUG_POSTFIX})
set(CMAKE_RELEASE_POSTFIX ${RELEASE_POSTFIX})
set(CMAKE_RELWITHDEBINFO_POSTFIX ${RELEASE_POSTFIX})
set(CMAKE_MINSIZEREL_POSTFIX ${RELEASE_POSTFIX})
endif()
include(CTest)
include(Platform)
# Add subdirectories
add_subdirectory(ql)
if (QL_BUILD_EXAMPLES)
add_subdirectory(Examples)
endif()
if (QL_BUILD_TEST_SUITE OR QL_BUILD_BENCHMARK)
add_subdirectory(test-suite)
endif()
# CPack support (make package, make package_source)
set(CPACK_PACKAGE_VERSION_MAJOR ${QUANTLIB_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${QUANTLIB_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${QUANTLIB_VERSION_PATCH})
set(CPACK_PACKAGE_FILE_NAME ${PACKAGE_NAME}-${PACKAGE_VERSION})
set(CPACK_GENERATOR "TGZ" "ZIP" "7Z")
set(CPACK_SOURCE_PACKAGE_FILE_NAME ${PACKAGE_NAME}-${PACKAGE_VERSION})
set(CPACK_SOURCE_GENERATOR "TGZ" "ZIP" "7Z")
set(CPACK_SOURCE_IGNORE_FILES
"~$"
"\\\\.swp$"
"/[Bb]uild"
"/\\\\.app"
"/\\\\.cla"
"/\\\\.cod"
"/\\\\.git"
"/\\\\.lgt"
"/\\\\.mis")
include(CPack)