forked from mongodb/mongo-cxx-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
193 lines (162 loc) · 6.05 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
# Copyright 2016 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif()
project(MONGO_CXX_DRIVER LANGUAGES CXX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.2")
message(FATAL_ERROR "Insufficient GCC version - GCC 4.8.2+ required")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0.23506")
message(FATAL_ERROR "Insufficient Microsoft Visual C++ version - MSVC 2015 Update 1+ required")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.1")
message(FATAL_ERROR "Insufficient Apple clang version - XCode 5.1+ required")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5")
message(FATAL_ERROR "Insufficient clang version - clang 3.5+ required")
endif()
else()
message(WARNING "Unknown compiler... recklessly proceeding without a version check")
endif()
# All of our target compilers support the deprecated
# attribute. Normally, we would just let the GenerateExportHeader
# subsystem do this via configure check, but there appears to be a
# CMake bug where if -Werror is set on the command line, it breaks the
# configure check, and we end up not configuring the macro. That means
# that we end up not being able to turn deprecation warnings into
# errors. Instead, since we know all our platforms offer the feature,
# just hard enable it here.
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(COMPILER_HAS_DEPRECATED true)
else()
set(COMPILER_HAS_DEPRECATED_ATTR true)
endif()
set (CMAKE_SKIP_BUILD_RPATH false)
set (CMAKE_BUILD_WITH_INSTALL_RPATH false)
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH true)
# Ensure that RPATH is used on OSX
set(CMAKE_MACOSX_RPATH 1)
# Enforce the C++ standard, and disable extensions
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
# Include the required modules
include(GenerateExportHeader)
include(InstallRequiredSystemLibraries)
# Allow the user to decide whether to build the shared libaries or the static libraries.
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
set(BUILD_VERSION "0.0.0" CACHE STRING "Library version (for both libbsoncxx and libmongocxx)")
# If the user did not customize the install prefix,
# set it to live under build so we don't inadverently pollute /usr/local
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
endif()
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${PROJECT_SOURCE_DIR}/cmake
)
include(GNUInstallDirs)
include (ParseVersion)
if(BUILD_VERSION STREQUAL "0.0.0")
if(EXISTS ${CMAKE_BINARY_DIR}/VERSION_CURRENT)
file(STRINGS ${CMAKE_BINARY_DIR}/VERSION_CURRENT BUILD_VERSION)
else()
find_package(PythonInterp)
if(PYTHONINTERP_FOUND)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} etc/calc_release_version.py
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE CALC_RELEASE_VERSION
RESULT_VARIABLE CALC_RELEASE_VERSION_RESULT
)
if(NOT CALC_RELEASE_VERSION_RESULT STREQUAL 0)
# If python failed above, stderr would tell the user about it
message(WARNING
"BUILD_VERSION not specified and could not be calculated\
(script invocation failed); setting library version to 0.0.0"
)
else()
set(BUILD_VERSION ${CALC_RELEASE_VERSION})
endif()
else()
message(WARNING
"BUILD_VERSION not specified and could not be calculated\
(Python was not found on the system); setting library version to 0.0.0"
)
endif()
endif()
endif()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default is Release")
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_custom_target(hugo_dir
COMMAND ${CMAKE_COMMAND} -E make_directory hugo
)
add_custom_target(hugo
DEPENDS hugo_dir
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/docs
COMMAND hugo
VERBATIM
)
add_custom_target(hugo-deploy
DEPENDS hugo
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND etc/deploy-to-ghpages.pl --hugo [email protected]:mongodb/mongo-cxx-driver
VERBATIM
)
add_custom_target(docs_dir_current
COMMAND ${CMAKE_COMMAND} -E make_directory docs/api/current
)
add_custom_target(doxygen-current
DEPENDS docs_dir_current
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND doxygen ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
VERBATIM
)
add_custom_target(doxygen-all
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND etc/generate-all-apidocs.pl
VERBATIM
)
add_custom_target(doxygen-deploy
DEPENDS doxygen-all
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND etc/deploy-to-ghpages.pl --doxygen [email protected]:mongodb/mongo-cxx-driver
VERBATIM
)
add_custom_target(format
python ${CMAKE_SOURCE_DIR}/etc/clang_format.py format
VERBATIM
)
add_custom_target(format-lint
python ${CMAKE_SOURCE_DIR}/etc/clang_format.py lint
VERBATIM
)
add_custom_target(docs
DEPENDS hugo doxygen-current
)
set(THIRD_PARTY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/third_party)
enable_testing()
add_subdirectory(src)
add_subdirectory(examples EXCLUDE_FROM_ALL)
add_subdirectory(benchmark EXCLUDE_FROM_ALL)