Skip to content

Commit

Permalink
refactor: Install headers into repo-equivalent directories.
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
iphydf committed Jan 31, 2024
1 parent 511bfe3 commit 74eaa35
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 28 deletions.
31 changes: 16 additions & 15 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@ load("//tools/project:build_defs.bzl", "project")

project(license = "gpl3-https")

genrule(
filegroup(
name = "legacy_headers",
srcs = [
"tox/tox.h",
"tox/toxav.h",
"tox/toxencryptsave.h",
],
visibility = ["//visibility:public"],
)

filegroup(
name = "public_headers",
srcs = [
"//c-toxcore/toxav:toxav.h",
"//c-toxcore/toxcore:tox.h",
"//c-toxcore/toxcore:tox_private.h",
"//c-toxcore/toxencryptsave:toxencryptsave.h",
],
outs = [
"tox/toxav.h",
"tox/tox.h",
"tox/tox_private.h",
"tox/toxencryptsave.h",
],
cmd = """
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
cp $(location //c-toxcore/toxcore:tox.h) $(GENDIR)/c-toxcore/tox/tox.h
cp $(location //c-toxcore/toxcore:tox_private.h) $(GENDIR)/c-toxcore/tox/tox_private.h
cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h
""",
visibility = ["//visibility:public"],
)

cc_library(
name = "c-toxcore",
hdrs = [":public_headers"],
includes = ["."],
hdrs = [
":legacy_headers",
":public_headers",
],
strip_include_prefix = ".",
visibility = ["//visibility:public"],
deps = [
"//c-toxcore/toxav",
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ else()
endif()
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
set(toxcore_API_HEADERS
${toxcore_SOURCE_DIR}/tox/tox.h^tox
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox
Expand Down Expand Up @@ -386,6 +387,7 @@ if(BUILD_TOXAV)
toxav/video.c
toxav/video.h)
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
${toxcore_SOURCE_DIR}/tox/toxav.h^toxav
${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)

if(MSVC)
Expand All @@ -409,6 +411,7 @@ set(toxcore_SOURCES ${toxcore_SOURCES}
toxencryptsave/toxencryptsave.c
toxencryptsave/toxencryptsave.h)
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
${toxcore_SOURCE_DIR}/tox/toxencryptsave.h^tox
${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)

################################################################################
Expand Down Expand Up @@ -490,8 +493,8 @@ endif()
make_version_script(toxcore ${toxcore_API_HEADERS})

# Generate pkg-config file, install library to "${CMAKE_INSTALL_LIBDIR}" and install headers to
# "${CMAKE_INSTALL_INCLUDEDIR}/tox".
install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
# "${CMAKE_INSTALL_INCLUDEDIR}".
install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

################################################################################
#
Expand Down
6 changes: 5 additions & 1 deletion cmake/ModulePackage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if(FULLY_STATIC)
endif()

function(install_module lib)
cmake_parse_arguments(INSTALL_MODULE "" "DESTINATION" "" ${ARGN})
if(TARGET ${lib}_shared)
set_target_properties(${lib}_shared PROPERTIES
VERSION ${SOVERSION}
Expand Down Expand Up @@ -59,7 +60,10 @@ function(install_module lib)
foreach(sublib ${${lib}_API_HEADERS})
string(REPLACE "^" ";" sublib ${sublib})
list(GET sublib 0 header)
string(REPLACE "${${lib}_SOURCE_DIR}/" "" target_header ${header})
get_filename_component(target_path ${target_header} DIRECTORY)

install(FILES ${header} ${ARGN})
install(FILES ${header} DESTINATION
"${INSTALL_MODULE_DESTINATION}/${target_path}")
endforeach()
endfunction()
12 changes: 7 additions & 5 deletions cmake/StrictAbi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ function(_make_version_script target)
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"
OUTPUT_VARIABLE sublib_SYMS
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS})
if(sublib_SYMS)
string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS})

foreach(sym ${sublib_SYMS})
file(APPEND ${${target}_VERSION_SCRIPT}
"${sym};\n")
endforeach(sym)
foreach(sym ${sublib_SYMS})
file(APPEND ${${target}_VERSION_SCRIPT}
"${sym};\n")
endforeach(sym)
endif()
endforeach(sublib)

file(APPEND ${${target}_VERSION_SCRIPT}
Expand Down
1 change: 1 addition & 0 deletions testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

CIMPLE_FILES = [
"//c-toxcore:legacy_headers",
"//c-toxcore/toxav:cimple_files",
"//c-toxcore/toxcore:cimple_files",
"//c-toxcore/toxencryptsave:cimple_files",
Expand Down
4 changes: 4 additions & 0 deletions tox/tox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2024 The TokTok team.
*/
#include "../toxcore/tox.h"
4 changes: 4 additions & 0 deletions tox/toxav.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2024 The TokTok team.
*/
#include "../toxav/toxav.h"
4 changes: 4 additions & 0 deletions tox/toxencryptsave.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2024 The TokTok team.
*/
#include "../toxencryptsave/toxencryptsave.h"
2 changes: 0 additions & 2 deletions toxav/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ cc_library(
hdrs = ["bwcontroller.h"],
deps = [
":ring_buffer",
"//c-toxcore/toxcore",
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
Expand Down Expand Up @@ -129,7 +128,6 @@ cc_library(
srcs = ["groupav.c"],
hdrs = ["groupav.h"],
deps = [
"//c-toxcore/toxcore",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:group",
"//c-toxcore/toxcore:logger",
Expand Down
6 changes: 3 additions & 3 deletions toxcore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,10 @@ cc_library(
],
)

alias(
cc_library(
name = "toxcore",
actual = ":tox_dispatch",
visibility = ["//c-toxcore:__subpackages__"],
visibility = ["//c-toxcore:__pkg__"],
deps = [":tox_dispatch"],
)

sh_library(
Expand Down

0 comments on commit 74eaa35

Please sign in to comment.