-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
180 lines (147 loc) Β· 8.27 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
#
# QaterialGallery CMake script by Olivier Le Doeuff
#
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# β CMAKE PROPERTIES β
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# β PROJECT SETTINGS β
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
set(QATERIALGALLERY_PROJECT "QaterialGallery" CACHE STRING "Qaterial Gallery Project Name")
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# β VERSION β
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Project version must be set here
set(QATERIALGALLERY_VERSION_MAJOR 1)
set(QATERIALGALLERY_VERSION_MINOR 4)
set(QATERIALGALLERY_VERSION_PATCH 2)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE QATERIALGALLERY_VERSION_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if(NOT QATERIALGALLERY_VERSION_TAG)
set(QATERIALGALLERY_VERSION_TAG 00000000)
endif()
set(QATERIALGALLERY_VERSION_TAG_HEX 0x${QATERIALGALLERY_VERSION_TAG})
set(QATERIALGALLERY_VERSION_TAG ${QATERIALGALLERY_VERSION_TAG} CACHE STRING "Git Tag of Qaterial")
set(QATERIALGALLERY_VERSION ${QATERIALGALLERY_VERSION_MAJOR}.${QATERIALGALLERY_VERSION_MINOR}.${QATERIALGALLERY_VERSION_PATCH})
project(${QATERIALGALLERY_PROJECT} VERSION ${QATERIALGALLERY_VERSION} LANGUAGES CXX)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(QATERIALGALLERY_TARGET ${QATERIALGALLERY_PROJECT} CACHE STRING "Qaterial Gallery Target Name")
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
set(QATERIALGALLERY_BUILD_SHARED ON CACHE BOOL "Build as a shared library (Default for Android build)" FORCE)
else()
set(QATERIALGALLERY_BUILD_SHARED OFF CACHE BOOL "Build as a shared library")
endif()
set(QATERIALGALLERY_BUILD_STATIC OFF CACHE BOOL "Build as a static library")
set(QATERIALGALLERY_IGNORE_ENV OFF CACHE BOOL "The executable will discard system qt, and will try to use qt binary deploy along the target. Should be ON when deploying installer")
set(QATERIALGALLERY_ENABLE_PCH ON CACHE BOOL
"Enable precompile headers support for 'QaterialGallery'. \"
Only work if CMake support 'target_precompile_headers'. \"
This can speed up compilation time.")
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# β DEPENDENCIES β
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
find_package(Qt5 REQUIRED COMPONENTS
Core
Qml
Gui
Quick
QuickControls2
Svg
Xml
QuickCompiler
)
find_package(Qt5 QUIET COMPONENTS QmlWorkerScript)
include(cmake/Dependencies.cmake)
include(cmake/FetchSpdlog.cmake)
include(cmake/FetchQaterial.cmake)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# β STATUS β
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# βββ GLOBAL ββββ
message(STATUS "------ ${QATERIALGALLERY_TARGET} v${QATERIALGALLERY_VERSION} Configuration ------")
message(STATUS "QATERIALGALLERY_BUILD_SHARED : ${QATERIALGALLERY_BUILD_SHARED}")
message(STATUS "QATERIALGALLERY_BUILD_STATIC : ${QATERIALGALLERY_BUILD_STATIC}")
message(STATUS "QATERIALGALLERY_IGNORE_ENV : ${QATERIALGALLERY_IGNORE_ENV}")
message(STATUS "------ ${QATERIALGALLERY_TARGET} End Configuration ------")
# ββββ CHECK CONFLICT ββββ
if(QATERIALGALLERY_BUILD_SHARED AND QATERIALGALLERY_BUILD_STATIC)
message(FATAL_ERROR "QaterialGallery can't compile shared and static library at the same time")
endif()
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# β SOURCES β
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
qt_generate_qmldir(QATERIALGALLERY_QMLDIR_FILE
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qml/QaterialGallery
MODULE "QaterialGallery")
qt_generate_qrc(QATERIALGALLERY_QML_QRC
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qml/QaterialGallery
DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/QaterialGalleryGenerated
NAME QaterialGallery.qrc
PREFIX "QaterialGallery"
GLOB_EXPRESSION "*.qml;qmldir"
RECURSE)
qt_generate_qrc(QATERIALGALLERY_RES_QML_QRC
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qml/QaterialGallery
DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/QaterialGalleryGenerated
NAME QaterialGalleryRes.qrc
PREFIX "QaterialGallery"
GLOB_EXPRESSION "*.png;*svg"
RECURSE)
qtquick_compiler_add_resources(QATERIALGALLERY_QML_RES ${QATERIALGALLERY_QML_QRC})
file(GLOB_RECURSE QATERIALGALLERY_QML_SRCS qml/QaterialGallery/*.qml)
source_group("Qml" FILES "${QATERIALGALLERY_QML_SRCS}")
set(QATERIALGALLERY_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp
${QATERIALGALLERY_QML_RES}
${QATERIALGALLERY_RES_QML_QRC}
)
# Dont Run Moc on cpp file generated from qml
foreach(GENERATED_RES ${QATERIALGALLERY_QML_RES})
set_property(SOURCE ${GENERATED_RES} PROPERTY SKIP_AUTOMOC ON)
source_group("QtQuickCompiler Files" FILES ${GENERATED_RES})
endforeach()
# ββββ TARGET ββββ
if(QATERIALGALLERY_BUILD_SHARED)
add_library(${QATERIALGALLERY_TARGET} SHARED ${QATERIALGALLERY_SRCS})
target_compile_definitions(${QATERIALGALLERY_TARGET} PRIVATE -DQATERIALGALLERY_SHARED)
else()
if(QATERIALGALLERY_BUILD_STATIC)
add_library(${QATERIALGALLERY_TARGET} STATIC ${QATERIALGALLERY_SRCS})
else()
add_executable(${QATERIALGALLERY_TARGET} ${QATERIALGALLERY_SRCS})
endif()
target_compile_definitions(${QATERIALGALLERY_TARGET} PUBLIC -DQATERIALGALLERY_STATIC)
endif()
# ββββ SETTINGS ββββ
target_compile_features(${QATERIALGALLERY_TARGET} PUBLIC cxx_std_11)
if(QATERIALGALLERY_IGNORE_ENV)
message(STATUS "The executable will discard every ")
target_compile_definitions(${QATERIALGALLERY_TARGET} PRIVATE -DQATERIALGALLERY_IGNORE_ENV)
endif()
# ββββ DEPENDENCIES ββββ
set_target_properties(${QATERIALGALLERY_TARGET} PROPERTIES
AUTOMOC TRUE
AUTORCC TRUE)
target_link_libraries(${QATERIALGALLERY_TARGET} PRIVATE
Qaterial
spdlog
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
Qt::QuickControls2
Qt::Svg
Qt::Widgets
)
target_compile_definitions(${QATERIALGALLERY_TARGET} PRIVATE
-DQATERIALGALLERY_VERSION="${QATERIALGALLERY_VERSION}"
)
# ββββββββββ POST BUILD PLATFORM DEPENDANCIES βββββββββββββ
include(platforms/Deploy.cmake)