Skip to content

Commit

Permalink
Separate public include headers
Browse files Browse the repository at this point in the history
  • Loading branch information
HexDecimal committed Nov 2, 2024
1 parent 16ba247 commit c7acf65
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 99 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ jobs:
wget --no-verbose https://github.com/Felerius/cpp-amalgamate/releases/download/1.0.1/cpp-amalgamate-x86_64-unknown-linux-gnu -O ~/cpp-amalgamate
chmod +x ~/cpp-amalgamate
- name: Generate source amalgam
run: ~/cpp-amalgamate -v src/libtcod-fov/*.c -o libtcod-fov.c
run: ~/cpp-amalgamate -v src/libtcod-fov/*.c --dir-quote include/libtcod-fov --unresolvable-quote-include error -o libtcod-fov.c
- name: Generate header amalgam
run: ~/cpp-amalgamate -v src/libtcod-fov.h -o libtcod-fov.h
run: ~/cpp-amalgamate -v include/libtcod-fov.h --unresolvable-quote-include error -o libtcod-fov.h
- name: Upload amalgams
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if(LIBTCODFOV_TOOLS)
list(APPEND VCPKG_MANIFEST_FEATURES "fovtool")
endif()

file(STRINGS src/libtcod-fov/version.h LIBTCODFOV_VERSION_LINE REGEX "TCODFOV_STRVERSION")
file(STRINGS include/libtcod-fov/version.h LIBTCODFOV_VERSION_LINE REGEX "TCODFOV_STRVERSION")
string(REGEX MATCH "TCODFOV_STRVERSION \"([^\"]+)\"" LIBTCODFOV_VERSION_LINE ${LIBTCODFOV_VERSION_LINE})
set(LIBTCODFOV_VERSION_FULL ${CMAKE_MATCH_1})
string(REGEX MATCH "([0-9]+\.[0-9]+\.[0-9]+)" LIBTCODFOV_VERSION ${LIBTCODFOV_VERSION_FULL})
Expand Down
2 changes: 1 addition & 1 deletion buildsys/autotools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ AM_LDFLAGS = $(SDL_LIBS) $(X11_LIBS) $(ZLIB_LIBS) $(SYSLIBS)
lib_LTLIBRARIES = libtcod-fov.la

libtcod_fov_root_includedir = $(includedir)
libtcod_fov_root_include_HEADERS = ../../src/libtcod-fov.h
libtcod_fov_root_include_HEADERS = ../../include/libtcod-fov.h

include $(srcdir)/sources.am

Expand Down
26 changes: 12 additions & 14 deletions buildsys/autotools/sources.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

libtcod_fov_includedir = $(includedir)/libtcod-fov
libtcod_fov_include_HEADERS = \
../../src/libtcod-fov/bresenham.h \
../../src/libtcod-fov/bresenham.hpp \
../../src/libtcod-fov/config.h \
../../src/libtcod-fov/error.h \
../../src/libtcod-fov/error.hpp \
../../src/libtcod-fov/fov.h \
../../src/libtcod-fov/fov.hpp \
../../src/libtcod-fov/fov_types.h \
../../src/libtcod-fov/libtcod_int.h \
../../src/libtcod-fov/logging.h \
../../src/libtcod-fov/map_inline.h \
../../src/libtcod-fov/map_types.h \
../../src/libtcod-fov/utility.h \
../../src/libtcod-fov/version.h
../../include/libtcod-fov/bresenham.h \
../../include/libtcod-fov/bresenham.hpp \
../../include/libtcod-fov/config.h \
../../include/libtcod-fov/error.h \
../../include/libtcod-fov/error.hpp \
../../include/libtcod-fov/fov.h \
../../include/libtcod-fov/fov.hpp \
../../include/libtcod-fov/fov_types.h \
../../include/libtcod-fov/logging.h \
../../include/libtcod-fov/map_inline.h \
../../include/libtcod-fov/map_types.h \
../../include/libtcod-fov/version.h

libtcod_fov_la_SOURCES = \
../../src/libtcod-fov/bresenham_c.c \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions scripts/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ignore = [
"ANN101", # missing-type-self
"ANN102", # missing-type-cls
"T20", # flake8-print
"COM", # flake8-commas
"ISC001", # single-line-implicit-string-concatenation
]

[tool.ruff.lint.pydocstyle] # https://docs.astral.sh/ruff/settings/#lintpydocstyle
Expand Down
3 changes: 2 additions & 1 deletion scripts/tag_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def parse_changelog(args: argparse.Namespace) -> tuple[str, str]:

def update_version_header(args: argparse.Namespace) -> None:
"""Update version.h to use the given tag."""
version_header_path: Final = Path("src/libtcod/version.h")
version_header_path: Final = Path("include/libtcod-fov/version.h")
match = re.match(
pattern=r"(?P<head>.*?)\n#define TCODFOV_MAJOR_VERSION.*?TCODFOV_STRVERSION[^\n]*\n(?P<tail>.*)",
string=version_header_path.read_text(encoding="utf-8"),
Expand Down Expand Up @@ -136,6 +136,7 @@ def main() -> None:
update_vcpkg_manifest(args)

replace_unreleased_tags(args.tag, PROJECT_DIR / "src", dry_run=args.dry_run)
replace_unreleased_tags(args.tag, PROJECT_DIR / "include", dry_run=args.dry_run)

if not args.dry_run:
CHANGELOG_PATH.write_text(new_changelog, encoding="utf-8")
Expand Down
7 changes: 5 additions & 2 deletions scripts/update_copyrights.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import argparse
import datetime
import itertools
import os
import re
from pathlib import Path
Expand Down Expand Up @@ -70,10 +71,12 @@ def main() -> None:

copyright = get_copyright(args)
# This avoids touching vendor files.
for file in os.listdir(PROJECT_DIR / "src"):
for file in os.listdir(PROJECT_DIR / "include"):
if RE_SOURCE_FILE.match(file):
update_file(PROJECT_DIR / "src" / file, copyright, args)
for dirpath, _, filenames in os.walk(PROJECT_DIR / "src/libtcod"):
for dirpath, _, filenames in itertools.chain(
os.walk(PROJECT_DIR / "src/libtcod-fov"), os.walk(PROJECT_DIR / "include")
):
for file in filenames:
if RE_SOURCE_FILE.match(file):
update_file(Path(dirpath, file), copyright, args)
Expand Down
33 changes: 9 additions & 24 deletions scripts/update_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@
BANNER = "# This file was automatically generated by scripts/update_sources.py"


VENDOR_SOURCES = ()

VENDOR_SOURCES_AUTOMAKE = ()


def get_sources(
*,
sources: bool = False,
includes: bool = False,
root: str | PathLike[str] = "src",
directory: str | PathLike[str] = "src/libtcod-fov",
vendor_sources: tuple[Path, ...] = VENDOR_SOURCES,
) -> Iterable[tuple[Path, Sequence[Path]]]:
"""Iterate over sources and headers with sub-folders grouped together."""
re_inclusion = []
Expand All @@ -43,20 +38,17 @@ def get_sources(
# Ignore hidden directories.
dirs[:] = [dir for dir in dirs if not dir.startswith(".")] # noqa: A001
files = [current_path / f for f in files_str if re_valid.match(f)]
group = current_path.relative_to("src")
group = current_path.relative_to(root, walk_up=False)
yield group, files
if sources and vendor_sources:
yield Path("vendor"), vendor_sources


def all_sources(
*,
sources: bool = True,
includes: bool = False,
vendor_sources: tuple[Path, ...] = VENDOR_SOURCES,
) -> Iterable[Path]:
"""Iterate over all sources needed to compile libtcod."""
for _, sources_ in get_sources(sources=sources, includes=includes, vendor_sources=vendor_sources):
for _, sources_ in get_sources(sources=sources, includes=includes):
yield from sources_


Expand All @@ -66,7 +58,9 @@ def generate_am() -> str:
This might be run on Windows, so it must return Unix file separators.
"""
out = f"{BANNER}\n"
for group_path, files_str in get_sources(sources=False, includes=True):
for group_path, files_str in get_sources(
sources=False, includes=True, root="include", directory="include/libtcod-fov"
):
group_posix = PurePosixPath(group_path)
include_name = str(group_posix).replace("/", "_").replace("-", "_")
files = [str(PurePosixPath("../..", f)) for f in files_str]
Expand All @@ -76,9 +70,7 @@ def generate_am() -> str:
out += "\n"

out += "\nlibtcod_fov_la_SOURCES = \\"
out += "\n\t" + " \\\n\t".join(
str(PurePosixPath("../..", f)) for f in all_sources(vendor_sources=VENDOR_SOURCES_AUTOMAKE)
)
out += "\n\t" + " \\\n\t".join(str(PurePosixPath("../..", f)) for f in all_sources())
out += "\n"
return out

Expand All @@ -89,20 +81,13 @@ def generate_cmake() -> str:
out += "\ntarget_sources(${PROJECT_NAME} PRIVATE\n "
out += "\n ".join(str(PurePosixPath(f.relative_to("src"))) for f in all_sources(includes=True))
out += "\n)"
for group_path, files in get_sources(sources=False, includes=True, directory=Path("src/")):
for group_path, files in get_sources(sources=False, includes=True, root="include", directory="include"):
group_posix = PurePosixPath(group_path)
if str(group_posix).startswith("vendor"):
continue
out += "\ninstall(FILES\n "
out += "\n ".join(str(PurePosixPath(f.relative_to("src"))) for f in files)
out += "\n ".join(str(PurePosixPath(f.relative_to("src", walk_up=True))) for f in files)
out += f"\n DESTINATION ${{CMAKE_INSTALL_INCLUDEDIR}}/{group_posix}"
out += "\n COMPONENT IncludeFiles"
out += "\n)"
for group_path, files in get_sources(sources=True, includes=True):
group_str = str(PurePosixPath(group_path)).replace("/", r"\\")
out += f"\nsource_group({group_str} FILES\n "
out += "\n ".join(str(PurePosixPath(f.relative_to("src"))) for f in files)
out += "\n)"
out += "\n"
return out

Expand Down
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD_REQUIRED TRUE)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED TRUE)

target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include/libtcod-fov>
)

target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
)

if(BUILD_SHARED_LIBS)
Expand Down
66 changes: 13 additions & 53 deletions src/sources.cmake
Original file line number Diff line number Diff line change
@@ -1,76 +1,36 @@
# This file was automatically generated by scripts/update_sources.py
target_sources(${PROJECT_NAME} PRIVATE
libtcod-fov/bresenham.h
libtcod-fov/bresenham.hpp
libtcod-fov/bresenham_c.c
libtcod-fov/config.h
libtcod-fov/error.c
libtcod-fov/error.h
libtcod-fov/error.hpp
libtcod-fov/fov.h
libtcod-fov/fov.hpp
libtcod-fov/fov_c.c
libtcod-fov/fov_circular_raycasting.c
libtcod-fov/fov_diamond_raycasting.c
libtcod-fov/fov_permissive2.c
libtcod-fov/fov_recursive_shadowcasting.c
libtcod-fov/fov_restrictive.c
libtcod-fov/fov_symmetric_shadowcast.c
libtcod-fov/fov_types.h
libtcod-fov/libtcod_int.h
libtcod-fov/logging.c
libtcod-fov/logging.h
libtcod-fov/map_inline.h
libtcod-fov/map_types.h
libtcod-fov/utility.h
libtcod-fov/version.h
)
install(FILES
libtcod-fov.h
../include/libtcod-fov.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/.
COMPONENT IncludeFiles
)
install(FILES
libtcod-fov/bresenham.h
libtcod-fov/bresenham.hpp
libtcod-fov/config.h
libtcod-fov/error.h
libtcod-fov/error.hpp
libtcod-fov/fov.h
libtcod-fov/fov.hpp
libtcod-fov/fov_types.h
libtcod-fov/libtcod_int.h
libtcod-fov/logging.h
libtcod-fov/map_inline.h
libtcod-fov/map_types.h
libtcod-fov/utility.h
libtcod-fov/version.h
../include/libtcod-fov/bresenham.h
../include/libtcod-fov/bresenham.hpp
../include/libtcod-fov/config.h
../include/libtcod-fov/error.h
../include/libtcod-fov/error.hpp
../include/libtcod-fov/fov.h
../include/libtcod-fov/fov.hpp
../include/libtcod-fov/fov_types.h
../include/libtcod-fov/logging.h
../include/libtcod-fov/map_inline.h
../include/libtcod-fov/map_types.h
../include/libtcod-fov/version.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libtcod-fov
COMPONENT IncludeFiles
)
source_group(libtcod-fov FILES
libtcod-fov/bresenham.h
libtcod-fov/bresenham.hpp
libtcod-fov/bresenham_c.c
libtcod-fov/config.h
libtcod-fov/error.c
libtcod-fov/error.h
libtcod-fov/error.hpp
libtcod-fov/fov.h
libtcod-fov/fov.hpp
libtcod-fov/fov_c.c
libtcod-fov/fov_circular_raycasting.c
libtcod-fov/fov_diamond_raycasting.c
libtcod-fov/fov_permissive2.c
libtcod-fov/fov_recursive_shadowcasting.c
libtcod-fov/fov_restrictive.c
libtcod-fov/fov_symmetric_shadowcast.c
libtcod-fov/fov_types.h
libtcod-fov/libtcod_int.h
libtcod-fov/logging.c
libtcod-fov/logging.h
libtcod-fov/map_inline.h
libtcod-fov/map_types.h
libtcod-fov/utility.h
libtcod-fov/version.h
)

0 comments on commit c7acf65

Please sign in to comment.