Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Install headers into repo-equivalent directories. #2599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -359,6 +359,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 @@ -393,6 +394,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 @@ -416,6 +418,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 @@ -497,8 +500,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 other/bootstrap_daemon/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ COPY other/DHT_bootstrap.c other/
COPY other/pkgconfig other/pkgconfig
COPY other/rpm other/rpm
COPY testing/misc_tools.[ch] testing/
COPY tox tox
COPY toxcore toxcore
COPY toxencryptsave toxencryptsave
COPY third_party third_party
Expand Down
3 changes: 3 additions & 0 deletions other/rpm/toxcore.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ getent passwd tox-bootstrapd >/dev/null || \
%files devel
%defattr(-, root, root)
%{_includedir}/tox/
%{_includedir}/toxav/
%{_includedir}/toxcore/
%{_includedir}/toxencryptsave/
%{_libdir}/pkgconfig/toxcore.pc

%files static
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 @@ -1116,10 +1116,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
Loading