From b1b421fe4baddb698d91584f243ab720e8347c0a Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Fri, 15 May 2026 13:09:33 +0100 Subject: [PATCH] cmake: separate generated headers from translated headers Make a distinction between generated headers and "translated" headers. This is important to support build-time dependencies when headers are updated. Generated headers are those which contain build-time feature specifications, like `git2_features.h` that are internal to the build and `experimental.h` that contain API information. Translated headers are the headers that are in `include/git2`, but may be translated to have a unique prefix like `incklude/git2-experimental`. This distinction is important so that the CMakeFiles.txt depend on the in-tree include files (`src/include`) and the generated header files _but not_ the translated header files. Otherwise there are two `pack.h` and it's unclear whether the in-tree build is targeting the one in `src/include` or the one in the build tree. Without this, updating an in-tree header file like `pack.h` would not cause a rebuild of its dependencies. --- deps/reftable/CMakeLists.txt | 8 +++----- deps/xdiff/CMakeLists.txt | 2 +- src/cli/CMakeLists.txt | 3 +-- src/libgit2/CMakeLists.txt | 9 +++++---- src/util/CMakeLists.txt | 7 +++---- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/deps/reftable/CMakeLists.txt b/deps/reftable/CMakeLists.txt index e096e71e2..cdebf5c5b 100644 --- a/deps/reftable/CMakeLists.txt +++ b/deps/reftable/CMakeLists.txt @@ -8,14 +8,12 @@ list(SORT SRC_REFTABLE) set_property(TARGET reftable PROPERTY C_STANDARD 99) target_sources(reftable PRIVATE ${SRC_REFTABLE}) target_include_directories(reftable PRIVATE - include - "${PROJECT_BINARY_DIR}/src/util" - "${PROJECT_BINARY_DIR}/include" + "include" "${PROJECT_SOURCE_DIR}/src/util" "${PROJECT_SOURCE_DIR}/include" + "${PROJECT_BINARY_DIR}/gen_headers" ${LIBGIT2_DEPENDENCY_INCLUDES} - ${LIBGIT2_SYSTEM_INCLUDES} -) + ${LIBGIT2_SYSTEM_INCLUDES}) # The reftable library is not warning-free, so we disable turning warnings into # errors. diff --git a/deps/xdiff/CMakeLists.txt b/deps/xdiff/CMakeLists.txt index 743ac636f..82af0fad5 100644 --- a/deps/xdiff/CMakeLists.txt +++ b/deps/xdiff/CMakeLists.txt @@ -6,7 +6,7 @@ add_library(xdiff OBJECT ${SRC_XDIFF}) target_include_directories(xdiff SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/src/util" - "${PROJECT_BINARY_DIR}/src/util" + "${PROJECT_BINARY_DIR}/gen_headers" ${LIBGIT2_SYSTEM_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES}) diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index d121c588a..517ede8ca 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -1,9 +1,8 @@ set(CLI_INCLUDES - "${libgit2_BINARY_DIR}/src/util" - "${libgit2_BINARY_DIR}/include" "${libgit2_SOURCE_DIR}/src/util" "${libgit2_SOURCE_DIR}/src/cli" "${libgit2_SOURCE_DIR}/include" + "${libgit2_BINARY_DIR}/gen_headers" "${LIBGIT2_DEPENDENCY_INCLUDES}" "${LIBGIT2_SYSTEM_INCLUDES}") diff --git a/src/libgit2/CMakeLists.txt b/src/libgit2/CMakeLists.txt index c9b642ec9..8045ddef9 100644 --- a/src/libgit2/CMakeLists.txt +++ b/src/libgit2/CMakeLists.txt @@ -7,11 +7,10 @@ include(PkgBuildConfig) include(CMakePackageConfigHelpers) set(LIBGIT2_INCLUDES - "${PROJECT_BINARY_DIR}/src/util" - "${PROJECT_BINARY_DIR}/include" "${PROJECT_SOURCE_DIR}/src/libgit2" "${PROJECT_SOURCE_DIR}/src/util" - "${PROJECT_SOURCE_DIR}/include") + "${PROJECT_SOURCE_DIR}/include" + "${PROJECT_BINARY_DIR}/gen_headers") # Collect sourcefiles file(GLOB SRC_H @@ -104,7 +103,7 @@ endif() # support experimental features and functionality -configure_file(experimental.h.in "${PROJECT_BINARY_DIR}/include/${LIBGIT2_FILENAME}/experimental.h") +configure_file(experimental.h.in "${PROJECT_BINARY_DIR}/gen_headers/experimental.h") # translate filenames in the headers so that they match the install directory # (allows for side-by-side installs of libgit2 and libgit2-experimental.) @@ -120,6 +119,8 @@ foreach(HEADER_SOURCE ${SRC_H}) configure_file("${CMAKE_CURRENT_BINARY_DIR}/${HEADER_RELATIVE}.tmp" "${PROJECT_BINARY_DIR}/${HEADER_RELATIVE}" COPYONLY) endforeach() +configure_file("${PROJECT_BINARY_DIR}/gen_headers/experimental.h" "${PROJECT_BINARY_DIR}/include/${LIBGIT2_FILENAME}/experimental.h" COPYONLY) + # cmake package targets set(LIBGIT2_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 0811057f3..090cd8bf9 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -2,13 +2,12 @@ add_library(util OBJECT) -configure_file(git2_features.h.in git2_features.h) +configure_file(git2_features.h.in "${PROJECT_BINARY_DIR}/gen_headers/git2_features.h") set(UTIL_INCLUDES - "${PROJECT_BINARY_DIR}/src/util" - "${PROJECT_BINARY_DIR}/include" "${PROJECT_SOURCE_DIR}/src/util" - "${PROJECT_SOURCE_DIR}/include") + "${PROJECT_SOURCE_DIR}/include" + "${PROJECT_BINARY_DIR}/gen_headers") file(GLOB UTIL_SRC *.c *.h allocators/*.c allocators/*.h hash.h) list(SORT UTIL_SRC)