-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
231 lines (192 loc) · 7.61 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
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
project(sqlitepp)
set(TITLE "Sqlitepp")
set(AUTHOR "Matthew Chandler <[email protected]>")
set(COPYRIGHT "2019 Matthew Chandler")
set(SUMMARY "A thin sqlite C++ wrapper")
set(WEBSITE "http://github.com/mattvchandler/sqlitepp")
set(VERSION_MAJOR 1)
set(VERSION_MINOR 2)
set(VERSION_PATCH 3)
set(VERSION_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-Wall -Wextra)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# libraries
option(SQLITEPP_GEN_DOC_TARGET "Generate 'doc' target" ON)
option(INCLUDE_SQLITE "Download and include sqlite3 (removes dependency on external sqlite library)" OFF)
option(DISABLE_SHARED_LIBS "Disable building of static library" OFF)
option(DISABLE_STATIC_LIBS "Disable building of shared library" OFF)
if(INCLUDE_SQLITE)
find_package(Threads REQUIRED)
set(SQLITE_VERSION_STR "3280000")
set(SQLITE_ARCHIVE_NAME "sqlite-amalgamation-${SQLITE_VERSION_STR}")
file(GENERATE OUTPUT "${PROJECT_BINARY_DIR}/get_sqlite.cmake" CONTENT
"file(DOWNLOAD
https://www.sqlite.org/2019/${SQLITE_ARCHIVE_NAME}.zip
\"${PROJECT_BINARY_DIR}/${SQLITE_ARCHIVE_NAME}.zip\"
SHOW_PROGRESS)
execute_process(COMMAND \${CMAKE_COMMAND} -E tar xf
\"${PROJECT_BINARY_DIR}/${SQLITE_ARCHIVE_NAME}.zip\"
)
file(COPY \"${PROJECT_BINARY_DIR}/${SQLITE_ARCHIVE_NAME}/sqlite3.h\"
DESTINATION \"${PROJECT_BINARY_DIR}/include/${PROJECT_NAME}/\")\n")
add_custom_command(OUTPUT "${PROJECT_BINARY_DIR}/${SQLITE_ARCHIVE_NAME}/sqlite3.c"
COMMAND ${CMAKE_COMMAND} -P "${PROJECT_BINARY_DIR}/get_sqlite.cmake"
COMMENT "Getting sqlite source code")
add_custom_target(get_sqlite
DEPENDS "${PROJECT_BINARY_DIR}/${SQLITE_ARCHIVE_NAME}/sqlite3.c")
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/include/"
"${PROJECT_BINARY_DIR}/include"
)
set(SOURCES
"${PROJECT_BINARY_DIR}/${SQLITE_ARCHIVE_NAME}/sqlite3.c"
src/database.cpp
src/sqlite.cpp
src/error.cpp
src/stmt.cpp
)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(SQLITE sqlite3 REQUIRED)
file(GENERATE OUTPUT "${PROJECT_BINARY_DIR}/include/${PROJECT_NAME}/sqlite3.h"
CONTENT "#include <sqlite3.h>\n")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include/
${SQLITE_INCLUDE_DIRS}
"${PROJECT_BINARY_DIR}/include"
)
link_directories(
${SQLITE_LIBRARY_DIRS}
)
set(SOURCES
src/database.cpp
src/sqlite.cpp
src/error.cpp
src/stmt.cpp
)
endif()
if(SQLITEPP_GEN_DOC_TARGET)
find_package(Doxygen)
if(DOXYGEN_FOUND)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/doc/html/index.html
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
DEPENDS ${PROJECT_BINARY_DIR}/Doxyfile
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/README.md
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*
COMMENT "Generating documentation with Doxygen")
add_custom_target(doc DEPENDS ${PROJECT_BINARY_DIR}/doc/html/index.html)
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES doc)
endif()
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${PROJECT_BINARY_DIR}/Doxyfile
@ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
@ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-config-version.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
@ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.pc
@ONLY)
# main compilation
add_library(${PROJECT_NAME}_obj OBJECT ${SOURCES})
set_target_properties(${PROJECT_NAME}_obj PROPERTIES POSITION_INDEPENDENT_CODE 1)
set(SHARED_LIBS ${PROJECT_NAME})
set(STATIC_LIBS ${PROJECT_NAME}-static)
set(TARGETS ${SHARED_LIBS} ${STATIC_LIBS})
if(DISABLE_STATIC_LIBS AND DISABLE_SHARED_LIBS)
message(FATAL_ERROR "Both static and shared libs disabled - nothing to do!")
endif()
if(DISABLE_SHARED_LIBS)
set(STATIC_LIBS ${SHARED_LIBS})
unset(SHARED_LIBS)
set(TARGETS ${STATIC_LIBS})
endif()
if(DISABLE_STATIC_LIBS)
unset(STATIC_LIBS)
set(TARGETS ${SHARED_LIBS})
endif()
if(NOT DISABLE_SHARED_LIBS)
add_library(${SHARED_LIBS} SHARED $<TARGET_OBJECTS:${PROJECT_NAME}_obj>)
endif()
if(NOT DISABLE_STATIC_LIBS)
add_library(${STATIC_LIBS} STATIC $<TARGET_OBJECTS:${PROJECT_NAME}_obj>)
endif()
if(INCLUDE_SQLITE)
add_dependencies(${PROJECT_NAME}_obj
get_sqlite)
foreach(TARGET ${TARGETS})
target_link_libraries(${TARGET}
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS}
)
endforeach()
else()
foreach(TARGET ${TARGETS})
target_link_libraries(${TARGET}
${SQLITE_LIBRARIES}
)
endforeach()
endif()
# install targets
install(TARGETS ${TARGETS}
EXPORT "${PROJECT_NAME}-targets"
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin"
)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}" DESTINATION "include")
install(DIRECTORY "${PROJECT_BINARY_DIR}/include/${PROJECT_NAME}" DESTINATION "include")
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" DESTINATION "lib/cmake/${PROJECT_NAME}")
install(EXPORT "${PROJECT_NAME}-targets" DESTINATION "lib/cmake/${PROJECT_NAME}")
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" DESTINATION "lib/cmake/${PROJECT_NAME}")
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.pc" DESTINATION "share/pkgconfig")
# CPack vars
set(CPACK_GENERATOR TGZ)
set(CPACK_PACKAGE_CONTACT "${AUTHOR}")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY)
set(CPACK_PACKAGE_NAME "lib${PROJECT_NAME}-dev")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${TITLE}: ${SUMMARY}")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_SOURCE_IGNORE_FILES
${PROJECT_BINARY_DIR}/*
${CMAKE_CURRENT_SOURCE_DIR}/.git/*
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}
)
# Debian-specific settings
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
find_program(DPKG "dpkg")
if(DPKG)
set(CPACK_GENERATOR DEB;TGZ)
execute_process(COMMAND ${DPKG} --print-architecture
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
if(NOT INCLUDE_SQLITE)
set(CPACK_DEBIAN_PACKAGE_DEPENDS
"libsqlite3-0")
else()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
endif()
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
endif()
endif()
include(CPack)