Skip to content

Commit 0c2dcc9

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 5c093c4 commit 0c2dcc9

File tree

10 files changed

+48
-28
lines changed

10 files changed

+48
-28
lines changed

BUILD.bazel

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ 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",
11-
"//c-toxcore/toxcore:tox_private.h",
1221
"//c-toxcore/toxencryptsave:toxencryptsave.h",
1322
],
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-
""",
2623
visibility = ["//visibility:public"],
2724
)
2825

2926
cc_library(
3027
name = "c-toxcore",
31-
hdrs = [":public_headers"],
28+
hdrs = [
29+
":legacy_headers",
30+
":public_headers",
31+
],
3232
includes = ["."],
3333
visibility = ["//visibility:public"],
3434
deps = [

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ else()
355355
endif()
356356
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
357357
set(toxcore_API_HEADERS
358+
${toxcore_SOURCE_DIR}/tox/tox.h^tox
358359
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
359360
${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox
360361
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox
@@ -386,6 +387,7 @@ if(BUILD_TOXAV)
386387
toxav/video.c
387388
toxav/video.h)
388389
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
390+
${toxcore_SOURCE_DIR}/tox/toxav.h^toxav
389391
${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
390392

391393
if(MSVC)
@@ -409,6 +411,7 @@ set(toxcore_SOURCES ${toxcore_SOURCES}
409411
toxencryptsave/toxencryptsave.c
410412
toxencryptsave/toxencryptsave.h)
411413
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
414+
${toxcore_SOURCE_DIR}/tox/toxencryptsave.h^tox
412415
${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)
413416

414417
################################################################################
@@ -490,8 +493,8 @@ endif()
490493
make_version_script(toxcore ${toxcore_API_HEADERS})
491494

492495
# Generate pkg-config file, install library to "${CMAKE_INSTALL_LIBDIR}" and install headers to
493-
# "${CMAKE_INSTALL_INCLUDEDIR}/tox".
494-
install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
496+
# "${CMAKE_INSTALL_INCLUDEDIR}".
497+
install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
495498

496499
################################################################################
497500
#

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}

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"

toxav/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ cc_library(
4747
hdrs = ["bwcontroller.h"],
4848
deps = [
4949
":ring_buffer",
50-
"//c-toxcore/toxcore",
5150
"//c-toxcore/toxcore:Messenger",
5251
"//c-toxcore/toxcore:ccompat",
5352
"//c-toxcore/toxcore:logger",
@@ -129,7 +128,6 @@ cc_library(
129128
srcs = ["groupav.c"],
130129
hdrs = ["groupav.h"],
131130
deps = [
132-
"//c-toxcore/toxcore",
133131
"//c-toxcore/toxcore:ccompat",
134132
"//c-toxcore/toxcore:group",
135133
"//c-toxcore/toxcore:logger",

toxcore/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,10 +982,10 @@ cc_library(
982982
],
983983
)
984984

985-
alias(
985+
cc_library(
986986
name = "toxcore",
987-
actual = ":tox_dispatch",
988-
visibility = ["//c-toxcore:__subpackages__"],
987+
visibility = ["//c-toxcore:__pkg__"],
988+
deps = [":tox_dispatch"],
989989
)
990990

991991
sh_library(

0 commit comments

Comments
 (0)