forked from CoatiSoftware/Sourcetrail
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathCMakeLists.txt
414 lines (383 loc) · 16.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#${CMAKE_SOURCE_DIR}/CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
include(cmake/version.cmake)
project(
Sourcetrail
DESCRIPTION "interactive source explorer"
VERSION ${VERSION_STRING}
HOMEPAGE_URL "opensourcesourcetrail.github.io"
LANGUAGES C CXX)
#---------------------------------------------------------------------------------------------------------------------------------
set(BUILD_CXX_LANGUAGE_PACKAGE
OFF
CACHE BOOL "Add C and C++ support to the Sourcetrail indexer.")
set(BUILD_DOC
OFF
CACHE BOOL "Build documentation.")
set(ENABLE_UNIT_TEST
OFF
CACHE BOOL "Build unit-tests.")
set(ENABLE_GUI_TEST
OFF
CACHE BOOL "Build gui-tests.")
set(ENABLE_INTEGRATION_TEST
OFF
CACHE BOOL "Build integration-tests.")
set(ENABLE_SANITIZER_ADDRESS
OFF
CACHE BOOL "Inject address sanitizer.")
set(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
OFF
CACHE BOOL "Inject undefined behavior sanitizer.")
set(ENABLE_SANITIZER_THREAD CACHE BOOL "Inject thread sanitizer. `not supported`")
set(ENABLE_SANITIZER_MEMORY
OFF
CACHE BOOL "Inject memory sanitizer. `not supported`")
set(ENABLE_COVERAGE
OFF
CACHE BOOL "Build coverage report run `ninja coverage`.")
set(ENABLE_BUILD_WITH_TIME_TRACE
OFF
CACHE BOOL "Trace building time.")
set(SOURCETRAIL_CMAKE_VERBOSE
OFF
CACHE BOOL "CMake verbose")
set(SOURCETRAIL_WARNING_AS_ERROR
OFF
CACHE BOOL "Treat warnings as errors")
set(SOURCETRAIL_USE_LIBCPP
OFF
CACHE BOOL "Use libc++ instead of libstdc++")
set(GCOV_VERSION
"gcov-12"
CACHE STRING "Version of gcov")
#---------------------------------------------------------------------------------------------------------------------------------
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
#---------------------------------------------------------------------------------------------------------------------------------
include(cmake/add_files.cmake)
include(cmake/version_setup.cmake)
include(cmake/licenses.cmake)
include(cmake/create_symlink.cmake)
include(cmake/add_sourcetrail_library.cmake)
include(cmake/add_sourcetrail_interface.cmake)
include(cmake/add_sourcetrail_test.cmake)
include(cmake/clang-tidy.cmake)
include(cmake/cppcheck.cmake)
include(cmake/coverage.cmake)
#---------------------------------------------------------------------------------------------------------------------------------
if(ENABLE_SANITIZER_ADDRESS
OR ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
OR ENABLE_SANITIZER_THREAD
OR ENABLE_SANITIZER_MEMORY)
include(cmake/sanitizers.cmake)
endif()
#---------------------------------------------------------------------------------------------------------------------------------
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
add_compile_options(-fcolor-diagnostics)
if(SOURCETRAIL_USE_LIBCPP)
add_compile_options(-stdlib=libc++)
add_link_options(-stdlib=libc++)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
endif()
#---------------------------------------------------------------------------------------------------------------------------------
include(cmake/set_alternate_linker.cmake)
set(USE_ALTERNATE_LINKER
""
CACHE STRING "Use alternate linker. Leave empty for system default; alternatives are 'gold', 'lld', 'bfd', 'mold'")
if(NOT
"${USE_ALTERNATE_LINKER}"
STREQUAL
"")
set_alternate_linker(${USE_ALTERNATE_LINKER})
endif()
#---------------------------------------------------------------------------------------------------------------------------------
include(cmake/compiler_warnings.cmake)
#---------------------------------------------------------------------------------------------------------------------------------
if(BUILD_DOC)
include(cmake/doxygen.cmake)
endif()
# Variables ----------------------------------------------------------------------------------------------------------------------
if(WIN32)
set(PLATFORM_INCLUDE "includesWindows.h")
elseif(APPLE)
set(PLATFORM_INCLUDE "includesMac.h")
else()
set(PLATFORM_INCLUDE "includesLinux.h")
endif()
set(BASH "")
if(WIN32)
execute_process(COMMAND CMD /c where bash OUTPUT_VARIABLE BASH)
string(
REGEX
REPLACE "\n$"
""
BASH
"${BASH}")
if(SOURCETRAIL_CMAKE_VERBOSE)
message("bash: '${BASH}'")
endif()
endif()
# Project ------------------------------------------------------------------------------------------------------------------------
set(PROJECT_NAME Sourcetrail)
#RPATH
if(UNIX AND NOT APPLE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib/:$$ORIGIN/lib/")
endif()
# Settings -----------------------------------------------------------------------------------------------------------------------
find_package(expected-lite REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(range-v3 CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(SQLite3 CONFIG REQUIRED)
# Boost --------------------------------------------------------------------------------------------------------------------------
set(Boost_USE_MULTITHREAD ON)
set(Boost_USE_STATIC_LIBS
ON
CACHE BOOL "Set to ON to force the use of the static libraries.")
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(
Boost 1.83
COMPONENTS date_time
filesystem
program_options
system
REQUIRED)
# Qt -----------------------------------------------------------------------------------------------------------------------------
set(QT_MIN_VERSION "5.15.0")
set(QT_MIN_VERSION_HEX 0x051500)
find_package(
Qt5 ${QT_MIN_VERSION}
COMPONENTS Widgets
PrintSupport
Network
Svg
REQUIRED)
if(WIN32)
find_package(
Qt5 ${QT_MIN_VERSION}
COMPONENTS WinExtras
REQUIRED)
endif()
if(Qt5Widgets_FOUND)
if(SOURCETRAIL_CMAKE_VERBOSE)
message(STATUS "Found Qt ${Qt5Widgets_VERSION_STRING}")
endif()
# FIX: Qt was built with -reduce-relocations
if(Qt5_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
add_definitions(-DQT_DEPRECATED_WARNINGS)
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=${QT_MIN_VERSION_HEX} # disables all the APIs deprecated at or before the specified Qt version
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=${QT_MIN_VERSION_HEX})
endif()
# Setup --------------------------------------------------------------------------------------------------------------------------
if(WIN32)
include(cmake/copy_qt_binaries.cmake)
endif()
if(ENABLE_UNIT_TEST OR ENABLE_INTEGRATION_TEST)
enable_testing()
find_package(GTest CONFIG REQUIRED)
include(GoogleTest)
add_library(gtest_main ./tests/gtest_main.cpp)
add_library(Sourcetrail::gtest_main ALIAS gtest_main)
target_link_libraries(
gtest_main
PUBLIC GTest::gmock
GTest::gtest
spdlog::spdlog
Sourcetrail::core::utility::utilityString
Sourcetrail::core::utility::TextCodec)
endif()
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_PREFIX_LEN)
add_subdirectory(src/external)
add_subdirectory(src/lib)
add_subdirectory(src/lib_gui)
#---------------------------------------------------------------------------------------------------------------------------------
add_subdirectory(src/core)
add_subdirectory(src/scheduling)
add_subdirectory(src/messaging)
add_subdirectory(src/lib_gui/utility/utilityApp)
# Lib Cxx ------------------------------------------------------------------------------------------------------------------------
if(BUILD_CXX_LANGUAGE_PACKAGE)
add_subdirectory(src/lib_cxx)
endif()
# Lib ----------------------------------------------------------------------------------------------------------------------------
add_library(Sourcetrail_lib ${LIB_FILES})
add_library(Sourcetrail::lib ALIAS Sourcetrail_lib)
target_include_directories(
Sourcetrail_lib
PUBLIC ${LIB_INCLUDE_PATHS}
${LIB_GUI_INCLUDE_PATHS}
${CMAKE_SOURCE_DIR}/src/lib_gui/utility/
${CMAKE_SOURCE_DIR}/src/lib_gui/utility/path_detector/
${CMAKE_BINARY_DIR}/src/lib)
target_link_libraries(
Sourcetrail_lib
PUBLIC Sourcetrail::messaging
Sourcetrail::core::utility::ConfigManager
Sourcetrail::core::utility::LowMemoryStringMap
Sourcetrail::core::utility::Status
Sourcetrail::core::utility::Tree
Sourcetrail::core::utility::utility
Sourcetrail::core::utility::Migration
Sourcetrail::core::utility::Migrator
Sourcetrail::core::utility::file::FilePath
Sourcetrail::core::utility::file::FilePathFilter
Sourcetrail::core::utility::toUnderlying
Sourcetrail::scheduling
CppSQLite::CppSQLite3
nonstd::expected-lite
PRIVATE Sourcetrail::core
Sourcetrail::core::utility::ConfigManager
Sourcetrail::core::utility::logging
Sourcetrail::core::utility::ScopedFunctor
Sourcetrail::core::utility::Status
Sourcetrail::core::utility::TextAccess
Sourcetrail::core::utility::TextCodec
Sourcetrail::core::utility::utilityUuid
Sourcetrail::lib_gui
Sourcetrail::libGui::utility::utilityApp
Sourcetrail::core::utility::file::FileSystem
Sourcetrail::core::utility::file::utilityFile
Sourcetrail::core::utility::file::FileManager
$<$<BOOL:${BUILD_CXX_LANGUAGE_PACKAGE}>:Sourcetrail::lib_cxx>
Boost::filesystem
Boost::program_options
Boost::system
SQLite::SQLite3
$<$<PLATFORM_ID:Windows>:bcrypt>)
#configure language package defines
configure_file("${CMAKE_SOURCE_DIR}/cmake/language_packages.h.in" "${CMAKE_BINARY_DIR}/src/lib/language_packages.h")
# Lib gui_utility ----------------------------------------------------------------------------------------------------------------
add_library(Sourcetrail_lib_gui_utility)
add_library(Sourcetrail::lib_gui::utility ALIAS Sourcetrail_lib_gui_utility)
target_sources(
Sourcetrail_lib_gui_utility
PRIVATE src/lib_gui/utility/utilityPathDetection.cpp src/lib_gui/utility/path_detector/CombinedPathDetector.cpp
src/lib_gui/utility/path_detector/PathDetector.cpp)
target_include_directories(Sourcetrail_lib_gui_utility PUBLIC src/lib_gui/utility/ src/lib_gui/utility/path_detector/
src/lib_gui/utility/path_detector/cxx_header/)
target_link_libraries(
Sourcetrail_lib_gui_utility
PUBLIC Sourcetrail::core::utility::ApplicationArchitectureType Sourcetrail::core::utility::OsType
PRIVATE Boost::system
Qt5::Core
Sourcetrail::core
Sourcetrail::lib
Sourcetrail::core::utility::ScopedFunctor
Sourcetrail::core::utility::logging
Sourcetrail::libGui::utility::utilityApp)
# Lib Gui ------------------------------------------------------------------------------------------------------------------------
# target for running versionnumber script
# workaround for running customcommand (ninja dependency cycle)
add_custom_target(versionnumber ALL)
# Lib Gui ------------------------------------------------------------------------------------------------------------------------
add_library(Sourcetrail_lib_gui ${LIB_GUI_FILES} bin/resources.qrc ${CMAKE_BINARY_DIR}/src/lib_gui/productVersion.h)
add_library(Sourcetrail::lib_gui ALIAS Sourcetrail_lib_gui)
target_link_libraries(
Sourcetrail_lib_gui
PUBLIC Sourcetrail::lib
Qt5::Widgets
Qt5::Network
Qt5::Svg
Sourcetrail::core::utility::SingleValueCache
Sourcetrail::core::utility::LowMemoryStringMap
Sourcetrail::core::utility::Migrator
Sourcetrail::core::utility::file::FilePathFilter
Sourcetrail::core::utility::file::FileSystem
Sourcetrail::libGui::utility::utilityApp
$<$<PLATFORM_ID:Windows>:Qt5::WinExtras>
PRIVATE Sourcetrail::core
Sourcetrail::core::utility::logging
Sourcetrail::core::utility::OrderedCache
Sourcetrail::core::utility::ScopedFunctor
Sourcetrail::core::utility::Status
Sourcetrail::core::utility::TextAccess
Sourcetrail::core::utility::TextCodec
Sourcetrail::core::utility::toUnderlying
Sourcetrail::core::utility::utility
Sourcetrail::core::utility::utilityUuid
Sourcetrail::core::utility::file::utilityFile
Sourcetrail::core::utility::file::FilePath
Sourcetrail::core::utility::file::FileManager
Sourcetrail::lib_gui::utility
Sourcetrail::libGui::utility::utilityApp
Sourcetrail::messaging
$<$<BOOL:${BUILD_CXX_LANGUAGE_PACKAGE}>:Sourcetrail::lib_cxx>)
# command for versioning script
add_custom_command(
TARGET versionnumber
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -DBINARY_DIR=${CMAKE_BINARY_DIR} -P ${CMAKE_SOURCE_DIR}/cmake/version.cmake
BYPRODUCTS ${CMAKE_BINARY_DIR}/src/lib_gui/productVersion.h DEPENDS Sourcetrail_lib_gui
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "check/update version number")
add_dependencies(Sourcetrail_lib_gui versionnumber)
target_include_directories(
Sourcetrail_lib_gui
PUBLIC ${LIB_GUI_INCLUDE_PATHS}
${LIB_INCLUDE_PATHS}
${CMAKE_BINARY_DIR}/src/lib_gui
${CMAKE_BINARY_DIR}/src/lib)
# configure platform specific include file
configure_file("${PROJECT_SOURCE_DIR}/src/lib_gui/platform_includes/includes.h.in"
"${PROJECT_BINARY_DIR}/src/lib_gui/includes.h")
#configure the versioning file
configure_file(${CMAKE_SOURCE_DIR}/cmake/productVersion.h.in ${CMAKE_BINARY_DIR}/src/lib_gui/productVersion.h)
set_target_properties(
Sourcetrail_lib_gui
PROPERTIES AUTOMOC ON
AUTORCC ON
INCLUDE_CURRENT_DIR ON)
set_property(SOURCE ${CMAKE_BINARY_DIR}/src/lib_gui/productVersion.h PROPERTY SKIP_AUTOMOC ON)
# Indexer App --------------------------------------------------------------------------------------------------------------------
add_subdirectory(src/indexer)
# App ----------------------------------------------------------------------------------------------------------------------------
add_subdirectory(src/app)
# Tests --------------------------------------------------------------------------------------------------------------------------
if(ENABLE_UNIT_TEST
OR ENABLE_GUI_TEST
OR ENABLE_INTEGRATION_TEST)
if(WIN32 AND NOT ${SR_IS_CI})
copy_qt_binaries("${CMAKE_BINARY_DIR}/test" FALSE)
endif()
execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "make_directory" "${CMAKE_BINARY_DIR}/test")
create_symlink("${CMAKE_SOURCE_DIR}/bin/test/data" "${CMAKE_BINARY_DIR}/test/data")
find_package(
Qt5 ${QT_MIN_VERSION}
COMPONENTS Test Sql
REQUIRED)
if(ENABLE_UNIT_TEST)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/lib/tests/)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/lib_gui/tests/)
if(BUILD_CXX_LANGUAGE_PACKAGE)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/lib_cxx/tests/)
endif()
endif()
if(ENABLE_INTEGRATION_TEST)
add_subdirectory(tests)
endif()
endif()
# Assets -------------------------------------------------------------------------------------------------------------------------
execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "make_directory" "${CMAKE_BINARY_DIR}/app")
create_symlink("${CMAKE_SOURCE_DIR}/bin/app/data" "${CMAKE_BINARY_DIR}/app/data")
create_symlink("${CMAKE_SOURCE_DIR}/bin/app/user" "${CMAKE_BINARY_DIR}/app/user")
# Packaging ----------------------------------------------------------------------------------------------------------------------
# TODO(SOUR-104)