-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
350 lines (305 loc) · 14 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
#################################################################################################################################################
# Mdt top level configuration file
#################################################################################################################################################
cmake_minimum_required(VERSION 3.2)
project(Mdt0 VERSION 0.3.7)
# Additionnal Cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
#################################################################################################################################################
# Common setup
#################################################################################################################################################
# Those must be set before including Mdt modules
set(CPACK_PACKAGE_CONTACT "Philippe Steinmann <[email protected]>") # TODO Check if set outside (see cpack options)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Mdt is a utilities library")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_NSIS_COMPONENT_INSTALL ON)
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
# Specify where to find Qt
# If Qt5 is not installed on a system known location,
# or you want to use a specific version,
# or you are on Windows, QT_PREFIX_PATH should be specified
if(QT_PREFIX_PATH)
list(APPEND CMAKE_PREFIX_PATH "${QT_PREFIX_PATH}")
endif()
message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")
message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
message("CMAKE_HOST_SYSTEM_PROCESSOR: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message("CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
find_package(Qt5 COMPONENTS Core)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
# On Windows, RPATH do not exist
# To be able to run tests, we have to put all binaries in the same directory
# We also tell CMake to use Wine to execute tests if we cross-compiled
if(WIN32)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
if(CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING_EMULATOR wine)
endif()
endif()
# Enable testing
# Must be placed before any add_subdirectory() command, else tests that are defined in sub-directories will be ignored
enable_testing()
#################################################################################################################################################
# Compiler options
#################################################################################################################################################
# C++ standard
set(CMAKE_CXX_STANDARD 14)
# Build C++ flags adding those set in cache file
set(CMAKE_CXX_FLAGS "${MDT_CXX_FLAGS_TO_PREPEND} ${CMAKE_CXX_FLAGS} ${MDT_CXX_FLAGS_TO_APPEND}")
# On UNIX, we allways add debug symbols (will be stripped and put into separate .dbg files)
if(UNIX)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
add_compile_options(-g)
endif()
endif(UNIX)
# Thread support
find_package(Threads REQUIRED)
#################################################################################################################################################
# Additionnal CMake modules
#################################################################################################################################################
# List of targeted translations
# This is used by MdtAddTranslations.cmake module
set(TRANSLATION_LANGUAGES en fr de)
include(MdtAddLibraryTranslations)
include(MdtAddLibrary)
#################################################################################################################################################
# Install options ( Note: some options needs to be set before add_subdirectory() )
#################################################################################################################################################
get_filename_component(install_prefix "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)
# Generate the post-install script
# This will change the RPATH on the user's target platform
if( NOT ("${install_prefix}" STREQUAL "/usr") )
configure_file(
"${CMAKE_SOURCE_DIR}/MdtPostInstall.cmake.in"
"${CMAKE_BINARY_DIR}/MdtPostInstall.cmake"
@ONLY
)
install(
FILES "${CMAKE_BINARY_DIR}/MdtPostInstall.cmake"
DESTINATION "." COMPONENT dev
)
endif()
#################################################################################################################################################
# Licenses
#################################################################################################################################################
# For system wide installation,
# installing licenses files is specific to the Linux distribution .
if( NOT ("${install_prefix}" STREQUAL "/usr") )
install(
FILES "${CMAKE_SOURCE_DIR}/LICENSE"
DESTINATION "."
)
endif()
#################################################################################################################################################
# Libraries
#################################################################################################################################################
add_subdirectory(libs/QtSolutions)
add_subdirectory(libs/Error_Core)
add_subdirectory(libs/Error_Widgets)
add_subdirectory(libs/Application_Core)
add_subdirectory(libs/Application_Core_Single)
add_subdirectory(libs/Application_Widgets)
add_subdirectory(libs/Application_Widgets_Single)
add_subdirectory(libs/Algorithm)
add_subdirectory(libs/Expected)
add_subdirectory(libs/FilterExpression)
add_subdirectory(libs/Numeric)
add_subdirectory(libs/PlainText_Core)
add_subdirectory(libs/ItemModel)
# # add_subdirectory(libs/SerialPort)
# add_subdirectory(libs/Sql)
# add_subdirectory(libs/ItemEditor)
# add_subdirectory(libs/ItemEditor_Sql)
add_subdirectory(libs/TestLib_Core)
add_subdirectory(libs/FileSystem_Core)
add_subdirectory(libs/DeployUtils_Core)
add_subdirectory(libs/Translation_Core)
add_subdirectory(libs/Translation_Widgets)
# include(MdtInstallQt5)
#################################################################################################################################################
# Tools and Helpers
#################################################################################################################################################
add_subdirectory(tools)
add_subdirectory(cmake)
#################################################################################################################################################
# Icons
#################################################################################################################################################
# add_subdirectory(icons)
#################################################################################################################################################
# Unit tests
#################################################################################################################################################
# On Windows, we have to copy external libraries to the test runtime directory
# On Windows we have the following situation
#
# We are on a Windows machine, using Qt provided build suite,
# and the related script that setups PATH accordingly.
# In this case, nothing special to do.
#
# We are cross-compiling for Windows from a Linux machine using MXE.
# In this case, Qt libraries and mingw libraries are not in the PATH.
# We have to find depepndencies of the unit tests and copy them into the bin directory.
# Note: it is probably possible to create a temporary environnment,
# but doing the current way has the positive side effect
# to check if dependencies tools works.
# Those tools will be used later for binary distrubutions.
if(WIN32 AND CMAKE_RUNTIME_OUTPUT_DIRECTORY AND CMAKE_CROSSCOMPILING)
include(MdtDependenciesUtils)
# Because I not found a proper way to get a list of all existing tests,
# just put some of them that have the most dependencies.
mdt_copy_binary_dependencies(
TARGETS mdtitemmodel_filterproxymodeltest mdtdeployutils_librarytest mdtplaintext_csvparsertest mdterror_errortest
LIBRARY_DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
PLUGIN_DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
SEARCH_FIRST_PATH_PREFIX_LIST ${CMAKE_PREFIX_PATH}
)
# mdt_copy_binary_dependencies(
# TARGET QtSingleApplication
# DESTINATION_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
# NO_WARNINGS
# )
# mdt_copy_binary_dependencies(
# TARGET Application
# DESTINATION_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
# NO_WARNINGS
# )
# mdt_copy_binary_dependencies(
# TARGET mdterrortest
# DESTINATION_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
# NO_WARNINGS
# )
# mdt_copy_binary_dependencies(
# TARGET mdterror_widgetstest
# DESTINATION_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
# NO_WARNINGS
# )
# mdt_copy_binary_dependencies(
# TARGET mdtitemeditor_sqlcontrollertest
# DESTINATION_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
# NO_WARNINGS
# )
# mdt_copy_binary_dependencies_experimental(
# TARGET QtSingleApplication
# DESTINATION_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
# SEARCH_FIRST_PATH_PREFIX_LIST ${CMAKE_PREFIX_PATH}
# )
# mdt_copy_binary_dependencies_experimental(
# TARGET Application
# DESTINATION_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
# SEARCH_FIRST_PATH_PREFIX_LIST ${CMAKE_PREFIX_PATH}
# )
# mdt_copy_binary_dependencies_experimental(
# TARGET mdterrortest
# DESTINATION_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
# SEARCH_FIRST_PATH_PREFIX_LIST ${CMAKE_PREFIX_PATH}
# )
# If we are doing cross-compilation,
# recusrsive resolving do not work
# We have to add manually libraries that are missing
# if(CMAKE_CROSSCOMPILING AND MINGW)
# mdt_find_and_copy_libraries(
# LIBRARIES
# libpcre2-16-0 zlib1 libeay32 ssleay32 libharfbuzz-0 libpng16-16 libfreetype-6 libglib-2.0-0
# libbz2 libintl-8 libpcre-1 libiconv-2
# DESTINATION_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
# )
# endif()
endif()
#################################################################################################################################################
# Top level package configuration files
#################################################################################################################################################
# Top level Mdt<major-version>Config.cmake
# This permits the user to call, for example, find_package(Mdt<major-version> COMPONENTS ItemModel Sql)
# Will generate Mdt<major-version>Config.cmake at install time
# and install it to <install-prefix>/lib/cmake/Mdt<major-version>/
include(CMakePackageConfigHelpers)
configure_package_config_file(
MdtConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
COMPONENT ${PROJECT_NAME}
)
# Top level Mdt<major-version>ConfigVersion.cmake
# This permits the user to call, for example, find_package(Mdt<major-version> 0.1 COMPONENTS ItemModel Sql)
# Will generate Mdt<major-version>ConfigVersion.cmake at install time
# and install it to <install-prefix>/lib/cmake/Mdt<major-version>/
# NOTE: Mdt0 is experimental and will allways break between version
# Major version compatibility should be provided starting Mdt1
# (When true, pass COMPATIBILITY SameMajorVersion as argument)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY ExactVersion
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
COMPONENT ${PROJECT_NAME}
)
#################################################################################################################################################
# CPack
#################################################################################################################################################
set(CPACK_SOURCE_IGNORE_FILES
"${CMAKE_BINARY_DIR}"
"build"
"\.#"
".DS_Store*"
"ehthumbs.db"
"Icon?"
"Thumbs.db"
".directory"
"$.log^"
"$.tmp^"
"CMakeFiles"
"CTest."
"Makefile"
"cmake_install.cmake"
)
if(UNIX)
set(CPACK_GENERATOR TBZ2)
set(CPACK_SOURCE_GENERATOR TBZ2)
endif()
if(WIN32)
# set(CPACK_GENERATOR NSIS)
set(CPACK_SOURCE_GENERATOR ZIP)
endif()
# Make properties defined for CPack availabe as variables in current scope
get_cmake_property(components COMPONENTS)
foreach(component ${components})
get_property(
CPACK_COMPONENT_${component}_DESCRIPTION
GLOBAL
PROPERTY CPACK_COMPONENT_${component}_DESCRIPTION
)
if(UNIX)
string(TOUPPER ${component} component_upper)
get_property(
CPACK_COMPONENT_${component_upper}_DESCRIPTION
GLOBAL
PROPERTY CPACK_COMPONENT_${component_upper}_DESCRIPTION
)
endif()
endforeach()
# Detect compile architecture
# See: https://stackoverflow.com/questions/11944060/how-to-detect-target-architecture-using-cmake
# Thanks to: https://github.com/axr/solar-cmake
include(TargetArch)
target_architecture(COMPILE_ARCHITECTURE)
message("COMPILE_ARCHITECTURE: ${COMPILE_ARCHITECTURE}")
# Get Qt5 version
# After success, find_package() wil define Qt5_VERSION, Qt5_VERSION_MAJOR, etc..
find_package(Qt5 COMPONENTS Core)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
message("DEBUG build")
set(debug_file_name_postfix "-debug")
else()
set(debug_file_name_postfix "")
endif()
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-Qt-${Qt5_VERSION_MAJOR}.${Qt5_VERSION_MINOR}-${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-${COMPILE_ARCHITECTURE}${debug_file_name_postfix}")
include(CPack)