-
Notifications
You must be signed in to change notification settings - Fork 16
/
CMakeLists.txt
196 lines (150 loc) · 5.24 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
# NeoPG - cmake file
# Copyright 2017 The NeoPG developers
#
# NeoPG is released under the Simplified BSD License (see license.txt)
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
# Get version number before calling project().
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(GitVersion)
set(NeoPG_VERSION_STRING "${GIT_VERSION_STRING}")
set(NeoPG_VERSION_STRING_FULL "${GIT_VERSION_STRING_FULL}")
project(NeoPG VERSION "${NeoPG_VERSION_STRING}" LANGUAGES CXX)
message(STATUS "${PROJECT_NAME} ${${PROJECT_NAME}_VERSION_STRING_FULL}")
# Add targets for maintainers: release, changelog
set(GitRelease_USER "das-labor")
set(GitRelease_PROJECT "neopg")
include(GitRelease)
# Add user-settable options.
option(BUILD_SHARED_LIBS "Build shared libraries." ON)
# Compiler setup.
set(CXXSTD 11)
if(DEFINED ENV{CXXSTD})
set(CXXSTD $ENV{CXXSTD})
endif()
set(CMAKE_CXX_STANDARD ${CXXSTD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DARWIN_C_SOURCE")
endif()
# Google Test
set(GTEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/googletest/googletest/)
set(GTEST_INCLUDE_DIR ${GTEST_ROOT}/include)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
set(gtest_force_shared_crt ON CACHE BOOL
"Use shared (DLL) run-time lib even when Google Test is built as static lib.")
endif()
add_subdirectory(${GTEST_ROOT} EXCLUDE_FROM_ALL)
add_library(GTest::GTest ALIAS gtest)
add_library(GTest::Main ALIAS gtest_main)
# Add all tests as dependencies to "tests" so the coverage target can
# depend on them.
add_custom_target(tests)
enable_testing()
# PEGTL
set(PEGTL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/pegtl)
set(PEGTL_INCLUDE_DIR ${PEGTL_ROOT}/include)
set(PEGTL_BUILD_TESTS OFF CACHE BOOL "")
add_subdirectory(${PEGTL_ROOT} EXCLUDE_FROM_ALL)
# Rang
set(RANG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/rang)
set(RANG_INCLUDE_DIR ${RANG_ROOT}/include)
# CLI11
set(CLI11_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/CLI11)
set(CLI11_INCLUDE_DIR ${CLI11_ROOT}/include)
# Spdlog
set(SPDLOG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/spdlog)
set(SPDLOG_INCLUDE_DIR ${SPDLOG_ROOT}/include)
# json
set(JSON_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/json)
set(JSON_INCLUDE_DIR ${JSON_ROOT}/include)
set(TAOCPP_JSON_BUILD_TESTS OFF CACHE BOOL "")
add_subdirectory(${JSON_ROOT} EXCLUDE_FROM_ALL)
# CodeCoverage
include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
if(CMAKE_BUILD_TYPE MATCHES Debug)
option(COVERAGE "Create coverage data")
if(COVERAGE)
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
set(COVERAGE_EXCLUDES '*/3rdparty/*' '*/usr/*' '*/nix/store/*')
SETUP_TARGET_FOR_COVERAGE(
NAME coverage
EXECUTABLE ctest
DEPENDENCIES tests
)
SETUP_TARGET_FOR_COVERAGE_HTML(
NAME coverage-html
EXECUTABLE ctest
DEPENDENCIES tests
)
SETUP_TARGET_FOR_COVERAGE_COBERTURA(
NAME coverage-data
EXECUTABLE ctest
DEPENDENCIES tests
)
endif(COVERAGE)
endif(CMAKE_BUILD_TYPE MATCHES Debug)
# Doxygen
find_package(Doxygen)
option(BUILD_DOC "Create and install documentation (requires Doxygen)" ${DOXYGEN_FOUND})
if(BUILD_DOC)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/neopg-tool/Doxyfile.in)
set(DOXYFILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYFILE_IN} ${DOXYFILE} @ONLY)
message("Doxygen build started")
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Doxygen"
VERBATIM)
# install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
endif()
find_package(PkgConfig)
pkg_check_modules(sqlite REQUIRED IMPORTED_TARGET sqlite3)
pkg_check_modules(botan-2 REQUIRED IMPORTED_TARGET botan-2)
pkg_check_modules(libusb-1.0 REQUIRED IMPORTED_TARGET libusb-1.0)
pkg_check_modules(gnutls REQUIRED IMPORTED_TARGET gnutls)
find_package(Boost COMPONENTS locale date_time REQUIRED)
find_package(CURL REQUIRED)
find_package(Threads)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/neopg-tool/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
add_subdirectory(neopg)
add_subdirectory(legacy)
add_subdirectory(neopg-tool)
install(EXPORT neopg NAMESPACE neopg:: DESTINATION lib/cmake/neopg)
# get all project files
file(GLOB_RECURSE ALL_SOURCE_FILES
${CMAKE_SOURCE_DIR}/legacy/*.cpp
${CMAKE_SOURCE_DIR}/legacy/*.h
${CMAKE_SOURCE_DIR}/include/*.cpp
${CMAKE_SOURCE_DIR}/include/*.h
${CMAKE_SOURCE_DIR}/lib/*.cpp
${CMAKE_SOURCE_DIR}/lib/*.h
${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/src/*.h
${CMAKE_SOURCE_DIR}/tests/*.cpp
${CMAKE_SOURCE_DIR}/tests/*.h
)
# additional target to perform cppcheck run, requires cppcheck
add_custom_target(
lint
COMMAND cppcheck
--enable=warning,performance,portability,information,missingInclude
--std=c++11
--language=c++
--verbose
--quiet
${ALL_SOURCE_FILES}
)
# additional target to perform clang-format run, requires clang-format
find_program(CLANG_FORMAT NAMES clang-format-4.0 clang-format)
add_custom_target(
pretty
COMMAND ${CLANG_FORMAT} --version
COMMAND ${CLANG_FORMAT} -style=file -i ${ALL_SOURCE_FILES}
)