From 29a715ae6b35cae9f541ceae9cc7bb00d75bf170 Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Thu, 5 Mar 2026 01:34:34 +0000 Subject: [PATCH] Support building under /build/ directories Github PR 247[0] changed the way that wangle chose which headers to install. As part of this, certain directories, for example `/build/`, were filtered out. Unfortunately this filtering is performed on the absolute path of the source code. If wangle is cloned underneath any directory which matches one of the filtered directories, then all the header files will be filtered out and no headers installed. Fix this by changing the initial list to be relative to the source directory such that the filtering cannot mistakenly match on paths outside the wangle source tree. [0] https://github.com/facebook/wangle/pull/247 --- wangle/CMakeLists.txt | 20 +++++++++++--------- wangle/cmake/WangleFunctions.cmake | 22 ++++++++-------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/wangle/CMakeLists.txt b/wangle/CMakeLists.txt index 1655b55bc..38f65c014 100644 --- a/wangle/CMakeLists.txt +++ b/wangle/CMakeLists.txt @@ -148,20 +148,22 @@ install( # ============================================================================= # Collect all headers via recursive glob (like folly/fizz does) -file(GLOB_RECURSE WANGLE_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h") +file(GLOB_RECURSE WANGLE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "${CMAKE_CURRENT_SOURCE_DIR}/*.h") # Filter out test, facebook, and other non-public directories -list(FILTER WANGLE_HEADERS EXCLUDE REGEX "/test/") -list(FILTER WANGLE_HEADERS EXCLUDE REGEX "/facebook/") -list(FILTER WANGLE_HEADERS EXCLUDE REGEX "/build/") -list(FILTER WANGLE_HEADERS EXCLUDE REGEX "/example/") +list(FILTER WANGLE_HEADERS EXCLUDE REGEX "(^|/)test/") +list(FILTER WANGLE_HEADERS EXCLUDE REGEX "(^|/)facebook/") +list(FILTER WANGLE_HEADERS EXCLUDE REGEX "(^|/)build/") +list(FILTER WANGLE_HEADERS EXCLUDE REGEX "(^|/)example/") # Collect test headers separately -file(GLOB_RECURSE WANGLE_TEST_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h") -list(FILTER WANGLE_TEST_HEADERS INCLUDE REGEX "/test/") -list(FILTER WANGLE_TEST_HEADERS EXCLUDE REGEX "/facebook/") +file(GLOB_RECURSE WANGLE_TEST_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "${CMAKE_CURRENT_SOURCE_DIR}/*.h") +list(FILTER WANGLE_TEST_HEADERS INCLUDE REGEX "(^|/)test/") +list(FILTER WANGLE_TEST_HEADERS EXCLUDE REGEX "(^|/)facebook/") # Install headers preserving directory structure -wangle_install_headers(wangle ${CMAKE_CURRENT_SOURCE_DIR} ${WANGLE_HEADERS}) +wangle_install_headers(wangle . ${WANGLE_HEADERS}) # ============================================================================= # CMake package configuration diff --git a/wangle/cmake/WangleFunctions.cmake b/wangle/cmake/WangleFunctions.cmake index c0e51e9ef..a4c1c57ed 100644 --- a/wangle/cmake/WangleFunctions.cmake +++ b/wangle/cmake/WangleFunctions.cmake @@ -13,26 +13,20 @@ # limitations under the License. # Install header files preserving directory structure -# Similar to folly's auto_install_files() function(wangle_install_headers rootName rootDir) file(TO_CMAKE_PATH "${rootDir}" rootDir) - string(LENGTH "${rootDir}" rootDirLength) foreach(fil ${ARGN}) file(TO_CMAKE_PATH "${fil}" filePath) - string(FIND "${filePath}" "/" rIdx REVERSE) - if(rIdx EQUAL -1) + + # dirname $fil + string(FIND "${filePath}" "/" lastSlash REVERSE) + if(lastSlash EQUAL -1) continue() endif() - string(SUBSTRING "${filePath}" 0 ${rIdx} filePath) - - string(LENGTH "${filePath}" filePathLength) - string(FIND "${filePath}" "${rootDir}" rIdx) - if(rIdx EQUAL 0) - math(EXPR filePathLength "${filePathLength} - ${rootDirLength}") - string(SUBSTRING "${filePath}" ${rootDirLength} ${filePathLength} fileGroup) - install(FILES ${fil} - DESTINATION ${INCLUDE_INSTALL_DIR}/${rootName}${fileGroup}) - endif() + string(SUBSTRING "${filePath}" 0 ${lastSlash} dirName) + + install(FILES ${rootDir}/${fil} + DESTINATION ${INCLUDE_INSTALL_DIR}/${rootName}/${dirName}) endforeach() endfunction()