-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
132 lines (108 loc) · 3.89 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
# This file is part of KDToolBars.
#
# SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <[email protected]> for commercial licensing options.
#
cmake_minimum_required(VERSION 3.15)
project(KDToolBars VERSION 0.1.0)
include(FeatureSummary)
include(GNUInstallDirs)
option(KDToolBars_QT6 "Build against Qt 6" OFF)
option(KDToolBars_TESTS "Build tests" ON)
option(KDToolBars_STATIC "Build statically" OFF)
option(KDToolBars_DOCS "Build the API documentation" OFF)
option(KDToolBars_EXAMPLES "Build examples" ON)
option(KDToolBars_DEVELOPER_MODE "Developer Mode" OFF)
option(KDToolBars_WERROR "Compile with -Werror" OFF)
option(KDToolBars_ENABLE_SANITIZERS "Compile with ASAN and UBSAN" OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/ECM/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/KDAB/modules")
# Set a default build type if none was specified
set(default_build_type "Release")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git" OR KDToolBars_DEVELOPER_MODE)
set(default_build_type "Debug")
endif()
if(KDToolBars_ENABLE_SANITIZERS)
# For CI usage, but feel free to add MSVC support
add_compile_options(-fsanitize=address -fsanitize=undefined)
add_link_options(-fsanitize=address -fsanitize=undefined)
endif()
if(KDToolBars_DEVELOPER_MODE)
set(KDToolBars_WERROR ON)
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to ${default_build_type} as none was specified.")
set(CMAKE_BUILD_TYPE
"${default_build_type}"
CACHE STRING "Choose the type of build." FORCE
)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
if(KDToolBars_QT6)
set(QT_VERSION_MAJOR 6)
set(KDTOOLBARS_LIBRARY_QTID "-qt6")
else()
set(QT_VERSION_MAJOR 5)
set(KDTOOLBARS_LIBRARY_QTID "")
endif()
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Widgets
REQUIRED
)
include(KDQtInstallPaths) # to set QT_INSTALL_FOO variables
# Always build the test harness in developer-mode
if(KDToolBars_DEVELOPER_MODE)
set(KDToolBars_TESTS ON)
endif()
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(KDToolBars_IS_ROOT_PROJECT TRUE)
message(STATUS "Building KDToolBars ${KDToolBars_VERSION} in ${CMAKE_BUILD_TYPE} mode. "
"Installing to ${CMAKE_INSTALL_PREFIX}"
)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
else()
# Always disable tests, examples, docs when used as a submodule
set(KDToolBars_IS_ROOT_PROJECT FALSE)
set(KDToolBars_TESTS FALSE)
set(KDToolBars_EXAMPLES FALSE)
set(KDToolBars_DOCS FALSE)
endif()
if(KDToolBars_STATIC)
set(KDTOOLBARS_LIBRARY_MODE "STATIC")
else()
set(KDTOOLBARS_LIBRARY_MODE "SHARED")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
# Default to hidden visibility for symbols
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
add_subdirectory(src)
if(KDToolBars_EXAMPLES)
add_subdirectory(examples)
endif()
if(KDToolBars_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if(KDToolBars_DOCS)
add_subdirectory(docs) # needs to go last, in case there are build source files
endif()
if(KDToolBars_IS_ROOT_PROJECT)
# Add uninstall target (not for submodules since parent projects typically have uninstall too)
include(ECMUninstallTarget)
endif()
if(KDToolBars_IS_ROOT_PROJECT)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
endif()