This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
CMakeLists.txt
202 lines (164 loc) · 5.45 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
194
195
196
197
198
199
200
201
202
####################################
# General project definition
####################################
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.2 FATAL_ERROR)
option(BUILD_SHARED_LIBS "Build shared versions of libraries" ON)
option(INFLUXCXX_TESTING "Enable testing for this component" ON)
# Set cmake policy by version: https://cmake.org/cmake/help/latest/manual/cmake-policies.7.html
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.12)
endif()
# Define project
project(influxdb-cxx
VERSION 0.0.1
DESCRIPTION "InfluxDB C++ client library"
LANGUAGES CXX
)
# Documentation dir
#add_subdirectory(doc)
# Add compiler flags for warnings and debug symbols
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra")
# Set fPIC for all targets
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Set CMAKE_INSTALL_LIBDIR explicitly to lib (to avoid lib64 on CC7)
set(CMAKE_INSTALL_LIBDIR lib)
# Set the default build type to "RelWithDebInfo"
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "RelWithDebInfo"
CACHE
STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Coverage."
FORCE
)
endif()
# Add coverage flags to Debug build
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
endif()
# Fixes warning when using boost from brew
set(Boost_USE_MULTITHREADED TRUE)
####################################
# Dependencies
####################################
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(Boost COMPONENTS unit_test_framework system program_options)
find_package(CURL REQUIRED MODULE)
####################################
# Library
####################################
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
set(INCLUDE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/include")
# Create library
# note: BUILD_SHARED_LIBS specifies if static or shared
# as boost is build without -fPIC, we cannot
# statically link against it when building
# influxdb as shared object
add_library(InfluxDB
src/InfluxDB.cxx
src/Point.cxx
src/InfluxDBFactory.cxx
$<$<BOOL:${Boost_FOUND}>:src/UDP.cxx>
$<$<BOOL:${Boost_FOUND}>:src/UnixSocket.cxx>
src/HTTP.cxx
)
target_include_directories(InfluxDB
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
# Link targets
target_link_libraries(InfluxDB
PRIVATE
$<$<BOOL:${Boost_FOUND}>:Boost::system>
CURL::libcurl
)
# Use C++17
target_compile_features(InfluxDB PUBLIC cxx_std_17)
# Set compile definition if Boost found
target_compile_definitions(InfluxDB
PRIVATE
$<$<BOOL:${Boost_FOUND}>:INFLUXDB_WITH_BOOST>
)
####################################
# Tests
####################################
# Tests require Boost::unit_test_framework
if (Boost_FOUND AND INFLUXCXX_TESTING)
enable_testing()
set(TEST_SRCS
test/testUdp.cxx
test/testPoint.cxx
test/testHttp.cxx
test/testQuery.cxx
test/testFactory.cxx
)
foreach (test ${TEST_SRCS})
get_filename_component(test_name ${test} NAME)
string(REGEX REPLACE ".cxx" "" test_name ${test_name})
add_executable(${test_name} ${test})
target_link_libraries(${test_name}
PRIVATE
InfluxDB Boost::unit_test_framework
)
add_test(NAME ${test_name} COMMAND ${test_name})
set_tests_properties(${test_name} PROPERTIES TIMEOUT 60)
endforeach()
add_executable(benchmark test/benchmark.cxx)
target_link_libraries(benchmark PRIVATE InfluxDB Boost::program_options)
endif()
####################################
# Install
####################################
include(GNUInstallDirs)
# Build targets with install rpath on Mac to dramatically speed up installation
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}")
endif()
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif()
unset(isSystemDir)
# Install library
install(TARGETS InfluxDB
EXPORT InfluxDBTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# Create version file
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/cmake/InfluxDBConfigVersion.cmake"
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)
# Install headers
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Export targets
install(EXPORT InfluxDBTargets
FILE
InfluxDBTargets.cmake
NAMESPACE
InfluxData::
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/InfluxDB
)
# Configure and install Config files
configure_package_config_file(
cmake/InfluxDBConfig.cmake.in cmake/InfluxDBConfig.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/InfluxDB"
PATH_VARS CMAKE_INSTALL_PREFIX
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/InfluxDBConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/InfluxDBConfigVersion.cmake"
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/InfluxDB
)