forked from Nilsen84/lunar-client-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
163 lines (123 loc) · 4.75 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
cmake_minimum_required(VERSION 3.21)
project(lunar-client-qt LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
# ----------------------- Options -------------------------
option(USE_QT6 "Use Qt 6 instead of Qt 5" OFF)
option(INCLUDE_UPDATER "Include update checker" ON)
if(USE_QT6)
set(QT_VER Qt6)
else()
set(QT_VER Qt5)
endif()
# ---------------------------- Get current version and tag --------------------------------
set(LCQT_VERSION Unknown)
set(LCQT_VERSION_TAG Unknown)
find_package(Git)
if(Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --match "v[0-9]*"
OUTPUT_VARIABLE tag
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
if(tag MATCHES "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)")
set(LCQT_VERSION ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3})
set(LCQT_VERSION_TAG v${LCQT_VERSION})
message(STATUS "Found version tag: ${LCQT_VERSION_TAG}")
else()
message(WARNING "Couldn't find latest version tag, disabling update checker.")
set(INCLUDE_UPDATER Off)
endif()
else()
message(WARNING "Couldn't find git, disabling update checker.")
set(INCLUDE_UPDATER Off)
endif()
# ----------------------- Parse json config file -----------------------------
file(READ ${CMAKE_CURRENT_LIST_DIR}/config.json CONFIG)
macro(CONFIG_VAR KEY OUTPUT_VAR)
string(JSON ${OUTPUT_VAR} GET ${CONFIG} ${KEY})
endmacro()
config_var("agentsDestDir" AGENTS_DEST_DIR)
config_var("githubReleaseApiLink" GITHUB_RELEASE_LINK)
# ----------------------- Replace values in cpp file -----------------------------
configure_file(${CMAKE_SOURCE_DIR}/buildconfig.cpp.in ${CMAKE_BINARY_DIR}/buildconfig.cpp @ONLY)
set(VERSION_FILE ${CMAKE_BINARY_DIR}/buildconfig.cpp)
# ----------------------- Sources ------------------------
set(SOURCE_FILES
src/main.cpp
src/gui/mainwindow.cpp
src/gui/mainwindow.h
src/launch/offlinelauncher.cpp
src/launch/offlinelauncher.h
src/gui/pages/generalpage.cpp
src/gui/pages/generalpage.h
src/gui/pages/configurationpage.h
src/gui/pages/agentspage.cpp
src/gui/pages/agentspage.h
src/launch/launcher.h
src/launch/launcher.cpp
src/config/config.cpp
src/config/config.h
src/gui/pages/minecraftpage.cpp
src/gui/pages/minecraftpage.h
src/gui/widgets/filechooser.cpp
src/gui/widgets/filechooser.h
src/gui/widgets/widgetutils.cpp
src/gui/widgets/widgetutils.h
src/buildconfig.h
src/gui/agents/agentsmodel.cpp
src/gui/agents/agentsmodel.h
src/gui/agents/agentsview.cpp
src/gui/agents/agentsview.h
src/gui/style/removeoutline.cpp
src/gui/style/removeoutline.h
src/util/fs.cpp src/util/fs.h
src/util/utils.cpp
src/util/utils.h
src/util/sysinfo.cpp
src/util/sysinfo.h
)
set(UPDATER_SOURCES src/updater/updatechecker.cpp src/updater/updatechecker.h)
if(INCLUDE_UPDATER)
list(APPEND SOURCE_FILES ${UPDATER_SOURCES})
endif()
# ------------------------- Dependencies --------------------------
set(QT_COMPONENTS Core Gui Widgets Svg)
if(INCLUDE_UPDATER)
list(APPEND QT_COMPONENTS Network)
endif()
find_package(${QT_VER} COMPONENTS ${QT_COMPONENTS} REQUIRED)
# ----------------------------- Executable --------------------------------------
add_executable(lunar-client-qt WIN32 MACOSX_BUNDLE ${SOURCE_FILES} ${VERSION_FILE} res.qrc)
# ----------------------------- Compile Definitions --------------------------------
if(INCLUDE_UPDATER)
target_compile_definitions(lunar-client-qt PRIVATE INCLUDE_UPDATER)
endif()
# ------------------------- Copy java agents -----------------------
if(UNIX AND APPLE)
set(JAR_DEST_DIR ${CMAKE_BINARY_DIR}/lunar-client-qt.app/Contents/MacOS)
else()
set(JAR_DEST_DIR ${CMAKE_BINARY_DIR})
endif()
macro(COPY_JARS S_DIR T_DIR)
add_custom_command(
TARGET lunar-client-qt
PRE_BUILD
COMMAND ${CMAKE_COMMAND}
-Dsrc_dir=${CMAKE_CURRENT_LIST_DIR}/java/${S_DIR}
-Ddst_dir=${JAR_DEST_DIR}/${T_DIR}
-P ${CMAKE_CURRENT_LIST_DIR}/cmake/copy_jars.cmake
COMMENT "Copying '${S_DIR}' to '${T_DIR}'"
VERBATIM
)
endmacro()
copy_jars(agents ${AGENTS_DEST_DIR})
# ----------------------- Link against libraries ------------------------------
add_subdirectory(3rdparty)
list(TRANSFORM QT_COMPONENTS PREPEND ${QT_VER}:: OUTPUT_VARIABLE QT_LIBS)
target_link_libraries(lunar-client-qt ${QT_LIBS} QuaZip::QuaZip)
# ---------------------- Set include directory ---------------------------
target_include_directories(lunar-client-qt PRIVATE src)