Rewrite prefixed libowfat exported header includes

This commit is contained in:
Mario Fetka
2026-06-03 11:23:17 +00:00
parent 610fed2936
commit 9c4faae381
2 changed files with 41 additions and 7 deletions

View File

@@ -85,10 +85,29 @@ set(_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(_generated_libowfat_dir "${_generated_dir}/libowfat")
file(MAKE_DIRECTORY "${_generated_libowfat_dir}" "${LIBOWFAT_BUILD_PUBLIC_INCLUDE_DIR}")
function(_libowfat_rewrite_public_includes out_var content)
set(_rewritten "${content}")
if(NOT LIBOWFAT_INSTALL_INCLUDE_SUBDIR STREQUAL "libowfat")
string(REPLACE "<libowfat/" "<${LIBOWFAT_INSTALL_INCLUDE_SUBDIR}/" _rewritten "${_rewritten}")
string(REPLACE "\"libowfat/" "\"${LIBOWFAT_INSTALL_INCLUDE_SUBDIR}/" _rewritten "${_rewritten}")
endif()
set(${out_var} "${_rewritten}" PARENT_SCOPE)
endfunction()
function(_write_public_header name content)
_libowfat_rewrite_public_includes(_public_content "${content}")
file(WRITE "${LIBOWFAT_BUILD_PUBLIC_INCLUDE_DIR}/${name}" "${_public_content}")
endfunction()
function(_write_generated_header name content)
file(WRITE "${_generated_dir}/${name}" "${content}")
file(WRITE "${_generated_libowfat_dir}/${name}" "${content}")
file(WRITE "${LIBOWFAT_BUILD_PUBLIC_INCLUDE_DIR}/${name}" "${content}")
_write_public_header("${name}" "${content}")
endfunction()
function(_copy_public_header input name)
file(READ "${input}" _header_content)
_write_public_header("${name}" "${_header_content}")
endfunction()
function(_write_feature_header name content_if_true)
@@ -137,20 +156,20 @@ _write_generated_header(havealloca.h "${_havealloca_content}")
if(HAVE_POLL)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/iopause.h2" "${_generated_dir}/iopause.h" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/iopause.h2" "${_generated_libowfat_dir}/iopause.h" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/iopause.h2" "${LIBOWFAT_BUILD_PUBLIC_INCLUDE_DIR}/iopause.h" COPYONLY)
_copy_public_header("${CMAKE_CURRENT_SOURCE_DIR}/iopause.h2" iopause.h)
else()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/iopause.h1" "${_generated_dir}/iopause.h" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/iopause.h1" "${_generated_libowfat_dir}/iopause.h" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/iopause.h1" "${LIBOWFAT_BUILD_PUBLIC_INCLUDE_DIR}/iopause.h" COPYONLY)
_copy_public_header("${CMAKE_CURRENT_SOURCE_DIR}/iopause.h1" iopause.h)
endif()
if(HAVE_SYS_SELECT_H)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/select.h2" "${_generated_dir}/select.h" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/select.h2" "${_generated_libowfat_dir}/select.h" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/select.h2" "${LIBOWFAT_BUILD_PUBLIC_INCLUDE_DIR}/select.h" COPYONLY)
_copy_public_header("${CMAKE_CURRENT_SOURCE_DIR}/select.h2" select.h)
else()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/select.h1" "${_generated_dir}/select.h" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/select.h1" "${_generated_libowfat_dir}/select.h" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/select.h1" "${LIBOWFAT_BUILD_PUBLIC_INCLUDE_DIR}/select.h" COPYONLY)
_copy_public_header("${CMAKE_CURRENT_SOURCE_DIR}/select.h1" select.h)
endif()
add_executable(libowfat_ent EXCLUDE_FROM_ALL "${CMAKE_CURRENT_SOURCE_DIR}/ent.c")
@@ -182,10 +201,10 @@ set(LIBOWFAT_PUBLIC_HEADERS
foreach(_hdr IN LISTS LIBOWFAT_PUBLIC_HEADERS)
if(EXISTS "${_generated_dir}/${_hdr}")
configure_file("${_generated_dir}/${_hdr}" "${_generated_libowfat_dir}/${_hdr}" COPYONLY)
configure_file("${_generated_dir}/${_hdr}" "${LIBOWFAT_BUILD_PUBLIC_INCLUDE_DIR}/${_hdr}" COPYONLY)
_copy_public_header("${_generated_dir}/${_hdr}" "${_hdr}")
else()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${_hdr}" "${_generated_libowfat_dir}/${_hdr}" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${_hdr}" "${LIBOWFAT_BUILD_PUBLIC_INCLUDE_DIR}/${_hdr}" COPYONLY)
_copy_public_header("${CMAKE_CURRENT_SOURCE_DIR}/${_hdr}" "${_hdr}")
endif()
endforeach()

View File

@@ -109,3 +109,18 @@ be enabled explicitly:
-DLIBOWFAT_BUILD_TEST_PROGRAMS=ON
-DLIBOWFAT_RUN_SELF_TESTS=ON
```
### Prefixed CMake header exports
When `LIBOWFAT_LIBRARY_PREFIX` is set, CMake exports public headers below a
matching include directory, for example `nwlibowfat`. The original sources and
internal build include tree still keep the upstream `libowfat` layout, but the
public build/install header copies are rewritten so their nested includes also
use the selected directory name. For example:
```c
#include <nwlibowfat/buffer.h>
```
will include other libowfat headers through `nwlibowfat/...`, avoiding conflicts
with a system-installed `libowfat` header set.