Skip to content

Commit cf21829

Browse files
committed
Externalizing and unifying dependency management
1 parent 7bc2eff commit cf21829

File tree

3 files changed

+177
-113
lines changed

3 files changed

+177
-113
lines changed

cmake/dependencies.cmake

Lines changed: 33 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,40 @@
22
# SPDX-License-Identifier: BSD-3-Clause
33

44
include(FetchContent)
5-
include(ExternalProject)
65

7-
set(DECLARED_DEPENDENCIES "")
8-
set(DEPENDECIES_JSON "")
9-
10-
#################################################
11-
12-
set(ARGUM_REPO gershnik/argum)
13-
set(ARGUM_VER v2.6)
14-
FetchContent_Declare(argum
15-
URL https://github.com/${ARGUM_REPO}/tarball/${ARGUM_VER}
16-
)
17-
list(APPEND DECLARED_DEPENDENCIES argum)
18-
list(APPEND DEPENDECIES_JSON "\"argum\": \"pkg:github/${ARGUM_REPO}@${ARGUM_VER}\"")
6+
file(READ dependencies.json DEPENDECIES_JSON)
7+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS dependencies.json)
198

20-
#################################################
21-
22-
set(SYS_STRING_REPO gershnik/sys_string)
23-
set(SYS_STRING_VER v2.20)
24-
FetchContent_Declare(sys_string
25-
URL https://github.com/${SYS_STRING_REPO}/tarball/${SYS_STRING_VER}
26-
)
27-
list(APPEND DECLARED_DEPENDENCIES sys_string)
28-
list(APPEND DEPENDECIES_JSON "\"sys_string\": \"pkg:github/${SYS_STRING_REPO}@${SYS_STRING_VER}\"")
299

30-
#################################################
10+
set(DECLARED_DEPENDENCIES "")
3111

32-
set(ISPTR_REPO gershnik/intrusive_shared_ptr)
33-
set(ISPTR_VER v1.9)
34-
FetchContent_Declare(isptr
35-
URL https://github.com/${ISPTR_REPO}/tarball/${ISPTR_VER}
12+
function(fetch_dependency name #extras for FetchContent_Declare
3613
)
37-
list(APPEND DECLARED_DEPENDENCIES isptr)
38-
list(APPEND DEPENDECIES_JSON "\"isptr\": \"pkg:github/${ISPTR_REPO}@${ISPTR_VER}\"")
14+
string(JSON version GET "${DEPENDECIES_JSON}" ${name} version)
15+
string(JSON url GET "${DEPENDECIES_JSON}" ${name} url)
16+
string(JSON md5 GET "${DEPENDECIES_JSON}" ${name} md5)
17+
string(REPLACE "\$\{version\}" ${version} url "${url}")
18+
set(extras "")
19+
foreach(i RANGE 1 ${ARGC})
20+
list(APPEND extras ${ARGV${i}})
21+
endforeach()
22+
FetchContent_Declare(${name}
23+
URL ${url}
24+
URL_HASH MD5=${md5}
25+
${extras}
26+
)
27+
set(deplist ${DECLARED_DEPENDENCIES})
28+
list(APPEND deplist ${name})
29+
set(DECLARED_DEPENDENCIES ${deplist} PARENT_SCOPE)
30+
endfunction()
3931

4032
#################################################
4133

42-
set(PTL_REPO gershnik/ptl)
43-
set(PTL_VER v1.6)
44-
FetchContent_Declare(ptl
45-
URL https://github.com/${PTL_REPO}/tarball/${PTL_VER}
46-
)
47-
list(APPEND DECLARED_DEPENDENCIES ptl)
48-
list(APPEND DEPENDECIES_JSON "\"ptl\": \"pkg:github/${PTL_REPO}@${PTL_VER}\"")
49-
50-
#################################################
34+
fetch_dependency(argum)
35+
fetch_dependency(sys_string)
36+
fetch_dependency(isptr)
37+
fetch_dependency(ptl)
38+
fetch_dependency(modern-uuid)
5139

5240
if (WSDDN_PREFER_SYSTEM)
5341
find_package(LibXml2)
@@ -69,83 +57,24 @@ if (NOT LibXml2_FOUND)
6957
set(LIBXML2_WITH_MODULES OFF)
7058
set(LIBXML2_WITH_PROGRAMS OFF)
7159

72-
set(LIBXML_VER v2.14.5)
73-
FetchContent_Declare(libxml2
74-
URL https://gitlab.gnome.org/GNOME/libxml2/-/archive/${LIBXML_VER}/libxml2-${LIBXML_VER}.tar.gz
75-
)
76-
list(APPEND DECLARED_DEPENDENCIES libxml2)
77-
list(APPEND DEPENDECIES_JSON "\"libxml2\": \"pkg:generic/libxml2@${LIBXML_VER}\"")
78-
60+
fetch_dependency(libxml2)
61+
7962
endif()
8063

81-
#################################################
82-
83-
set(MUUID_REPO gershnik/modern-uuid)
84-
set(MUUID_VER v1.8)
85-
FetchContent_Declare(modern-uuid
86-
URL https://github.com/${MUUID_REPO}/tarball/${MUUID_VER}
87-
)
88-
list(APPEND DECLARED_DEPENDENCIES modern-uuid)
89-
list(APPEND DEPENDECIES_JSON "\"modern-uuid\": \"pkg:github/${MUUID_REPO}@${MUUID_VER}\"")
90-
91-
#################################################
9264

9365
set(FMT_INSTALL OFF)
94-
95-
set(FMT_REPO fmtlib/fmt)
96-
set(FMT_VER 11.2.0)
97-
FetchContent_Declare(fmt
98-
URL https://github.com/${FMT_REPO}/tarball/${FMT_VER}
99-
)
100-
list(APPEND DECLARED_DEPENDENCIES fmt)
101-
list(APPEND DEPENDECIES_JSON "\"fmt\": \"pkg:github/${FMT_REPO}@${FMT_VER}\"")
102-
103-
#################################################
66+
fetch_dependency(fmt)
10467

10568
set(SPDLOG_NO_ATOMIC_LEVELS ON CACHE BOOL "prevent spdlog from using of std::atomic log levels (use only if your code never modifies log levels concurrently)")
10669
set(SPDLOG_NO_TLS ON CACHE BOOL "prevent spdlog from using thread local storage")
10770
set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "Use external fmt library instead of bundled")
71+
fetch_dependency(spdlog)
10872

109-
set(SPDLOG_REPO gabime/spdlog)
110-
set(SPDLOG_VER v1.15.3)
111-
FetchContent_Declare(spdlog
112-
URL https://github.com/${SPDLOG_REPO}/tarball/${SPDLOG_VER}
113-
)
114-
list(APPEND DECLARED_DEPENDENCIES spdlog)
115-
list(APPEND DEPENDECIES_JSON "\"spdlog\": \"pkg:github/${SPDLOG_REPO}@${SPDLOG_VER}\"")
116-
117-
#################################################
118-
119-
set(TOMPLUSPLUS_REPO marzer/tomlplusplus)
120-
set(TOMPLUSPLUS_VER v3.4.0)
121-
FetchContent_Declare(tomlplusplus
122-
URL https://github.com/${TOMPLUSPLUS_REPO}/tarball/${TOMPLUSPLUS_VER}
123-
)
124-
list(APPEND DECLARED_DEPENDENCIES tomlplusplus)
125-
list(APPEND DEPENDECIES_JSON "\"tomlplusplus\": \"pkg:github/${TOMPLUSPLUS_REPO}@${TOMPLUSPLUS_VER}\"")
126-
127-
#################################################
128-
129-
set(OUTCOME_REPO ned14/outcome)
130-
set(OUTCOME_VER v2.2.12)
131-
FetchContent_Declare(outcome
132-
URL https://github.com/${OUTCOME_REPO}/tarball/${OUTCOME_VER}
73+
fetch_dependency(tomlplusplus)
74+
fetch_dependency(outcome
13375
SOURCE_SUBDIR include #we don't really want to build it
13476
)
135-
list(APPEND DECLARED_DEPENDENCIES outcome)
136-
list(APPEND DEPENDECIES_JSON "\"outcome\": \"pkg:github/${OUTCOME_REPO}@${OUTCOME_VER}\"")
137-
138-
#################################################
139-
140-
set(ASIO_VER 1.30.2)
141-
set(ASIO_URL https://sourceforge.net/projects/asio/files/asio/${ASIO_VER}%20%28Stable%29/asio-${ASIO_VER}.tar.gz/download)
142-
set(ASIO_CHECKSUM c1643d3eddd45b210b760acc7ec25d59)
143-
FetchContent_Declare(asio
144-
URL ${ASIO_URL}
145-
URL_HASH MD5=${ASIO_CHECKSUM}
146-
)
147-
list(APPEND DECLARED_DEPENDENCIES asio)
148-
list(APPEND DEPENDECIES_JSON "\"asio\": \"pkg:generic/asio@${ASIO_VER}?download_url=${ASIO_URL}&checksum=md5:${ASIO_CHECKSUM}\"")
77+
fetch_dependency(asio)
14978

15079
#################################################
15180

@@ -166,13 +95,4 @@ foreach(dir ${KNOWN_SUBDIRECTORIES})
16695
endif()
16796
endforeach()
16897

169-
list(JOIN DEPENDECIES_JSON ",\n " DEPENDECIES_JSON)
170-
cmake_path(RELATIVE_PATH CMAKE_CURRENT_LIST_FILE OUTPUT_VARIABLE JSON_SRC_PATH)
171-
set(DEPENDECIES_JSON "{
172-
\"version\": \"1.0\",
173-
\"src\": \"${JSON_SRC_PATH}\",
174-
\"dependencies\": {
175-
${DEPENDECIES_JSON}
176-
}}")
177-
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dependencies.json ${DEPENDECIES_JSON})
17898

dependencies.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"argum": {
3+
"version": "v2.6",
4+
"url": "https://github.com/gershnik/argum/tarball/${version}",
5+
"homepage": "https://github.com/gershnik/argum",
6+
"sha256": "72b2b6805da7bf022e8111f3c2f3ed08ae6c23daa0ad336de56f2bd133d653c4",
7+
"md5": "59141e9e95b75097b0cf6d9d36fc6304"
8+
},
9+
"asio": {
10+
"version": "1.30.2",
11+
"url": "https://sourceforge.net/projects/asio/files/asio/${version}%20%28Stable%29/asio-${version}.tar.gz/download",
12+
"homepage": "https://think-async.com/Asio/",
13+
"sha256": "12e7bb4dada8bc1191de9d550a59ee658ce4e645ffc97c911c099ab4e8699d55",
14+
"md5": "c1643d3eddd45b210b760acc7ec25d59"
15+
},
16+
"fmt": {
17+
"version": "11.2.0",
18+
"url": "https://github.com/fmtlib/fmt/tarball/${version}",
19+
"homepage": "https://github.com/fmtlib/fmt",
20+
"sha256": "15b7d9723d16e6ecbf83438a1611a2910879eaa5bc8d0e0fd8197c2f18f993be",
21+
"md5": "f040663ed1085fff0055481247fcde63"
22+
},
23+
"isptr": {
24+
"version": "v1.9",
25+
"url": "https://github.com/gershnik/intrusive_shared_ptr/tarball/${version}",
26+
"homepage": "https://github.com/gershnik/intrusive_shared_ptr",
27+
"sha256": "f9095609a2226f3aa6dbfcd4726a8521a56f4fd2f426b0898d92acd1f133aa6d",
28+
"md5": "574eb3ad0a8e5685cdc9e7712804900f"
29+
},
30+
"libxml2": {
31+
"version": "v2.14.5",
32+
"url": "https://gitlab.gnome.org/GNOME/libxml2/-/archive/${version}/libxml2-${version}.tar.gz",
33+
"homepage": "https://gitlab.gnome.org/GNOME/libxml2",
34+
"sha256": "54968c8ab8723c2d75a38fc45810e8cf60d44991e0887661bf9905a4042ad108",
35+
"md5": "2da0f9e59d6ce8d4f9d8460a8341b135"
36+
},
37+
"modern-uuid": {
38+
"version": "v1.8",
39+
"url": "https://github.com/gershnik/modern-uuid/tarball/${version}",
40+
"homepage": "https://github.com/gershnik/modern-uuid",
41+
"sha256": "bb3fb3e53b45cd7e6b977835cfc7ef25680e92b68daf709b1f494f46697dae02",
42+
"md5": "b8b5ba4e4fa9a104eff3121fe571f186"
43+
},
44+
"outcome": {
45+
"version": "v2.2.12",
46+
"url": "https://github.com/ned14/outcome/tarball/${version}",
47+
"homepage": "https://github.com/ned14/outcome",
48+
"sha256": "838ed35d1bdedcfe9cee2186b51d023404274418f2868798fefac5a54e8bb403",
49+
"md5": "4757c54b97d015c66b6431ba75de90a3"
50+
},
51+
"ptl": {
52+
"version": "v1.6",
53+
"url": "https://github.com/gershnik/ptl/tarball/${version}",
54+
"homepage": "https://github.com/gershnik/ptl",
55+
"sha256": "4ba354ef8615b758dbdd0faf7638a9fb4607ee55c0028a5a6ae87b3bdf005f3a",
56+
"md5": "6bc4c78819bed298786efdd0ee4e1585"
57+
},
58+
"spdlog": {
59+
"version": "v1.15.3",
60+
"url": "https://github.com/gabime/spdlog/tarball/${version}",
61+
"homepage": "https://github.com/gabime/spdlog",
62+
"sha256": "2f33b90dee78e9a910abbba1a294398277d4608831c6b8161ac74a7ca5493b49",
63+
"md5": "fff8a896dce461edf0402c2589526a46"
64+
},
65+
"sys_string": {
66+
"version": "v2.20",
67+
"url": "https://github.com/gershnik/sys_string/tarball/${version}",
68+
"homepage": "https://github.com/gershnik/sys_string",
69+
"sha256": "d2a0aa64e3e20e8f01ece30fa618393401d78bc9065b034aecf96814c0389c6f",
70+
"md5": "1ecc6165c86085c8aa158e0203824127"
71+
},
72+
"tomlplusplus": {
73+
"version": "v3.4.0",
74+
"url": "https://github.com/marzer/tomlplusplus/tarball/${version}",
75+
"homepage": "https://github.com/marzer/tomlplusplus",
76+
"sha256": "8874014da21de8d1414d9914c8f3c6b5f315c23a75951b33df46048c13dda12f",
77+
"md5": "562036440b3283550d508ef5dd85a839"
78+
}
79+
}

tools/hashdeps

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#! /usr/bin/env -S python3 -u
2+
3+
import argparse
4+
import json
5+
import hashlib
6+
7+
from pathlib import Path
8+
from urllib.request import urlretrieve
9+
from urllib.error import HTTPError
10+
11+
MYDIR = Path(__file__).parent
12+
13+
14+
15+
def hash_url(url):
16+
try:
17+
path, _ = urlretrieve(url)
18+
except HTTPError as err:
19+
raise RuntimeError(f'Unable to download {url}: {err}') from err
20+
try:
21+
sha256 = hashlib.sha256()
22+
md5 = hashlib.md5()
23+
buffer = bytearray(4096)
24+
view = memoryview(buffer)
25+
with open(path, 'rb') as f:
26+
while True:
27+
size = f.readinto(buffer)
28+
if size == 0:
29+
break
30+
sha256.update(view[:size])
31+
md5.update(view[:size])
32+
return sha256.hexdigest(), md5.hexdigest()
33+
finally:
34+
Path(path).unlink()
35+
36+
def main():
37+
parser = argparse.ArgumentParser()
38+
39+
parser.add_argument('name', nargs='*', type=str)
40+
args = parser.parse_args()
41+
42+
names = set(args.name)
43+
44+
with open(MYDIR.parent / 'dependencies.json', 'rt', encoding='utf-8') as f:
45+
deps = json.load(f)
46+
changed = False
47+
for dep, data in deps.items():
48+
if not len(names) == 0 and not dep in names:
49+
continue
50+
version = data['version']
51+
url: str = data['url']
52+
url = url.replace('${version}', version)
53+
sha256, md5 = hash_url(url)
54+
if data.get('sha256', '') != sha256:
55+
data['sha256'] = sha256
56+
changed = True
57+
if data.get('md5', '') != md5:
58+
data['md5'] = md5
59+
changed = True
60+
if changed:
61+
with open(MYDIR.parent / 'dependencies.json', 'wt', encoding='utf-8') as f:
62+
json.dump(deps, f, indent=4)
63+
64+
if __name__ == '__main__':
65+
main()

0 commit comments

Comments
 (0)