-
Notifications
You must be signed in to change notification settings - Fork 22
/
CMakeLists.txt
309 lines (252 loc) · 11.1 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
CMAKE_MINIMUM_REQUIRED(VERSION 3.24)
# project name
PROJECT(matador)
# project version
STRING(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
SET(APP_MAJOR_VERSION 0)
SET(APP_MINOR_VERSION 9)
SET(APP_PATCH_LEVEL 2)
SET(APP_VERSION "${APP_MAJOR_VERSION}.${APP_MINOR_VERSION}.${APP_PATCH_LEVEL}")
MESSAGE(STATUS "${PROJECT_NAME_UPPER} ${APP_VERSION}")
# Common compiler flags
# These are defined for clang/gcc compatibility.
# When non-compatible flags are implemented then we must specify them separately.
SET(GCC_CLANG_COMMON_FLAGS "-std=c++14 -Wall -Wextra -pedantic -ftemplate-backtrace-limit=0")
SET(GCC_CLANG_COMMON_FLAGS_DEBUG "-O0 -g -DDEBUG")
SET(GCC_CLANG_COMMON_FLAGS_RELEASE "-O1 -DNDEBUG")
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
SET(CMAKE_BUILD_PARALLEL_LEVEL 4)
IF(CMAKE_COMPILER_IS_GNUCXX)
MESSAGE(STATUS "GCC detected - Adding compiler flags")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_CLANG_COMMON_FLAGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "${GCC_CLANG_COMMON_FLAGS_DEBUG}")
SET(CMAKE_CXX_FLAGS_RELEASE "${GCC_CLANG_COMMON_FLAGS_RELEASE}")
message(STATUS "Common flags ${CMAKE_CXX_FLAGS}")
message(STATUS "Debug flags ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "Relase flags ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "Linker flags ${CMAKE_EXE_LINKER_FLAGS}")
ELSEIF(CMAKE_CXX_COMPILER MATCHES "clang")
MESSAGE(STATUS "Clang detected - Adding compiler flags")
SET(CMAKE_CXX_FLAGS "${GCC_CLANG_COMMON_FLAGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "${GCC_CLANG_COMMON_FLAGS_DEBUG}")
SET(CMAKE_CXX_FLAGS_RELEASE "${GCC_CLANG_COMMON_FLAGS_RELEASE}")
ELSEIF(MSVC)
MESSAGE(STATUS "MSVC detected - Adding compiler flags")
SET(CMAKE_CXX_FLAGS "/std:c++14 /W3 /EHsc /bigobj")
SET(CMAKE_CXX_FLAGS_DEBUG "/MDd /Od /Zi /D_DEBUG /DDEBUG")
SET(CMAKE_CXX_FLAGS_RELEASE "/O1 /DNDEBUG")
ENDIF()
MESSAGE(STATUS "Architecture: ${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_SYSTEM_NAME}")
SET(SYSTEM_NAME_LOWER)
STRING(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME_LOWER)
# add module path
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
IF (NOT CMAKE_BUILD_TYPE)
MESSAGE(STATUS "No build type selected, default to Release")
SET(CMAKE_BUILD_TYPE "Release")
ELSE()
MESSAGE(STATUS "Current build type ${CMAKE_BUILD_TYPE}")
ENDIF()
OPTION(COVERAGE "Enable generation of code coverage" false)
IF (NOT COVERAGE_TESTS)
SET(COVERAGE_TESTS "all")
ENDIF()
OPTION(ARCH "Compiler architecture for Clang/GCC" "")
OPTION(EXAMPLES "Build examples" true)
FIND_PACKAGE( Threads REQUIRED )
if (NOT MSVC AND (COVERAGE) AND CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT CMAKE_CXX_COMPILER MATCHES "clang")
MESSAGE(STATUS "coverage for compiler ${CMAKE_CXX_COMPILER}")
MESSAGE(STATUS "coverage tests are: ${COVERAGE_TESTS}")
SET(GCOV_BINARY "gcov" CACHE STRING "gcov binary")
MESSAGE(STATUS "gcov binary: ${GCOV_BINARY}")
# INCLUDE(CodeCoverage)
MESSAGE(STATUS "will generate coverage data")
SET(GCOV_ADDITIONAL_FLAGS "-fprofile-arcs -ftest-coverage")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCOV_ADDITIONAL_FLAGS}")
SET(CMAKE_C_FLAGS "{CMAKE_C_FLAGS} ${GCOV_ADDITIONAL_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${GCOV_ADDITIONAL_FLAGS} ")
# SETUP_TARGET_FOR_COVERAGE(coverage test_matador src coverage "exec;${COVERAGE_TESTS}")
else()
MESSAGE(STATUS "no coverage for compiler ${CMAKE_CXX_COMPILER}")
endif()
SET(NET_LIBRARIES)
if (WIN32)
# find_library(WSOCK32_LIBRARY wsock32)
# find_library(WS2_32_LIBRARY ws2_32)
# message(STATUS "WSOCK32 ${WSOCK32_LIBRARY}")
# message(STATUS "WS2_32 ${WS2_32_LIBRARY}")
MESSAGE(STATUS "Appending Windows Socket libs")
LIST(APPEND NET_LIBRARIES wsock32 ws2_32)
# LIST(APPEND NET_LIBRARIES ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY})
endif()
# Put the libaries and binaries that get built into directories at the
# top of the build tree rather than in hard-to-find leaf
# directories. This simplifies manual testing and the use of the build
# tree rather than installed Boost libraries.
IF (WIN32)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin)
SET(CMAKE_MODULE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin)
ELSE()
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
SET(CMAKE_MODULE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
ENDIF()
#
# configure include dir
#
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
SET(BACKENDS
SQLite3
MySQL
ODBC
PostgreSQL
)
FOREACH(backend ${BACKENDS})
STRING(TOUPPER ${backend} BACKEND_UPPER)
OPTION(${PROJECT_NAME_UPPER}_${BACKEND_UPPER} "Enable or disable backend ${backend}" TRUE)
OPTION(${PROJECT_NAME_UPPER}_${BACKEND_UPPER}_TEST "Enable or disable backend ${backend} tests" TRUE)
IF (${PROJECT_NAME_UPPER}_${BACKEND_UPPER})
FIND_PACKAGE(${backend})
IF (${BACKEND_UPPER}_FOUND)
ADD_DEFINITIONS(-D${PROJECT_NAME_UPPER}_${BACKEND_UPPER})
IF (${PROJECT_NAME_UPPER}_${BACKEND_UPPER}_TEST)
MESSAGE(STATUS "Enable ${backend} tests")
ADD_DEFINITIONS(-D${PROJECT_NAME_UPPER}_${BACKEND_UPPER}_TEST)
ENDIF()
ELSE()
MESSAGE(STATUS "No backend ${backend}")
ENDIF()
ELSE()
MESSAGE(STATUS "Backend ${backend} disabled")
ENDIF()
ENDFOREACH(backend)
INCLUDE(Matador)
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
# https://cmake.org/Wiki/CMake_RPATH_handling
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(CMAKE_MACOSX_RPATH TRUE)
# contains the full path to the top level directory of your build tree
MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} )
# contains the full path to the root of your project source directory,
# i.e. to the nearest directory where CMakeLists.txt contains the PROJECT() command
MESSAGE( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} )
MESSAGE( STATUS "CMAKE_BINARY_DIR: " ${CMAKE_BINARY_DIR} )
ENABLE_TESTING()
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(doc)
ADD_SUBDIRECTORY(test)
if (EXAMPLES)
ADD_SUBDIRECTORY(examples EXCLUDE_FROM_ALL)
ADD_SUBDIRECTORY(sandbox EXCLUDE_FROM_ALL)
ENDIF()
INSTALL(
DIRECTORY ${PROJECT_BINARY_DIR}/doc/web/
DESTINATION share/doc/matador
COMPONENT doc
)
set(ARCHPKG_ARCH ${CMAKE_SYSTEM_PROCESSOR})
if (${ARCH} MATCHES "32")
set(ARCHPKG_ARCH "x86")
elseif(${ARCH} MATCHES "64")
set(CPACK_SYSTEM_NAME "x86_64")
else()
set(ARCHPKG_ARCH ${CMAKE_SYSTEM_PROCESSOR})
endif()
add_custom_target(archpkg
COMMAND ${CMAKE_COMMAND}
-D NAME=${PROJECT_NAME}
-D URL=https://zussel.github.io/matador
-D DESC=Matador\ -\ take\ your\ database\ by\ the\ horns
-D VERSION=${APP_VERSION}
-D SRC_DIR=${PROJECT_SOURCE_DIR}
-D ARCH=${ARCHPKG_ARCH}
-D VERSION_INCLUDE_DIR=matador
-D VERSION_FILE=version.hpp
-P ${CMAKE_MODULE_PATH}/CreateArchLinuxPackage.cmake
)
# Basic CPack configuration
SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
SET(CPACK_PACKAGE_VENDOR "zussel")
SET(CPACK_PACKAGE_CONTACT "[email protected]")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "matador - take your database by the horns")
SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/License")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
SET(CPACK_PACKAGE_VERSION_MAJOR ${APP_MAJOR_VERSION})
SET(CPACK_PACKAGE_VERSION_MINOR ${APP_MINOR_VERSION})
SET(CPACK_PACKAGE_VERSION_PATCH ${APP_PATCH_LEVEL})
SET(CPACK_PACKAGE_INSTALL_DIRECTORY ${PROJECT_NAME})
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
if (${ARCH} MATCHES "32")
SET(CPACK_SYSTEM_NAME "x86-${SYSTEM_NAME_LOWER}")
elseif(${ARCH} MATCHES "64")
SET(CPACK_SYSTEM_NAME "x86_64-${SYSTEM_NAME_LOWER}")
else()
SET(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_PROCESSOR}-${SYSTEM_NAME_LOWER}")
endif()
endif()
SET(CPACK_GENERATOR "DEB;RPM;STGZ;TGZ;TZ")
# Tell CPack all of the components to install. The "ALL"
# refers to the fact that this is the set of components that
# will be included when CPack is instructed to put everything
# into the binary installer (the default behavior).
SET(CPACK_COMPONENTS_ALL libraries headers doc)
# Set the displayed names for each of the components to install.
# These will be displayed in the list of components inside the installer.
SET(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME ${PROJECT_NAME})
SET(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "${PROJECT_NAME} Headers")
# Provide descriptions for each of the components to install.
# When the user hovers the mouse over the name of a component,
# the description will be shown in the "Description" box in the
# installer. If no descriptions are provided, the "Description"
# box will be removed.
SET(CPACK_COMPONENT_LIBRARIES_DESCRIPTION "Take your application by the horns")
SET(CPACK_COMPONENT_HEADERS_DESCRIPTION "C/C++ header files for ${PROJECT_NAME}")
# Put the components into two different groups: "Runtime" and "Development"
#SET(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime")
SET(CPACK_COMPONENT_LIBRARIES_GROUP "Development")
SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
# Expand the "Development" group by default, since we have so few components.
# Also, provide this group with a description.
SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_EXPANDED ON)
SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION "All of the tools you'll ever need to develop software")
# It doesn't make sense to install the headers without the libraries
# (because you could never use the headers!), so make the headers component
# depend on the libraries component.
SET(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
# Create two installation types with pre-selected components.
# The "Developer" installation has just the library and headers,
# while the "Full" installation has everything.
SET(CPACK_ALL_INSTALL_TYPES Full Developer)
SET(CPACK_INSTALL_TYPE_FULL_DISPLAY_NAME "Everything")
SET(CPACK_COMPONENT_LIBRARIES_INSTALL_TYPES Developer Full)
SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
#SET(CPACK_COMPONENT_APPLICATIONS_INSTALL_TYPES Full)
SET(CPACK_PACKAGE_DIRECTORY "${PROJECT_SOURCE_DIR}/Package")
# Debian package settings
set(CPACK_DEB_COMPONENT_INSTALL OFF)
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
set(CPACK_DEBIAN_COMPRESSION_TYPE "gzip")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://zussel.github.io/matador")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF)
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION ON)
#set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/packaging/postinst;")
set(CPACK_DEBIAN_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
# RPM package settings
set(CPACK_RPM_COMPONENT_INSTALL OFF)
set(CPACK_RPM_PACKAGE_RELEASE "1")
set(CPACK_RPM_PACKAGE_SUMMARY "Matador")
set(CPACK_RPM_PACKAGE_DESCRIPTION "Matador - a c++ orm library")
set(CPACK_RPM_PACKAGE_LICENSE "GPLv3")
set(CPACK_RPM_PACKAGE_VENDOR "zussel")
set(CPACK_RPM_PACKAGE_URL "https://zussel.github.io/matador")
set(CPACK_RPM_PACKAGE_AUTOREQ 0)
set(CPACK_RPM_PACKAGE_AUTOPROV 0)
# Include CPack to introduce the appropriate targets
INCLUDE(CPack)