Skip to content

Commit 8e59161

Browse files
committed
refactor: Install headers into repo-equivalent directories.
This allows code to be built from an un-installed toxcore repo the same way it's built from an installed toxcore. I.e. all `#include` directives will work the same inside the toxcore repo and on a system which has toxcore installed. Previously, "toxcore/tox.h" was installed as "tox/tox.h", making `make install` a requirement for building any client code. Now, clients can be built directly from the repo source, which is especially nice for simple clients like echobots. Output: ``` -- Installing: /usr/local/include/tox/tox.h -- Installing: /usr/local/include/toxcore/tox.h -- Installing: /usr/local/include/toxcore/tox_events.h -- Installing: /usr/local/include/toxcore/tox_dispatch.h -- Installing: /usr/local/include/toxcore/tox_private.h -- Installing: /usr/local/include/tox/toxav.h -- Installing: /usr/local/include/toxav/toxav.h -- Installing: /usr/local/include/tox/toxencryptsave.h -- Installing: /usr/local/include/toxencryptsave/toxencryptsave.h ```
1 parent 4067628 commit 8e59161

File tree

11 files changed

+53
-26
lines changed

11 files changed

+53
-26
lines changed

BUILD.bazel

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@ load("//tools/project:build_defs.bzl", "project")
33

44
project(license = "gpl3-https")
55

6-
genrule(
6+
filegroup(
7+
name = "legacy_headers",
8+
srcs = [
9+
"tox/tox.h",
10+
"tox/toxav.h",
11+
"tox/toxencryptsave.h",
12+
],
13+
visibility = ["//visibility:public"],
14+
)
15+
16+
filegroup(
717
name = "public_headers",
818
srcs = [
919
"//c-toxcore/toxav:toxav.h",
1020
"//c-toxcore/toxcore:tox.h",
1121
"//c-toxcore/toxcore:tox_private.h",
1222
"//c-toxcore/toxencryptsave:toxencryptsave.h",
1323
],
14-
outs = [
15-
"tox/toxav.h",
16-
"tox/tox.h",
17-
"tox/tox_private.h",
18-
"tox/toxencryptsave.h",
19-
],
20-
cmd = """
21-
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
22-
cp $(location //c-toxcore/toxcore:tox.h) $(GENDIR)/c-toxcore/tox/tox.h
23-
cp $(location //c-toxcore/toxcore:tox_private.h) $(GENDIR)/c-toxcore/tox/tox_private.h
24-
cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h
25-
""",
2624
visibility = ["//visibility:public"],
2725
)
2826

2927
cc_library(
3028
name = "c-toxcore",
31-
hdrs = [":public_headers"],
32-
includes = ["."],
29+
hdrs = [
30+
":legacy_headers",
31+
":public_headers",
32+
],
33+
strip_include_prefix = ".",
3334
visibility = ["//visibility:public"],
3435
deps = [
3536
"//c-toxcore/toxav",

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ else()
362362
endif()
363363
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
364364
set(toxcore_API_HEADERS
365+
${toxcore_SOURCE_DIR}/tox/tox.h^tox
365366
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
366367
${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox
367368
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox)
@@ -397,6 +398,7 @@ if(BUILD_TOXAV)
397398
toxav/video.c
398399
toxav/video.h)
399400
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
401+
${toxcore_SOURCE_DIR}/tox/toxav.h^toxav
400402
${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
401403

402404
if(MSVC)
@@ -420,6 +422,7 @@ set(toxcore_SOURCES ${toxcore_SOURCES}
420422
toxencryptsave/toxencryptsave.c
421423
toxencryptsave/toxencryptsave.h)
422424
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
425+
${toxcore_SOURCE_DIR}/tox/toxencryptsave.h^tox
423426
${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)
424427

425428
################################################################################
@@ -501,8 +504,8 @@ endif()
501504
make_version_script(toxcore ${toxcore_API_HEADERS})
502505

503506
# Generate pkg-config file, install library to "${CMAKE_INSTALL_LIBDIR}" and install headers to
504-
# "${CMAKE_INSTALL_INCLUDEDIR}/tox".
505-
install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
507+
# "${CMAKE_INSTALL_INCLUDEDIR}".
508+
install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
506509

507510
################################################################################
508511
#

cmake/ModulePackage.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ if(FULLY_STATIC)
2020
endif()
2121

2222
function(install_module lib)
23+
cmake_parse_arguments(INSTALL_MODULE "" "DESTINATION" "" ${ARGN})
2324
if(TARGET ${lib}_shared)
2425
set_target_properties(${lib}_shared PROPERTIES
2526
VERSION ${SOVERSION}
@@ -59,7 +60,10 @@ function(install_module lib)
5960
foreach(sublib ${${lib}_API_HEADERS})
6061
string(REPLACE "^" ";" sublib ${sublib})
6162
list(GET sublib 0 header)
63+
string(REPLACE "${${lib}_SOURCE_DIR}/" "" target_header ${header})
64+
get_filename_component(target_path ${target_header} DIRECTORY)
6265

63-
install(FILES ${header} ${ARGN})
66+
install(FILES ${header} DESTINATION
67+
"${INSTALL_MODULE_DESTINATION}/${target_path}")
6468
endforeach()
6569
endfunction()

cmake/StrictAbi.cmake

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ function(_make_version_script target)
3232
COMMAND ${SHELL} -c "egrep '^\\w' ${header} | grep '${ns}_[a-z0-9_]*(' | grep -v '^typedef' | grep -o '${ns}_[a-z0-9_]*(' | egrep -o '[a-z0-9_]+' | sort -u"
3333
OUTPUT_VARIABLE sublib_SYMS
3434
OUTPUT_STRIP_TRAILING_WHITESPACE)
35-
string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS})
35+
if(sublib_SYMS)
36+
string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS})
3637

37-
foreach(sym ${sublib_SYMS})
38-
file(APPEND ${${target}_VERSION_SCRIPT}
39-
"${sym};\n")
40-
endforeach(sym)
38+
foreach(sym ${sublib_SYMS})
39+
file(APPEND ${${target}_VERSION_SCRIPT}
40+
"${sym};\n")
41+
endforeach(sym)
42+
endif()
4143
endforeach(sublib)
4244

4345
file(APPEND ${${target}_VERSION_SCRIPT}

other/bootstrap_daemon/docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ COPY other/DHT_bootstrap.c other/
2727
COPY other/pkgconfig other/pkgconfig
2828
COPY other/rpm other/rpm
2929
COPY testing/misc_tools.[ch] testing/
30+
COPY tox tox
3031
COPY toxcore toxcore
3132
COPY toxencryptsave toxencryptsave
3233
COPY third_party third_party

other/rpm/toxcore.spec.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ getent passwd tox-bootstrapd >/dev/null || \
105105
%files devel
106106
%defattr(-, root, root)
107107
%{_includedir}/tox/
108+
%{_includedir}/toxav/
109+
%{_includedir}/toxcore/
110+
%{_includedir}/toxencryptsave/
108111
%{_libdir}/pkgconfig/toxcore.pc
109112

110113
%files static

testing/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
22

33
CIMPLE_FILES = [
4+
"//c-toxcore:legacy_headers",
45
"//c-toxcore/toxav:cimple_files",
56
"//c-toxcore/toxcore:cimple_files",
67
"//c-toxcore/toxencryptsave:cimple_files",

tox/tox.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* SPDX-License-Identifier: GPL-3.0-or-later
2+
* Copyright © 2024 The TokTok team.
3+
*/
4+
#include "../toxcore/tox.h"

tox/toxav.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* SPDX-License-Identifier: GPL-3.0-or-later
2+
* Copyright © 2024 The TokTok team.
3+
*/
4+
#include "../toxav/toxav.h"

tox/toxencryptsave.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* SPDX-License-Identifier: GPL-3.0-or-later
2+
* Copyright © 2024 The TokTok team.
3+
*/
4+
#include "../toxencryptsave/toxencryptsave.h"

0 commit comments

Comments
 (0)