-
Notifications
You must be signed in to change notification settings - Fork 528
/
CMakeLists.txt
232 lines (187 loc) · 6.53 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
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project (Unlocker)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/modules)
SET(UNLOCKER_STATIC_LIBS_WIN ON CACHE BOOL "Links statically") # Set to OFF for dynamic linking
IF (MSVC)
# prevent default manifest from being linked
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /MANIFEST:NO")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO")
ENDIF(MSVC)
find_package(ZLIB REQUIRED)
if(ZLIB_FOUND)
message (STATUS "ZLib found, version ${ZLIB_VERSION_STRING}")
endif()
find_package(CURL REQUIRED)
if(CURL_FOUND)
message (STATUS "Curl found, version ${CURL_VERSION_STRING}")
endif()
find_package(LibZip REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${LIBZIP_INCLUDE_DIRS})
if(LIBZIP_FOUND)
message (STATUS "LibZip found")
endif()
# main include files
include_directories ("${PROJECT_SOURCE_DIR}/include")
# main source files
set (SOURCE_FILES /
src/versionparser.cpp /
src/buildsparser.cpp /
src/archive.cpp /
src/network.cpp /
src/debug.cpp /
src/installinfo.cpp /
src/patcher.cpp /
src/tar.cpp /
src/main.cpp /
src/ziparchive.cpp /
src/toolsdownloader.cpp /
src/logging/combinedlogstrategy.cpp /
src/logging/terminallogstrategy.cpp /
src/logging/streamlogstrategy.cpp /
src/logging/logstrategy.cpp /
src/patchversioner.cpp /
)
if(WIN32)
set (SOURCE_FILES ${SOURCE_FILES} /
src/unlocker_win.cpp /
src/winservices.cpp /
src/win32/mainwindow.cpp /
src/win32/controls/button.cpp /
src/win32/controls/editbox.cpp /
src/win32/controls/window.cpp /
src/win32/controls/control.cpp /
src/win32/controls/label.cpp /
src/win32/controls/progress.cpp /
src/win32/controls/groupbox.cpp /
src/win32/controls/checkbox.cpp /
src/win32/controls/statusbar.cpp /
src/win32/patchertask.cpp /
src/win32/unpatchertask.cpp /
src/win32/downloadtoolstask.cpp /
src/logging/statusbarlogstrategy.cpp /
)
else()
set (SOURCE_FILES ${SOURCE_FILES} /
src/unlocker_lnx.cpp /
)
endif()
IF (MSVC)
IF (UNLOCKER_STATIC_LIBS_WIN)
# Preprocessor definitions needed to avoid name mangling when statically importing libs on MSVC compiler
# Name mangling is needed if libraries are built dynamically with MSVC
# Should not be an issue with other compilers
add_compile_definitions( "CURL_STATICLIB" )
ENDIF()
ENDIF (MSVC)
if(WIN32)
add_executable(Unlocker WIN32 ${SOURCE_FILES})
else()
add_executable(Unlocker ${SOURCE_FILES})
endif()
# Support skipping file offsets when tar contains files larger than ~2 Gig
target_compile_definitions(Unlocker PUBLIC _FILE_OFFSET_BITS=64)
set_target_properties(Unlocker PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON)
target_link_libraries (Unlocker ${ZLIB_LIBRARIES})
target_link_libraries (Unlocker ${CURL_LIBRARIES})
target_link_libraries (Unlocker ${LIBZIP_LIBRARY})
if(WIN32)
target_link_libraries (Unlocker ws2_32 Wldap32 ComCtl32.lib Shlwapi.lib)
endif()
# Amend manifest to tell Windows that the app needs admin privileges
IF (MSVC)
IF (CMAKE_MAJOR_VERSION LESS 3)
MESSAGE(WARNING "CMake version 3.0 or newer is required use build variable TARGET_FILE")
ELSE()
ADD_CUSTOM_COMMAND(
TARGET Unlocker
POST_BUILD
COMMAND "mt.exe" -manifest \"${PROJECT_SOURCE_DIR}/Unlocker.exe.manifest\" -outputresource:\"$<TARGET_FILE:Unlocker>\"\;\#1
COMMENT "Embedding manifest..."
)
ENDIF()
ENDIF(MSVC)
# Main test
# Tests need to be fixed to use the GUI-based functions
#[[
set (TEST_SOURCES tests/test_patch.cpp /
src/debug.cpp /
src/patcher.cpp /
src/network.cpp /
src/versionparser.cpp /
src/buildsparser.cpp /
src/archive.cpp /
src/installinfo.cpp /
src/winservices.cpp /
src/tar.cpp /
src/unlocker.cpp /
src/ziparchive.cpp /
src/toolsdownloader.cpp)
add_executable( TestPatch ${TEST_SOURCES})
target_compile_definitions(TestPatch PUBLIC _FILE_OFFSET_BITS=64)
include_directories(TestPatch ${ZLIB_INCLUDE_DIRS})
include_directories(TestPatch ${CURL_INCLUDE_DIRS})
include_directories(TestPatch ${LIBZIP_INCLUDE_DIRS})
target_link_libraries (TestPatch ${ZLIB_LIBRARIES})
target_link_libraries (TestPatch ${CURL_LIBRARIES})
target_link_libraries (TestPatch ${LIBZIP_LIBRARY})
if(WIN32)
target_link_libraries (TestPatch ws2_32 Wldap32)
endif()
set_target_properties( TestPatch PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON)
enable_testing()
add_test(NAME TestPatchTest COMMAND TestPatch "${PROJECT_SOURCE_DIR}")
#]]
# Tar test
set (TESTTAR_SOURCES tests/test_tar.cpp /
src/debug.cpp /
src/patcher.cpp /
src/versionparser.cpp /
src/buildsparser.cpp /
src/archive.cpp /
src/installinfo.cpp /
src/network.cpp /
src/tar.cpp /
src/ziparchive.cpp)
add_executable( TestTar ${TESTTAR_SOURCES} "include/unlocker_lnx.h")
target_compile_definitions(TestTar PUBLIC _FILE_OFFSET_BITS=64)
include_directories(TestTar ${ZLIB_INCLUDE_DIRS})
include_directories(TestTar ${CURL_INCLUDE_DIRS})
include_directories(TestTar ${LIBZIP_INCLUDE_DIRS})
target_link_libraries (TestTar ${ZLIB_LIBRARIES})
target_link_libraries (TestTar ${CURL_LIBRARIES})
target_link_libraries (TestTar ${LIBZIP_LIBRARY})
if(WIN32)
target_link_libraries (TestTar ws2_32 Wldap32)
endif()
set_target_properties( TestTar PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON)
enable_testing()
add_test(NAME TestTarTest COMMAND TestTar "${PROJECT_SOURCE_DIR}")
# Zip test
set (TESTZIP_SOURCES tests/test_zip.cpp /
src/debug.cpp /
src/patcher.cpp /
src/versionparser.cpp /
src/buildsparser.cpp /
src/archive.cpp /
src/installinfo.cpp /
src/network.cpp /
src/tar.cpp /
src/ziparchive.cpp /
src/toolsdownloader.cpp)
add_executable( TestZip ${TESTZIP_SOURCES} "include/unlocker_lnx.h")
target_compile_definitions(TestZip PUBLIC _FILE_OFFSET_BITS=64)
include_directories(TestZip ${ZLIB_INCLUDE_DIRS})
include_directories(TestZip ${CURL_INCLUDE_DIRS})
include_directories(TestZip ${LIBZIP_INCLUDE_DIRS})
target_link_libraries (TestZip ${ZLIB_LIBRARIES})
target_link_libraries (TestZip ${CURL_LIBRARIES})
target_link_libraries (TestZip ${LIBZIP_LIBRARY})
if(WIN32)
target_link_libraries (TestZip ws2_32 Wldap32)
endif()
set_target_properties( TestZip PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ON)
enable_testing()
add_test(NAME TestZipTest COMMAND TestZip "${PROJECT_SOURCE_DIR}")