pxsteamdl 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +417 -0
- package/COPYING +674 -0
- package/COPYING.LESSER +165 -0
- package/README.md +282 -2
- package/cmake/CPM.cmake +28 -0
- package/cmake/MergeArchives.cmake +37 -0
- package/cmake/PxSteamDLConfig.cmake.in +18 -0
- package/cmake/PxSteamDLInstall.cmake +115 -0
- package/cmake/mbedtls/pxsteamdl_mbedtls_config.h +10 -0
- package/cmake/mbedtls/threading_alt.h +7 -0
- package/cmake/version.hpp.in +8 -0
- package/include/pxsteamdl/error.hpp +48 -0
- package/include/pxsteamdl/pxsteamdl.hpp +144 -0
- package/node/index.d.ts +103 -0
- package/node/index.js +104 -0
- package/node/install.js +40 -0
- package/node/prebuild.js +22 -0
- package/node/pxsteamdl.cpp +372 -0
- package/node/util.js +49 -0
- package/package.json +43 -4
- package/prebuilds/darwin-arm64/pxsteamdl-addon.node +0 -0
- package/prebuilds/linux-x64/pxsteamdl-addon.node +0 -0
- package/prebuilds/win32-x64/pxsteamdl-addon.node +0 -0
- package/src/cdn.cpp +62 -0
- package/src/cdn.hpp +61 -0
- package/src/chunk.cpp +104 -0
- package/src/chunk.hpp +14 -0
- package/src/client.cpp +126 -0
- package/src/cm_packet.cpp +153 -0
- package/src/cm_packet.hpp +52 -0
- package/src/common.hpp +74 -0
- package/src/crypto.cpp +61 -0
- package/src/crypto.hpp +25 -0
- package/src/directory_lock.cpp +183 -0
- package/src/directory_lock.hpp +26 -0
- package/src/directory_update.cpp +109 -0
- package/src/directory_update.hpp +40 -0
- package/src/downloader.cpp +506 -0
- package/src/downloader.hpp +65 -0
- package/src/eresult.cpp +162 -0
- package/src/eresult.hpp +86 -0
- package/src/error.cpp +28 -0
- package/src/http.cpp +137 -0
- package/src/http.hpp +50 -0
- package/src/manifest.cpp +243 -0
- package/src/manifest.hpp +56 -0
- package/src/paths.cpp +68 -0
- package/src/paths.hpp +30 -0
- package/src/pending_file.cpp +244 -0
- package/src/pending_file.hpp +59 -0
- package/src/proto.cpp +111 -0
- package/src/proto.hpp +58 -0
- package/src/retry.cpp +25 -0
- package/src/retry.hpp +36 -0
- package/src/session.cpp +464 -0
- package/src/session.hpp +42 -0
- package/src/sleep.cpp +21 -0
- package/src/sleep.hpp +13 -0
- package/src/version.cpp +8 -0
- package/src/workshop.cpp +154 -0
- package/src/workshop.hpp +36 -0
- package/src/zip.cpp +118 -0
- package/src/zip.hpp +12 -0
package/CMakeLists.txt
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.24)
|
|
2
|
+
project(PxSteamDL VERSION 0.5.0 LANGUAGES CXX)
|
|
3
|
+
|
|
4
|
+
option(PXSTEAMDL_BUILD_CLI "Build the pxsteamdl command-line tool" ${PROJECT_IS_TOP_LEVEL})
|
|
5
|
+
option(PXSTEAMDL_BUILD_PYTHON "Build the Python extension module" OFF)
|
|
6
|
+
option(PXSTEAMDL_BUILD_NODE "Build the Node.js addon (use cmake-js: npm install)" OFF)
|
|
7
|
+
option(PXSTEAMDL_BUILD_TESTS "Build the unit tests (GoogleTest)" OFF)
|
|
8
|
+
option(PXSTEAMDL_BUILD_EXAMPLES "Build the programs in examples/" OFF)
|
|
9
|
+
option(PXSTEAMDL_INSTALL "Generate install rules: headers, one library with its dependencies merged in, find_package files" ${PROJECT_IS_TOP_LEVEL})
|
|
10
|
+
|
|
11
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
12
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
13
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
14
|
+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
15
|
+
|
|
16
|
+
include(GNUInstallDirs)
|
|
17
|
+
|
|
18
|
+
# <pxsteamdl/version.hpp>, from the version above; the single source of the version (the Python package reads it too).
|
|
19
|
+
configure_file(cmake/version.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/pxsteamdl/version.hpp @ONLY)
|
|
20
|
+
|
|
21
|
+
# All dependencies are built from source as static libraries (the Python module links them too, hence PIC).
|
|
22
|
+
# CPM's find_package redirection is off: curl locates mbedTLS/zstd/zlib through the variables set below.
|
|
23
|
+
set(CPM_DONT_UPDATE_MODULE_PATH ON)
|
|
24
|
+
set(BUILD_SHARED_LIBS OFF)
|
|
25
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
26
|
+
include(cmake/CPM.cmake)
|
|
27
|
+
|
|
28
|
+
CPMAddPackage(
|
|
29
|
+
NAME nlohmann_json
|
|
30
|
+
VERSION 3.12.0
|
|
31
|
+
URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz
|
|
32
|
+
EXCLUDE_FROM_ALL YES
|
|
33
|
+
SYSTEM YES
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
if(PXSTEAMDL_BUILD_NODE AND WIN32)
|
|
37
|
+
# node.lib exports node.exe's own zlib (inflate, crc32, ...), which clashes with ours at link time: prefix ours.
|
|
38
|
+
add_compile_definitions(Z_PREFIX)
|
|
39
|
+
endif()
|
|
40
|
+
CPMAddPackage(
|
|
41
|
+
NAME zlib
|
|
42
|
+
VERSION 1.3.2
|
|
43
|
+
URL https://github.com/madler/zlib/releases/download/v1.3.2/zlib-1.3.2.tar.xz
|
|
44
|
+
URL_HASH SHA256=d7a0654783a4da529d1bb793b7ad9c3318020af77667bcae35f95d0e42a792f3
|
|
45
|
+
EXCLUDE_FROM_ALL YES
|
|
46
|
+
SYSTEM YES
|
|
47
|
+
OPTIONS "ZLIB_BUILD_SHARED OFF" "ZLIB_BUILD_TESTING OFF" "ZLIB_INSTALL OFF"
|
|
48
|
+
)
|
|
49
|
+
add_library(ZLIB::ZLIB ALIAS zlibstatic)
|
|
50
|
+
# Satisfies CMake's FindZLIB (used by curl) without searching the system.
|
|
51
|
+
set(ZLIB_INCLUDE_DIR ${zlib_SOURCE_DIR})
|
|
52
|
+
set(ZLIB_LIBRARY ZLIB::ZLIB)
|
|
53
|
+
|
|
54
|
+
CPMAddPackage(
|
|
55
|
+
NAME xz
|
|
56
|
+
VERSION 5.8.4
|
|
57
|
+
URL https://github.com/tukaani-project/xz/releases/download/v5.8.4/xz-5.8.4.tar.xz
|
|
58
|
+
URL_HASH SHA256=4ce24038fd4221e0d13bc1a2de7a4db56e90b92b3bf75321f6c14be73f65de4b
|
|
59
|
+
EXCLUDE_FROM_ALL YES
|
|
60
|
+
SYSTEM YES
|
|
61
|
+
OPTIONS
|
|
62
|
+
"XZ_NLS OFF"
|
|
63
|
+
"XZ_THREADS no"
|
|
64
|
+
"XZ_ENCODERS "
|
|
65
|
+
"XZ_DECODERS lzma1"
|
|
66
|
+
"XZ_MATCH_FINDERS "
|
|
67
|
+
"XZ_CHECKS crc32"
|
|
68
|
+
"XZ_LZIP_DECODER OFF"
|
|
69
|
+
"XZ_MICROLZMA_ENCODER OFF"
|
|
70
|
+
"XZ_MICROLZMA_DECODER OFF"
|
|
71
|
+
"XZ_DOC OFF"
|
|
72
|
+
"BUILD_TESTING OFF"
|
|
73
|
+
)
|
|
74
|
+
# xz exports its public headers only through the installed package config.
|
|
75
|
+
target_include_directories(liblzma SYSTEM INTERFACE $<BUILD_INTERFACE:${xz_SOURCE_DIR}/src/liblzma/api>)
|
|
76
|
+
|
|
77
|
+
CPMAddPackage(
|
|
78
|
+
NAME zstd
|
|
79
|
+
VERSION 1.5.7
|
|
80
|
+
URL https://github.com/facebook/zstd/releases/download/v1.5.7/zstd-1.5.7.tar.gz
|
|
81
|
+
URL_HASH SHA256=eb33e51f49a15e023950cd7825ca74a4a2b43db8354825ac24fc1b7ee09e6fa3
|
|
82
|
+
SOURCE_SUBDIR build/cmake
|
|
83
|
+
EXCLUDE_FROM_ALL YES
|
|
84
|
+
SYSTEM YES
|
|
85
|
+
OPTIONS
|
|
86
|
+
"ZSTD_BUILD_PROGRAMS OFF"
|
|
87
|
+
"ZSTD_BUILD_TESTS OFF"
|
|
88
|
+
"ZSTD_BUILD_SHARED OFF"
|
|
89
|
+
"ZSTD_BUILD_STATIC ON"
|
|
90
|
+
"ZSTD_BUILD_COMPRESSION OFF"
|
|
91
|
+
"ZSTD_BUILD_DICTBUILDER OFF"
|
|
92
|
+
"ZSTD_LEGACY_SUPPORT OFF"
|
|
93
|
+
"ZSTD_MULTITHREAD_SUPPORT OFF"
|
|
94
|
+
)
|
|
95
|
+
set(ZSTD_INCLUDE_DIR ${zstd_SOURCE_DIR}/lib)
|
|
96
|
+
set(ZSTD_LIBRARY libzstd_static)
|
|
97
|
+
|
|
98
|
+
if(WIN32)
|
|
99
|
+
set(pxsteamdl_mbedtls_pthread OFF)
|
|
100
|
+
else()
|
|
101
|
+
set(pxsteamdl_mbedtls_pthread ON)
|
|
102
|
+
endif()
|
|
103
|
+
CPMAddPackage(
|
|
104
|
+
NAME mbedtls
|
|
105
|
+
VERSION 3.6.7
|
|
106
|
+
URL https://github.com/Mbed-TLS/mbedtls/releases/download/mbedtls-3.6.7/mbedtls-3.6.7.tar.bz2
|
|
107
|
+
URL_HASH SHA256=a7e8bcbec0e6f761b4af24f25677626b35f762f68eef79c08677a363212d11f6
|
|
108
|
+
EXCLUDE_FROM_ALL YES
|
|
109
|
+
SYSTEM YES
|
|
110
|
+
OPTIONS
|
|
111
|
+
"ENABLE_PROGRAMS OFF"
|
|
112
|
+
"ENABLE_TESTING OFF"
|
|
113
|
+
"USE_SHARED_MBEDTLS_LIBRARY OFF"
|
|
114
|
+
"USE_STATIC_MBEDTLS_LIBRARY ON"
|
|
115
|
+
"MBEDTLS_FATAL_WARNINGS OFF"
|
|
116
|
+
"DISABLE_PACKAGE_CONFIG_AND_INSTALL ON"
|
|
117
|
+
"LINK_WITH_PTHREAD ${pxsteamdl_mbedtls_pthread}"
|
|
118
|
+
"MBEDTLS_USER_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/mbedtls/pxsteamdl_mbedtls_config.h"
|
|
119
|
+
)
|
|
120
|
+
if(WIN32)
|
|
121
|
+
# threading_alt.h, included by every mbedTLS consumer (mbedtls/threading.h).
|
|
122
|
+
target_include_directories(mbedcrypto SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cmake/mbedtls)
|
|
123
|
+
endif()
|
|
124
|
+
# Picked up by curl's FindMbedTLS instead of pkg-config/system search.
|
|
125
|
+
set(MBEDTLS_INCLUDE_DIR ${mbedtls_SOURCE_DIR}/include)
|
|
126
|
+
set(MBEDTLS_LIBRARY mbedtls)
|
|
127
|
+
set(MBEDX509_LIBRARY mbedx509)
|
|
128
|
+
set(MBEDCRYPTO_LIBRARY mbedcrypto)
|
|
129
|
+
# curl would try_compile against the not-yet-built mbedcrypto; the probe only gates NTLM, which is disabled.
|
|
130
|
+
set(HAVE_MBEDTLS_DES_CRYPT_ECB 0)
|
|
131
|
+
# No build-host CA paths: the bundle below is the only trust store. These are cache entries, not CPM OPTIONS,
|
|
132
|
+
# because curl clears the "none" cache value and OPTIONS would leave a literal "none" behind.
|
|
133
|
+
set(CURL_CA_BUNDLE none CACHE STRING "")
|
|
134
|
+
set(CURL_CA_PATH none CACHE STRING "")
|
|
135
|
+
|
|
136
|
+
CPMAddPackage(
|
|
137
|
+
NAME curl
|
|
138
|
+
VERSION 8.22.0
|
|
139
|
+
URL https://github.com/curl/curl/releases/download/curl-8_22_0/curl-8.22.0.tar.xz
|
|
140
|
+
URL_HASH SHA256=f7ef3ae8a22e521f289803fe93543eb64c329b58aa73a9e224dfd915a2a5f4f7
|
|
141
|
+
EXCLUDE_FROM_ALL YES
|
|
142
|
+
SYSTEM YES
|
|
143
|
+
OPTIONS
|
|
144
|
+
"BUILD_CURL_EXE OFF"
|
|
145
|
+
"BUILD_STATIC_LIBS ON"
|
|
146
|
+
"BUILD_LIBCURL_DOCS OFF"
|
|
147
|
+
"BUILD_MISC_DOCS OFF"
|
|
148
|
+
"ENABLE_CURL_MANUAL OFF"
|
|
149
|
+
"BUILD_TESTING OFF"
|
|
150
|
+
"BUILD_EXAMPLES OFF"
|
|
151
|
+
"CURL_DISABLE_INSTALL ON"
|
|
152
|
+
"CURL_ENABLE_EXPORT_TARGET OFF"
|
|
153
|
+
"PICKY_COMPILER OFF"
|
|
154
|
+
"CURL_USE_PKGCONFIG OFF"
|
|
155
|
+
"CURL_USE_CMAKECONFIG OFF"
|
|
156
|
+
"CURL_USE_MBEDTLS ON"
|
|
157
|
+
"CURL_USE_OPENSSL OFF"
|
|
158
|
+
"CURL_ZLIB ON"
|
|
159
|
+
"CURL_ZSTD ON"
|
|
160
|
+
"CURL_BROTLI OFF"
|
|
161
|
+
"USE_NGHTTP2 OFF"
|
|
162
|
+
"USE_LIBIDN2 OFF"
|
|
163
|
+
"USE_WIN32_IDN OFF"
|
|
164
|
+
"USE_APPLE_IDN OFF"
|
|
165
|
+
"CURL_USE_LIBPSL OFF"
|
|
166
|
+
"CURL_USE_LIBSSH2 OFF"
|
|
167
|
+
"CURL_USE_LIBSSH OFF"
|
|
168
|
+
"CURL_USE_GSSAPI OFF"
|
|
169
|
+
"ENABLE_UNIX_SOCKETS OFF"
|
|
170
|
+
"CURL_DISABLE_DICT ON"
|
|
171
|
+
"CURL_DISABLE_FILE ON"
|
|
172
|
+
"CURL_DISABLE_FTP ON"
|
|
173
|
+
"CURL_DISABLE_GOPHER ON"
|
|
174
|
+
"CURL_DISABLE_IMAP ON"
|
|
175
|
+
"CURL_DISABLE_IPFS ON"
|
|
176
|
+
"CURL_DISABLE_LDAP ON"
|
|
177
|
+
"CURL_DISABLE_LDAPS ON"
|
|
178
|
+
"CURL_DISABLE_MQTT ON"
|
|
179
|
+
"CURL_DISABLE_POP3 ON"
|
|
180
|
+
"CURL_DISABLE_RTSP ON"
|
|
181
|
+
"CURL_DISABLE_SMTP ON"
|
|
182
|
+
"CURL_DISABLE_TELNET ON"
|
|
183
|
+
"CURL_DISABLE_TFTP ON"
|
|
184
|
+
"CURL_DISABLE_COOKIES ON"
|
|
185
|
+
"CURL_DISABLE_MIME ON"
|
|
186
|
+
"CURL_DISABLE_NETRC ON"
|
|
187
|
+
"CURL_DISABLE_WEBSOCKETS OFF"
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
# Mozilla CA bundle (as extracted by curl), compiled in: mbedTLS cannot use the OS trust store.
|
|
191
|
+
set(PXSTEAMDL_CA_BUNDLE_DATE 2026-09-25)
|
|
192
|
+
CPMAddPackage(
|
|
193
|
+
NAME cacert
|
|
194
|
+
VERSION ${PXSTEAMDL_CA_BUNDLE_DATE}
|
|
195
|
+
URL https://curl.se/ca/cacert-${PXSTEAMDL_CA_BUNDLE_DATE}.pem
|
|
196
|
+
URL_HASH SHA256=a41b5d356aea97a529fe27e0f7316d2f9d946d75927476cf9cf1b90637d00505
|
|
197
|
+
DOWNLOAD_ONLY YES
|
|
198
|
+
DOWNLOAD_NO_EXTRACT YES
|
|
199
|
+
)
|
|
200
|
+
set(ca_bundle_pem ${cacert_SOURCE_DIR}/cacert-${PXSTEAMDL_CA_BUNDLE_DATE}.pem)
|
|
201
|
+
set(ca_bundle_cpp ${CMAKE_CURRENT_BINARY_DIR}/ca_bundle.cpp)
|
|
202
|
+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${ca_bundle_pem})
|
|
203
|
+
file(READ ${ca_bundle_pem} ca_bundle_hex HEX)
|
|
204
|
+
string(REGEX REPLACE "(................................................................)" "\\1\n" ca_bundle_hex "${ca_bundle_hex}")
|
|
205
|
+
# A byte array, not a string literal: MSVC caps string literals at 64 KiB. The trailing 0 lets mbedTLS parse it in place.
|
|
206
|
+
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," ca_bundle_bytes "${ca_bundle_hex}")
|
|
207
|
+
file(CONFIGURE OUTPUT ${ca_bundle_cpp} @ONLY CONTENT [[
|
|
208
|
+
// Generated from cacert-@PXSTEAMDL_CA_BUNDLE_DATE@.pem by CMakeLists.txt.
|
|
209
|
+
#include <cstddef>
|
|
210
|
+
namespace pxsteamdl::detail {
|
|
211
|
+
extern const unsigned char kCaBundle[] = {
|
|
212
|
+
@ca_bundle_bytes@0x00};
|
|
213
|
+
extern const std::size_t kCaBundleSize = sizeof(kCaBundle);
|
|
214
|
+
}
|
|
215
|
+
]])
|
|
216
|
+
|
|
217
|
+
find_package(Threads REQUIRED)
|
|
218
|
+
|
|
219
|
+
function(pxsteamdl_warnings target)
|
|
220
|
+
if(MSVC)
|
|
221
|
+
target_compile_options(${target} PRIVATE /W4)
|
|
222
|
+
else()
|
|
223
|
+
target_compile_options(${target} PRIVATE -Wall -Wextra)
|
|
224
|
+
endif()
|
|
225
|
+
endfunction()
|
|
226
|
+
|
|
227
|
+
# Everything but the three files that talk to the outside world (HTTP, the CM session, pauses). The unit tests build
|
|
228
|
+
# these sources against fakes of those three instead (tests/fakes), so the whole download pipeline runs offline.
|
|
229
|
+
set(PXSTEAMDL_CORE_SOURCES
|
|
230
|
+
src/cdn.cpp
|
|
231
|
+
src/chunk.cpp
|
|
232
|
+
src/client.cpp
|
|
233
|
+
src/cm_packet.cpp
|
|
234
|
+
src/crypto.cpp
|
|
235
|
+
src/directory_lock.cpp
|
|
236
|
+
src/directory_update.cpp
|
|
237
|
+
src/downloader.cpp
|
|
238
|
+
src/eresult.cpp
|
|
239
|
+
src/error.cpp
|
|
240
|
+
src/manifest.cpp
|
|
241
|
+
src/paths.cpp
|
|
242
|
+
src/pending_file.cpp
|
|
243
|
+
src/proto.cpp
|
|
244
|
+
src/retry.cpp
|
|
245
|
+
src/version.cpp
|
|
246
|
+
src/workshop.cpp
|
|
247
|
+
src/zip.cpp
|
|
248
|
+
)
|
|
249
|
+
add_library(pxsteamdl
|
|
250
|
+
${PXSTEAMDL_CORE_SOURCES}
|
|
251
|
+
src/http.cpp
|
|
252
|
+
src/session.cpp
|
|
253
|
+
src/sleep.cpp
|
|
254
|
+
${ca_bundle_cpp}
|
|
255
|
+
)
|
|
256
|
+
add_library(PxSteamDL::pxsteamdl ALIAS pxsteamdl)
|
|
257
|
+
target_include_directories(pxsteamdl
|
|
258
|
+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
259
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
|
260
|
+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
261
|
+
PRIVATE src
|
|
262
|
+
)
|
|
263
|
+
target_link_libraries(pxsteamdl
|
|
264
|
+
PRIVATE CURL::libcurl MbedTLS::mbedcrypto ZLIB::ZLIB liblzma libzstd_static nlohmann_json::nlohmann_json
|
|
265
|
+
PUBLIC Threads::Threads
|
|
266
|
+
)
|
|
267
|
+
if(WIN32)
|
|
268
|
+
target_compile_definitions(pxsteamdl PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
|
|
269
|
+
target_link_libraries(pxsteamdl PRIVATE ws2_32)
|
|
270
|
+
endif()
|
|
271
|
+
pxsteamdl_warnings(pxsteamdl)
|
|
272
|
+
|
|
273
|
+
if(PXSTEAMDL_BUILD_CLI)
|
|
274
|
+
add_executable(pxsteamdl-cli cli/main.cpp)
|
|
275
|
+
set_target_properties(pxsteamdl-cli PROPERTIES OUTPUT_NAME pxsteamdl)
|
|
276
|
+
target_link_libraries(pxsteamdl-cli PRIVATE PxSteamDL::pxsteamdl)
|
|
277
|
+
if(WIN32)
|
|
278
|
+
target_sources(pxsteamdl-cli PRIVATE cli/utf8.manifest)
|
|
279
|
+
endif()
|
|
280
|
+
pxsteamdl_warnings(pxsteamdl-cli)
|
|
281
|
+
endif()
|
|
282
|
+
|
|
283
|
+
if(PXSTEAMDL_BUILD_PYTHON)
|
|
284
|
+
# SKBUILD_SABI_COMPONENT (set by scikit-build-core for abi3 builds) lets nanobind target the stable ABI.
|
|
285
|
+
find_package(Python 3.10 REQUIRED COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT})
|
|
286
|
+
CPMAddPackage(
|
|
287
|
+
NAME nanobind
|
|
288
|
+
GITHUB_REPOSITORY wjakob/nanobind
|
|
289
|
+
GIT_TAG v2.15.0
|
|
290
|
+
EXCLUDE_FROM_ALL YES
|
|
291
|
+
SYSTEM YES
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
# STABLE_ABI takes effect on Python >= 3.12 (abi3 wheel); older versions get a version-specific module.
|
|
295
|
+
nanobind_add_module(_pxsteamdl NB_STATIC STABLE_ABI python/pxsteamdl.cpp)
|
|
296
|
+
target_link_libraries(_pxsteamdl PRIVATE PxSteamDL::pxsteamdl)
|
|
297
|
+
pxsteamdl_warnings(_pxsteamdl)
|
|
298
|
+
nanobind_add_stub(_pxsteamdl_stub
|
|
299
|
+
MODULE _pxsteamdl
|
|
300
|
+
OUTPUT _pxsteamdl.pyi
|
|
301
|
+
PYTHON_PATH $<TARGET_FILE_DIR:_pxsteamdl>
|
|
302
|
+
DEPENDS _pxsteamdl
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
# Wheel layout (scikit-build-core): python/pxsteamdl/ is packaged by the backend. The component keeps
|
|
306
|
+
# dependency install rules out of the wheel.
|
|
307
|
+
install(TARGETS _pxsteamdl LIBRARY DESTINATION pxsteamdl COMPONENT python)
|
|
308
|
+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/_pxsteamdl.pyi DESTINATION pxsteamdl COMPONENT python)
|
|
309
|
+
endif()
|
|
310
|
+
|
|
311
|
+
if(PXSTEAMDL_BUILD_NODE)
|
|
312
|
+
if(NOT CMAKE_JS_INC)
|
|
313
|
+
message(FATAL_ERROR "PXSTEAMDL_BUILD_NODE needs the Node.js headers: build with cmake-js (npm install)")
|
|
314
|
+
endif()
|
|
315
|
+
execute_process(
|
|
316
|
+
COMMAND node -p "require('path').resolve(require('node-addon-api').include_dir)"
|
|
317
|
+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
318
|
+
OUTPUT_VARIABLE node_addon_api_dir
|
|
319
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
320
|
+
COMMAND_ERROR_IS_FATAL ANY
|
|
321
|
+
)
|
|
322
|
+
string(REPLACE "\"" "" node_addon_api_dir "${node_addon_api_dir}")
|
|
323
|
+
add_library(pxsteamdl-node SHARED node/pxsteamdl.cpp ${CMAKE_JS_SRC})
|
|
324
|
+
set_target_properties(pxsteamdl-node PROPERTIES OUTPUT_NAME pxsteamdl-addon PREFIX "" SUFFIX ".node")
|
|
325
|
+
target_include_directories(pxsteamdl-node SYSTEM PRIVATE ${CMAKE_JS_INC} ${node_addon_api_dir})
|
|
326
|
+
target_compile_definitions(pxsteamdl-node PRIVATE NAPI_CPP_EXCEPTIONS)
|
|
327
|
+
target_link_libraries(pxsteamdl-node PRIVATE PxSteamDL::pxsteamdl ${CMAKE_JS_LIB})
|
|
328
|
+
# node/index.js loads node/native/pxsteamdl-addon.node, whatever the generator.
|
|
329
|
+
set(node_native_dir $<1:${CMAKE_CURRENT_SOURCE_DIR}/node/native>)
|
|
330
|
+
set_target_properties(pxsteamdl-node PROPERTIES
|
|
331
|
+
LIBRARY_OUTPUT_DIRECTORY ${node_native_dir}
|
|
332
|
+
RUNTIME_OUTPUT_DIRECTORY ${node_native_dir}
|
|
333
|
+
)
|
|
334
|
+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
335
|
+
# The node executable exports the symbols of the libraries it bundles (zlib, and with some versions even
|
|
336
|
+
# mbedTLS), which would replace the addon's own static copies of different versions at load time. Bind the
|
|
337
|
+
# addon's references to its own code, and do not re-export the static libraries.
|
|
338
|
+
target_link_options(pxsteamdl-node PRIVATE -Wl,-Bsymbolic -Wl,--exclude-libs,ALL)
|
|
339
|
+
endif()
|
|
340
|
+
pxsteamdl_warnings(pxsteamdl-node)
|
|
341
|
+
endif()
|
|
342
|
+
|
|
343
|
+
if(PXSTEAMDL_BUILD_EXAMPLES)
|
|
344
|
+
add_executable(example-download examples/download.cpp)
|
|
345
|
+
target_link_libraries(example-download PRIVATE pxsteamdl)
|
|
346
|
+
endif()
|
|
347
|
+
|
|
348
|
+
if(PXSTEAMDL_BUILD_TESTS)
|
|
349
|
+
CPMAddPackage(
|
|
350
|
+
NAME googletest
|
|
351
|
+
VERSION 1.17.0
|
|
352
|
+
URL https://github.com/google/googletest/releases/download/v1.17.0/googletest-1.17.0.tar.gz
|
|
353
|
+
URL_HASH SHA256=65fab701d9829d38cb77c14acdc431d2108bfdbf8979e40eb8ae567edf10b27c
|
|
354
|
+
EXCLUDE_FROM_ALL YES
|
|
355
|
+
SYSTEM YES
|
|
356
|
+
OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF" "gtest_force_shared_crt ON"
|
|
357
|
+
)
|
|
358
|
+
enable_testing()
|
|
359
|
+
include(GoogleTest)
|
|
360
|
+
|
|
361
|
+
# A separate process holds a real kernel lock; the tests terminate it to verify stale-owner recovery.
|
|
362
|
+
add_executable(pxsteamdl-lock-holder tests/lock_holder.cpp src/directory_lock.cpp src/paths.cpp)
|
|
363
|
+
target_include_directories(pxsteamdl-lock-holder PRIVATE src include)
|
|
364
|
+
target_link_libraries(pxsteamdl-lock-holder PRIVATE Threads::Threads)
|
|
365
|
+
if(WIN32)
|
|
366
|
+
target_compile_definitions(pxsteamdl-lock-holder PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
|
|
367
|
+
target_sources(pxsteamdl-lock-holder PRIVATE cli/utf8.manifest)
|
|
368
|
+
endif()
|
|
369
|
+
pxsteamdl_warnings(pxsteamdl-lock-holder)
|
|
370
|
+
|
|
371
|
+
# Unit tests of the internal modules (src/*.hpp). They build the core sources again, with fakes in place of
|
|
372
|
+
# src/http.cpp, src/session.cpp and src/sleep.cpp, so they need no network or retry pauses.
|
|
373
|
+
add_executable(pxsteamdl-tests
|
|
374
|
+
${PXSTEAMDL_CORE_SOURCES}
|
|
375
|
+
tests/fakes/fake_http.cpp
|
|
376
|
+
tests/fakes/fake_session.cpp
|
|
377
|
+
tests/fakes/fake_sleep.cpp
|
|
378
|
+
tests/fake_steam.cpp
|
|
379
|
+
tests/chunk_test.cpp
|
|
380
|
+
tests/client_test.cpp
|
|
381
|
+
tests/cm_packet_test.cpp
|
|
382
|
+
tests/crypto_test.cpp
|
|
383
|
+
tests/directory_lock_test.cpp
|
|
384
|
+
tests/directory_update_test.cpp
|
|
385
|
+
tests/eresult_test.cpp
|
|
386
|
+
tests/error_test.cpp
|
|
387
|
+
tests/manifest_test.cpp
|
|
388
|
+
tests/paths_test.cpp
|
|
389
|
+
tests/proto_test.cpp
|
|
390
|
+
tests/retry_test.cpp
|
|
391
|
+
tests/version_test.cpp
|
|
392
|
+
tests/zip_test.cpp
|
|
393
|
+
)
|
|
394
|
+
target_include_directories(pxsteamdl-tests PRIVATE src tests tests/fakes include ${CMAKE_CURRENT_BINARY_DIR}/include)
|
|
395
|
+
target_link_libraries(pxsteamdl-tests
|
|
396
|
+
PRIVATE GTest::gtest_main ZLIB::ZLIB MbedTLS::mbedcrypto liblzma libzstd_static nlohmann_json::nlohmann_json
|
|
397
|
+
Threads::Threads
|
|
398
|
+
)
|
|
399
|
+
if(WIN32)
|
|
400
|
+
target_compile_definitions(pxsteamdl-tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
|
|
401
|
+
endif()
|
|
402
|
+
pxsteamdl_warnings(pxsteamdl-tests)
|
|
403
|
+
target_compile_definitions(pxsteamdl-tests PRIVATE PXSTEAMDL_LOCK_HOLDER_PATH="$<TARGET_FILE:pxsteamdl-lock-holder>")
|
|
404
|
+
add_dependencies(pxsteamdl-tests pxsteamdl-lock-holder)
|
|
405
|
+
gtest_discover_tests(pxsteamdl-tests)
|
|
406
|
+
|
|
407
|
+
# The real SleepFor(), which the fake above replaces.
|
|
408
|
+
add_executable(pxsteamdl-sleep-tests src/sleep.cpp tests/sleep_test.cpp)
|
|
409
|
+
target_include_directories(pxsteamdl-sleep-tests PRIVATE src)
|
|
410
|
+
target_link_libraries(pxsteamdl-sleep-tests PRIVATE GTest::gtest_main Threads::Threads)
|
|
411
|
+
pxsteamdl_warnings(pxsteamdl-sleep-tests)
|
|
412
|
+
gtest_discover_tests(pxsteamdl-sleep-tests)
|
|
413
|
+
endif()
|
|
414
|
+
|
|
415
|
+
if(PXSTEAMDL_INSTALL)
|
|
416
|
+
include(cmake/PxSteamDLInstall.cmake)
|
|
417
|
+
endif()
|