-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
251 lines (227 loc) · 9.01 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
# Copy: (c) 2023 blurryroots innovation qanat OÜ
# Author: sven freiberg
# .
cmake_minimum_required(VERSION 3.16)
# .
set(TARGET_NAME Eddy)
project(${TARGET_NAME})
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
if(LINUX)
endif()
# Add the application project.
add_subdirectory(Qt)
# Define the directory holding the refined build files.
set(RELEASE_TARGET_DIR "${PROJECT_SOURCE_DIR}/Release")
# Defined root directory based on qt cmake path.
set(QT_ROOT ${Qt5_DIR}/../../..)
# .
add_custom_target(${TARGET_NAME}_Prepare_Release_Dir ALL
DEPENDS ${TARGET_NAME}
COMMAND ${CMAKE_COMMAND} -E make_directory
${RELEASE_TARGET_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory
${RELEASE_TARGET_DIR}/Candidate
)
# .
if(MSVC)
# .
set(EXE_NAME "${TARGET_NAME}.exe")
set(LIB_EXT "dll")
set(RELEASE_CANDIDATE_EXE ${RELEASE_TARGET_DIR}/${EXE_NAME})
# Gather system dependencies.
set(WINSYS32 "C:/Windows/System32")
add_custom_target(${TARGET_NAME}_Deploy_Native_Dependencies_WIN ALL
DEPENDS ${TARGET_NAME}_Prepare_Release_Dir
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${WINSYS32}/concrt140.dll" "${RELEASE_TARGET_DIR}/concrt140.dll"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${WINSYS32}/vccorlib140.dll" "${RELEASE_TARGET_DIR}/vccorlib140.dll"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${WINSYS32}/msvcp140.dll" "${RELEASE_TARGET_DIR}/msvcp140.dll"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${WINSYS32}/vcruntime140.dll" "${RELEASE_TARGET_DIR}/vcruntime140.dll"
COMMAND ${CMAKE_COMMAND}
-DSRC_PATH=${EDDY_BUILD_PATH}
-DDST_PATH=${RELEASE_TARGET_DIR}
-DPATTERN=*.${LIB_EXT}
-P ${PROJECT_SOURCE_DIR}/CMake/CopyRecursiveCmd.cmake
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${EDDY_BUILD_PATH}/${EXE_NAME}
${RELEASE_CANDIDATE_EXE}
VERBATIM
)
# Locate windeployqt, which should come with qt installtion.
find_program(WINDEPLOYQT windeployqt HINTS "${_qt_bin_dir}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(WINDEPLOYQT_ARGS --pdb --debug --compiler-runtime)
else()
set(WINDEPLOYQT_ARGS --release --compiler-runtime)
endif()
set(DEPLOY_CMD ${WINDEPLOYQT} ${WINDEPLOYQT_ARGS} ${EXE_NAME})
message(STATUS "Preparing DEPLOY_CMD: ${DEPLOY_CMD}")
# Deploy qt dependencies.
add_custom_target(${TARGET_NAME}_Deploy_QT_Dependencies_WIN ALL
DEPENDS ${TARGET_NAME}_Deploy_Native_Dependencies_WIN
WORKING_DIRECTORY ${RELEASE_TARGET_DIR}
COMMAND ${DEPLOY_CMD}
VERBATIM
)
add_custom_target(${TARGET_NAME}_Compile_Release_Candidate
DEPENDS ${TARGET_NAME}_Deploy_QT_Dependencies_WIN
WORKING_DIRECTORY ${RELEASE_TARGET_DIR}
COMMAND echo "Compiling ..."
VERBATIM
)
elseif(LINUX)
# .
set(EXE_NAME "${TARGET_NAME}")
set(LIB_EXT "so")
set(QT_DEPLOY_TOOL_EXE linuxdeployqt-continuous-x86_64.AppImage)
set(QT_DEPLOY_BASE_URL https://github.com/probonopd/linuxdeployqt/releases)
set(QT_DEPLOY_TOOL_URL ${QT_DEPLOY_BASE_URL}/download/continuous/${QT_DEPLOY_TOOL_EXE})
set(QT_DEPLOY_TOOL_PATH ${PROJECT_SOURCE_DIR}/Tools/${QT_DEPLOY_TOOL_EXE})
message(STATUS "Downloading qt deploy for linux from: ${QT_DEPLOY_URL}")
include(FetchContent)
FetchContent_Declare(
QT_DEPLOY_TOOL_FETCH
URL ${QT_DEPLOY_TOOL_URL}
URL_HASH MD5=d84f43f29c4f038f0cc2aefda2ee2c5c
DOWNLOAD_NO_EXTRACT TRUE
DOWNLOAD_DIR ${PROJECT_SOURCE_DIR}/Tools
)
FetchContent_MakeAvailable(QT_DEPLOY_TOOL_FETCH)
message(STATUS "Available at: ${QT_DEPLOY_TOOL_PATH}")
# Collect relevant build artefacts and put them into a FHS structure.
# https://github.com/probonopd/linuxdeployqt/issues/237#issuecomment-472721609
add_custom_target(${TARGET_NAME}_Prepare_FSH_Structure
DEPENDS ${TARGET_NAME}
WORKING_DIRECTORY ${RELEASE_TARGET_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory
usr/bin
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${EDDY_BUILD_PATH}/${EXE_NAME}"
usr/bin/${EXE_NAME}
COMMAND ${CMAKE_COMMAND} -E make_directory
usr/share/icons/hicolor
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${PROJECT_SOURCE_DIR}/Raw/Linux/${TARGET_NAME}.desktop"
usr/share/${TARGET_NAME}.desktop
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${PROJECT_SOURCE_DIR}/Raw/Linux/${TARGET_NAME}.png"
usr/share/icons/hicolor/512x512/${TARGET_NAME}.png
COMMAND ${CMAKE_COMMAND} -E make_directory
usr/lib
COMMAND ${CMAKE_COMMAND}
-DSRC_PATH=${EDDY_BUILD_PATH}
-DDST_PATH=${RELEASE_TARGET_DIR}/usr/lib
-DPATTERN=*.so
-P ${PROJECT_SOURCE_DIR}/CMake/CopyRecursiveCmd.cmake
)
# Compile arguments for deploy command.
set(DYNLIBS_TO_DEPLOY "")
file(GLOB DYNLIBS
${RELEASE_TARGET_DIR}/usr/lib/*.so
)
foreach(DL IN LISTS ${DYNLIBS})
set(DYNLIBS_TO_DEPLOY "${DYNLIBS_TO_DEPLOY} -executable=${DL}")
endforeach()
# Create deploy command.
set(QT_DEPLOYLINUXCMD ${QT_DEPLOY_TOOL_PATH}
${DYNLIBS_TO_DEPLOY}
usr/share/${TARGET_NAME}.desktop
-appimage
-extra-plugins=iconengines,platformthemes/libqgtk3.so
-qmake=${QT_ROOT}/bin/qmake
-no-translations
-no-strip
)
# Define release candidate output.
set(RELEASE_CANDIDATE_EXE
${RELEASE_TARGET_DIR}/Candidate/${TARGET_NAME}.AppImage
)
# Use linuxdeployqt to generate appimage.
add_custom_target(${TARGET_NAME}_Compile_Release_Candidate
DEPENDS ${TARGET_NAME}_Prepare_FSH_Structure
WORKING_DIRECTORY ${RELEASE_TARGET_DIR}
# Qt root, output file path, linuxdeployqt command
COMMAND ${PROJECT_SOURCE_DIR}/Tools/./build-appimage.sh
${QT_ROOT}
${RELEASE_TARGET_DIR}
${RELEASE_CANDIDATE_EXE}
${QT_DEPLOYLINUXCMD}
BYPRODUCTS ${RELEASE_CANDIDATE_EXE}
VERBATIM
)
elseif(APPLE)
# .
set(EXE_NAME "${TARGET_NAME}")
set(LIB_EXT "dylib")
option(GENERATE_DMG "Whether to package the app bundle in dmg container." FALSE)
if (NOT GENERATE_DMG)
message(WARNING "No dmg option specified. Opting for GENERATE_DMG=FALSE.")
set(GENERATE_DMG FALSE)
else()
message(WARNING "GENERATE_DMG: ${GENERATE_DMG}")
endif()
# Fetch relevant build artefacts.
add_custom_target(${TARGET_NAME}_Deploy_Build ALL
DEPENDS ${TARGET_NAME}_Prepare_Release_Dir
COMMAND ${CMAKE_COMMAND}
-DSRC_PATH=${EDDY_BUILD_PATH}
-DDST_PATH=${RELEASE_TARGET_DIR}
-DPATTERN=*.${LIB_EXT}
-P ${PROJECT_SOURCE_DIR}/CMake/CopyRecursiveCmd.cmake
COMMAND ${CMAKE_COMMAND}
-DSRC_PATH=${EDDY_BUILD_PATH}/${TARGET_NAME}.app
-DDST_PATH=${RELEASE_TARGET_DIR}/${TARGET_NAME}.app
-DPATTERN=*
-P ${PROJECT_SOURCE_DIR}/CMake/CopyRecursiveCmd.cmake
VERBATIM
)
# Locate windeployqt, which should come with qt installtion.
set(MACDEPLOYQT "${QT_ROOT}/bin/macdeployqt")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(MACDEPLOYQT_ARGS "-libpath=${RELEASE_TARGET_DIR} -no-strip -use-debug-libs")
message(STATUS "MACDEPLOYQT_ARGS: ${MACDEPLOYQT_ARGS}")
else()
set(MACDEPLOYQT_ARGS -libpath=${RELEASE_TARGET_DIR})
endif()
if(GENERATE_DMG)
set(MACDEPLOYQT_ARGS ${MACDEPLOYQT_ARGS} -dmg)
endif()
# Deploy qt dependencies.
add_custom_target(${TARGET_NAME}_Deploy_QT_Dependencies_MAC ALL
DEPENDS ${TARGET_NAME}_Deploy_Build
WORKING_DIRECTORY ${RELEASE_TARGET_DIR}
COMMAND ${MACDEPLOYQT}
${EXE_NAME}.app
${MACDEPLOYQT_ARGS}
VERBATIM
)
set(RELEASE_CANDIDATE_NAME "${TARGET_NAME}.app/*")
if(GENERATE_DMG)
set(RELEASE_CANDIDATE_NAME "${TARGET_NAME}.dmg")
endif()
set(RELEASE_CANDIDATE_EXE
${RELEASE_TARGET_DIR}/Candidate/${RELEASE_CANDIDATE_NAME}
)
add_custom_target(${TARGET_NAME}_Compile_Release_Candidate
DEPENDS ${TARGET_NAME}_Deploy_QT_Dependencies_MAC
COMMAND ${CMAKE_COMMAND}
-DSRC_PATH=${RELEASE_TARGET_DIR}
-DDST_PATH=${RELEASE_TARGET_DIR}/Candidate/
-DPATTERN=${RELEASE_CANDIDATE_NAME}
-P ${PROJECT_SOURCE_DIR}/CMake/CopyRecursiveCmd.cmake
VERBATIM
)
else()
message(FATAL_ERROR "Unsupported OS")
endif()
# Convenice target for running (raw) build files directly.
add_custom_target(${TARGET_NAME}_Run
DEPENDS ${TARGET_NAME}
COMMAND ${RELEASE_CANDIDATE_EXE}
VERBATIM
)