Skip to content

Include paths broken when using experimental SHA256 support #7199

@atufankjian

Description

@atufankjian

Correct me if I'm wrong but I think there's an issue here:

FILE(READ "${PROJECT_SOURCE_DIR}/include/git2.h" LIBGIT2_INCLUDE)
STRING(REGEX REPLACE "#include \"git2\/" "#include \"${LIBGIT2_FILENAME}/" LIBGIT2_INCLUDE "${LIBGIT2_INCLUDE}")
FILE(WRITE "${PROJECT_BINARY_DIR}/include/${LIBGIT2_FILENAME}.h" ${LIBGIT2_INCLUDE})

This regex needs to be applied to more than just git2.h. E.g. sys/alloc.h here references git2/common.h

#include "git2/common.h"

Seems like the CMake needs to do something more like:

# Replace `git/` with `git-experimental/` in all headers
# Also, write all headers to the project binary dir; any of them could have been modified
foreach(HEADER_SOURCE ${SRC_H})
  # Compute desired path in the binary dir
  FILE(RELATIVE_PATH HEADER_RELATIVE ${PROJECT_SOURCE_DIR} ${HEADER_SOURCE})
  FILE(REAL_PATH ${HEADER_RELATIVE} HEADER_OUT BASE_DIRECTORY ${PROJECT_BINARY_DIR})

  FILE(READ "${HEADER_SOURCE}" HEADER_CONTENTS)
  STRING(REGEX REPLACE "#include \"git2\/" "#include \"${LIBGIT2_FILENAME}/" HEADER_CONTENTS "${HEADER_CONTENTS}")
  FILE(WRITE "${HEADER_OUT}" ${HEADER_CONTENTS})
endforeach()

# Rename git2.h after the regex & move
FILE(RENAME "${PROJECT_BINARY_DIR}/include/git2.h" "${PROJECT_BINARY_DIR}/include/${LIBGIT2_FILENAME}.h")

And I guess we'd need to make a change here too

install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/git2/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBGIT2_FILENAME}")

install(DIRECTORY ${PROJECT_BINARY_DIR}/include/git2/
        DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBGIT2_FILENAME}")

I have run into this issue on a project. We want to use libgit2's experimental SHA256 support but without a normal version of libgit2 installed next to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions