-
Notifications
You must be signed in to change notification settings - Fork 160
/
CMakeLists.txt
241 lines (192 loc) · 7.78 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
cmake_minimum_required(VERSION 3.16)
set(QTKEYCHAIN_VERSION 0.14.99)
set(QTKEYCHAIN_SOVERSION 1)
project(qtkeychain VERSION ${QTKEYCHAIN_VERSION} LANGUAGES CXX)
# Enable C++11
SET(CMAKE_CXX_STANDARD 11)
include(FindPkgConfig)
###
# write binaries and libraries into a shared folder, this simplifies the execution of tests on Windows
# see https://github.com/KDE/extra-cmake-modules/blob/b3a13868f7f54ab0b7ac19fd26b6dfead8907d25/kde-modules/KDECMakeSettings.cmake#L256C1-L258C69
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")
include(GNUInstallDirs)
include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
include(ECMSetupVersion)
include(ECMGeneratePriFile)
include(CMakeDependentOption)
option(BUILD_WITH_QT6 "Build qtkeychain with Qt 6" OFF)
option(BUILD_TEST_APPLICATION "Build test application" OFF)
option(BUILD_TRANSLATIONS "Build translations" ON)
option(BUILD_SHARED_LIBS "Build dynamic library" ON)
if(QTKEYCHAIN_STATIC)
set(BUILD_SHARED_LIBS OFF)
message(WARNING "QTKEYCHAIN_STATIC is deprecated. Use BUILD_SHARED_LIBS=OFF instead.")
endif()
CMAKE_DEPENDENT_OPTION(BUILD_TRANSLATIONS_AS_RESOURCES "Bundle translations with the library" OFF
"BUILD_TRANSLATIONS" OFF)
if(CMAKE_SYSTEM_NAME STREQUAL Android)
set(ANDROID 1)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Haiku)
set(HAIKU 1)
endif()
if (WIN32)
option(USE_CREDENTIAL_STORE "Build with windows CredentialStore support" ON)
if (USE_CREDENTIAL_STORE)
add_definitions(-DUSE_CREDENTIAL_STORE=1)
endif()
endif()
if( NOT BUILD_WITH_QT6 )
find_package(Qt5 COMPONENTS Core REQUIRED)
endif()
if (Qt5Core_FOUND AND NOT BUILD_WITH_QT6)
set(QTKEYCHAIN_VERSION_INFIX 5)
if(ANDROID)
if(Qt5Core_VERSION VERSION_LESS 5.7)
find_package(Qt5 COMPONENTS Core REQUIRED Private)
include_directories(${Qt5Core_PRIVATE_INCLUDE_DIRS})
endif()
find_package(Qt5 COMPONENTS AndroidExtras REQUIRED)
include_directories(${Qt5AndroidExtras_INCLUDE_DIRS})
set(QTANDROIDEXTRAS_LIBRARIES ${Qt5AndroidExtras_LIBRARIES})
endif()
if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT HAIKU)
find_package(Qt5 COMPONENTS DBus REQUIRED)
include_directories(${Qt5DBus_INCLUDE_DIRS})
set(QTDBUS_LIBRARIES ${Qt5DBus_LIBRARIES})
macro(qt_add_dbus_interface)
qt5_add_dbus_interface(${ARGN})
endmacro()
endif()
if(BUILD_TRANSLATIONS)
find_package(Qt5 COMPONENTS LinguistTools REQUIRED)
macro(qt_add_translation)
qt5_add_translation(${ARGN})
endmacro(qt_add_translation)
macro(qt_create_translation)
qt5_create_translation(${ARGN})
endmacro(qt_create_translation)
endif()
macro(qt_wrap_cpp)
qt5_wrap_cpp(${ARGN})
endmacro()
set(QTCORE_LIBRARIES ${Qt5Core_LIBRARIES})
include_directories(${Qt5Core_INCLUDE_DIRS})
else()
find_package(Qt6 COMPONENTS Core REQUIRED)
set(QTKEYCHAIN_VERSION_INFIX 6)
if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT HAIKU)
find_package(Qt6 COMPONENTS DBus REQUIRED)
include_directories(${Qt6DBus_INCLUDE_DIRS})
set(QTDBUS_LIBRARIES ${Qt6DBus_LIBRARIES})
macro(qt_add_dbus_interface)
qt6_add_dbus_interface(${ARGN})
endmacro()
endif()
if(BUILD_TRANSLATIONS)
find_package(Qt6 COMPONENTS LinguistTools REQUIRED)
macro(qt_add_translation)
qt6_add_translation(${ARGN})
endmacro(qt_add_translation)
macro(qt_create_translation)
qt6_create_translation(${ARGN})
endmacro(qt_create_translation)
endif()
macro(qt_wrap_cpp)
qt6_wrap_cpp(${ARGN})
endmacro()
set(QTCORE_LIBRARIES ${Qt6Core_LIBRARIES})
endif()
set(QTKEYCHAIN_TARGET_NAME qt${QTKEYCHAIN_VERSION_INFIX}keychain)
add_subdirectory(qtkeychain)
###
### Translations
###
set(qtkeychain_TR_FILES
translations/qtkeychain_de.ts
translations/qtkeychain_fr.ts
translations/qtkeychain_ro.ts
translations/qtkeychain_ru.ts
translations/qtkeychain_zh.ts
)
file(GLOB qtkeychain_TR_SOURCES qtkeychain/*.cpp qtkeychain/*.h qtkeychain/*.ui)
if ( BUILD_TRANSLATIONS )
qt_create_translation(qtkeychain_MESSAGES ${qtkeychain_TR_SOURCES} ${qtkeychain_TR_FILES})
qt_add_translation(qtkeychain_QM_FILES ${qtkeychain_TR_FILES})
add_custom_target(messages DEPENDS ${qtkeychain_MESSAGES})
add_custom_target(translations DEPENDS ${qtkeychain_QM_FILES} messages)
# https://github.com/frankosterfeld/qtkeychain/issues/185
add_dependencies(${QTKEYCHAIN_TARGET_NAME} translations)
if (BUILD_TRANSLATIONS_AS_RESOURCES)
set(QM_FILE_LIST "")
foreach(FILE ${qtkeychain_QM_FILES})
list(APPEND QM_FILE_LIST "<file>${FILE}</file>")
endforeach()
string(REPLACE ";" "" QM_FILE_LIST ${QM_FILE_LIST})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/translations/translations.qrc.in ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc)
target_sources(${QTKEYCHAIN_TARGET_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc)
else()
if(QTKEYCHAIN_VERSION_INFIX EQUAL 5 AND QT_TRANSLATIONS_DIR AND NOT QTKEYCHAIN_TRANSLATIONS_DIR)
# Back compatibility with pre-0.11 versions
message (WARNING "QT_TRANSLATIONS_DIR is deprecated, use QTKEYCHAIN_TRANSLATIONS_DIR instead")
set(QTKEYCHAIN_TRANSLATIONS_DIR ${QT_TRANSLATIONS_DIR}
CACHE PATH "The location of the QtKeychain translations" FORCE)
else()
set(QTKEYCHAIN_TRANSLATIONS_DIR
${CMAKE_INSTALL_DATADIR}/qt${QTKEYCHAIN_VERSION_INFIX}keychain/translations
CACHE PATH "The location of the QtKeychain translations" )
endif()
install(FILES ${qtkeychain_QM_FILES} DESTINATION ${QTKEYCHAIN_TRANSLATIONS_DIR})
endif()
endif( BUILD_TRANSLATIONS )
###
### Test application ("testclient")
###
if(BUILD_TEST_APPLICATION)
set( testclient_LIBRARIES ${QTKEYCHAIN_TARGET_NAME} )
if(APPLE)
list(APPEND testclient_LIBRARIES "-framework Cocoa")
if (BUILD_WITH_QT6)
find_package(Qt6 COMPONENTS Gui REQUIRED)
list(APPEND testclient_LIBRARIES Qt6::Gui)
else()
find_package(Qt5 COMPONENTS Gui REQUIRED)
list(APPEND testclient_LIBRARIES Qt5::Gui)
endif()
endif()
add_executable( testclient testclient.cpp )
target_link_libraries( testclient ${testclient_LIBRARIES})
endif()
include(CTest)
if(BUILD_TESTING)
add_subdirectory(autotest)
endif()
###
### CMake config file
###
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/QtKeychainConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/Qt${QTKEYCHAIN_VERSION_INFIX}KeychainConfig.cmake"
INSTALL_DESTINATION Qt${QTKEYCHAIN_VERSION_INFIX}Keychain)
ecm_setup_version("${QTKEYCHAIN_VERSION}" VARIABLE_PREFIX SNORE
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/Qt${QTKEYCHAIN_VERSION_INFIX}KeychainConfigVersion.cmake"
SOVERSION ${QTKEYCHAIN_VERSION})
if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT HAIKU)
set(PRI_EXTRA_DEPS "dbus")
endif()
ecm_generate_pri_file(BASE_NAME Qt${QTKEYCHAIN_VERSION_INFIX}Keychain
LIB_NAME ${QTKEYCHAIN_TARGET_NAME}
DEPS "core ${PRI_EXTRA_DEPS}"
INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}
FILENAME_VAR pri_filename)
install(FILES ${pri_filename} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
install(EXPORT Qt${QTKEYCHAIN_VERSION_INFIX}KeychainLibraryDepends
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Qt${QTKEYCHAIN_VERSION_INFIX}Keychain"
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Qt${QTKEYCHAIN_VERSION_INFIX}KeychainConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/Qt${QTKEYCHAIN_VERSION_INFIX}KeychainConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Qt${QTKEYCHAIN_VERSION_INFIX}Keychain
)