forked from tango-controls-hdbpp/libhdbpp-timescale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
215 lines (168 loc) · 6.92 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
203
204
205
206
207
208
209
210
211
212
213
214
215
# Functions and Pre-build -----------------------------------
# Stop messy in source builds
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
message( FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt." )
endif()
# Start Build Config -----------------------------------
cmake_minimum_required(VERSION 3.11)
set(CMAKE_SKIP_RPATH true)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_COLOR_MAKEFILE ON)
# Library output name for the final binaries
set(LIBHDBPP_TIMESCALE_NAME "libhdb++timescale")
# Versioning
set(VERSION_MAJOR "2")
set(VERSION_MINOR "0")
set(VERSION_PATCH "0")
set(VERSION_METADATA "")
set(VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
# Add any include paths from the command line
list(APPEND INCLUDE_PATHS ${CMAKE_INCLUDE_PATH})
list(APPEND INCLUDE_PATHS ${CMAKE_SOURCE_DIR})
list(APPEND LIBRARY_PATHS ${CMAKE_LIBRARY_PATH})
# Start the project
project(libhdbpp_timescale VERSION ${VERSION_STRING} LANGUAGES CXX)
# Require this for the libpqxx build, also this project is c++14 minimum
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Build options
option(BUILD_UNIT_TESTS "Build unit tests" OFF)
option(BUILD_BENCHMARK_TESTS "Build benchmarking tests (Forces RELEASE build)" OFF)
option(ENABLE_CLANG "Enable clang code and layout analysis" OFF)
if(BUILD_UNIT_TESTS)
message(STATUS "Unit tests will be built")
endif(BUILD_UNIT_TESTS)
if(BUILD_BENCHMARK_TESTS)
message(STATUS "Benchmark tests will be built (Forces RELEASE build)")
set(CMAKE_BUILD_TYPE "Release")
endif(BUILD_BENCHMARK_TESTS)
# arch install definitions
include(GNUInstallDirs)
message(STATUS "Searching for libraries...")
# Variable to contain a list of all the libs we depend on
set(TDB_LIBRARIES)
# allow pkg-config to search the CMAKE_PREFIX_PATH
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
list(APPEND CMAKE_PREFIX_PATH "/usr")
# Find Dependencies ---------------------
include(cmake/FindLibraries.cmake)
# First find tango if it has not already been found. Returns an interface library
# called TangoInterfaceLibrary
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Tango)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Attempt to find the various libraries the project is dependent on
if(TDB_LIBRARIES)
find_libraries(LIBRARIES ${TDB_LIBRARIES} SEARCH_PATHS ${LIBRARY_PATHS})
set(TDB_FOUND_LIBRARIES ${FOUND_LIBRARIES})
endif(TDB_LIBRARIES)
# Thirdparty Integration -----------------------------------
# build google benchmark (target: benchmark)
# do not build tests of benchmarking lib
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Suppressing benchmark's tests" FORCE)
add_subdirectory(thirdparty/google/benchmark EXCLUDE_FROM_ALL)
# build tests (targets: gtest_main, gtest)
add_subdirectory(thirdparty/google/googletest/googletest EXCLUDE_FROM_ALL)
# Include the thirdparty projects
add_subdirectory(thirdparty/libpqxx EXCLUDE_FROM_ALL)
add_subdirectory(thirdparty/spdlog EXCLUDE_FROM_ALL)
add_subdirectory(thirdparty/Catch2 EXCLUDE_FROM_ALL)
# For ease of use, we set the libpqxx output to our projects build directory,
# then if we build libpqxx as a shared library its easy to find
set_target_properties(pqxx_shared
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
# Currently we link libpqxx into our library as a static object, to ease
# deployment, so we make this small change here.
set_target_properties(pqxx_static
PROPERTIES
POSITION_INDEPENDENT_CODE 1)
# Code Analysis -----------------------------------
if(ENABLE_CLANG)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# To find clang, find_program will search your PATH environment variable.
# Ensure if you have a non-standard clang install, that it has been added
# to your path.
find_program(CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable")
if(NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found.")
else(NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}")
endif(NOT CLANG_TIDY_EXE)
endif(ENABLE_CLANG)
# Source -----------------------------------
add_subdirectory(src)
# Build Targets -----------------------------------
# Shared library --------
add_library(libhdbpp_timescale_shared_library SHARED ${SRC_FILES})
target_link_libraries(libhdbpp_timescale_shared_library
PUBLIC ${TDB_FOUND_LIBRARIES} pqxx_static spdlog::spdlog_header_only Threads::Threads
PRIVATE TangoInterfaceLibrary)
target_include_directories(libhdbpp_timescale_shared_library
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
${INCLUDE_PATHS}
"${PROJECT_BINARY_DIR}")
set_target_properties(libhdbpp_timescale_shared_library
PROPERTIES
OUTPUT_NAME hdb++timescale
LINK_FLAGS "-Wl,--no-undefined"
CXX_STANDARD 14
POSITION_INDEPENDENT_CODE 1
VERSION ${VERSION_STRING}
SOVERSION ${VERSION_MAJOR})
if(DO_CLANG_TIDY)
set_target_properties(libhdbpp_timescale_shared_library
PROPERTIES
CXX_CLANG_TIDY ${DO_CLANG_TIDY})
endif(DO_CLANG_TIDY)
target_compile_options(libhdbpp_timescale_shared_library
PRIVATE "$<$<CONFIG:DEBUG>:-g>")
# Static library --------
add_library(libhdbpp_timescale_static_library STATIC EXCLUDE_FROM_ALL ${SRC_FILES})
target_link_libraries(libhdbpp_timescale_static_library
PUBLIC ${TDB_FOUND_LIBRARIES} pqxx_static spdlog Threads::Threads
PRIVATE TangoInterfaceLibrary)
target_include_directories(libhdbpp_timescale_static_library
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
${INCLUDE_PATHS}
"${PROJECT_BINARY_DIR}")
set_target_properties(libhdbpp_timescale_static_library
PROPERTIES
OUTPUT_NAME hdb++timescale
LINK_FLAGS "-Wl,--no-undefined"
CXX_STANDARD 14
EXCLUDE_FROM_ALL 1)
target_compile_options(libhdbpp_timescale_static_library
PRIVATE "$<$<CONFIG:DEBUG>:-g>")
# Install Config -----------------------------------
install(
TARGETS libhdbpp_timescale_shared_library
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN HdbppTimescaleDb.hpp)
# Tests -----------------------------------
if(BUILD_UNIT_TESTS)
add_subdirectory(test)
endif(BUILD_UNIT_TESTS)
if(BUILD_BENCHMARK_TESTS)
add_subdirectory(benchmark)
endif(BUILD_BENCHMARK_TESTS)