From 0f25b75c81fcccf4027e958e8cef6a105c52aacf Mon Sep 17 00:00:00 2001 From: sentomk Date: Thu, 19 Nov 2026 00:37:07 +0800 Subject: [PATCH] fix(cmake): install every public header v0.9.6 added four headers (index_switch.hpp, inline.hpp, owned_eval.hpp, plain_value.hpp) that were missing from the hand-written header list in CMakeLists.txt. cmake --install, and so the vcpkg port, left them out, and including ptn/patternia.hpp from an installed copy failed with a missing-file error. Collect the headers with file(GLOB_RECURSE) instead of a list, and add the install.consumer CTest test: it installs the build tree into a scratch prefix, checks that every header under include/ was installed, and builds and runs a consumer that uses find_package(patternia). --- CMakeLists.txt | 63 ++++--------------------- tests/CMakeLists.txt | 18 +++++++ tests/install/consumer/CMakeLists.txt | 7 +++ tests/install/consumer/main.cpp | 23 +++++++++ tests/install/run_install_test.cmake | 67 +++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 55 deletions(-) create mode 100644 tests/install/consumer/CMakeLists.txt create mode 100644 tests/install/consumer/main.cpp create mode 100644 tests/install/run_install_test.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b4a5ac5..9a83ec1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,16 +52,6 @@ function(PTN_GENERATE_DUMMY_SOURCE OUT_ABS_PATH) set(${OUT_ABS_PATH} "${_path}" PARENT_SCOPE) endfunction() -function(PTN_JOIN_HEADERS OUT_VAR) - set(_accum) - - foreach(_h IN LISTS ARGN) - list(APPEND _accum "${_h}") - endforeach() - - set(${OUT_VAR} "${_accum}" PARENT_SCOPE) -endfunction() - # ========== Master project detection and defaulted options ========== PTN_IS_MASTER_PROJECT(_PTN_MASTER_PROJECT) PTN_SET_IF_UNDEFINED(PTN_MASTER_PROJECT ${_PTN_MASTER_PROJECT}) @@ -76,52 +66,15 @@ option(PTN_DEV_INDEX "Create local indexable target for IDEs (not installed)" ON option(PTN_SKIP_COMPILER_CHECK "Skip compiler version check" OFF) # ========== Public headers ========== -PTN_JOIN_HEADERS(PTN_HEADERS - include/ptn/patternia.hpp - - # Core Layer - include/ptn/core/fwd.h - include/ptn/core/common/common_traits.hpp - include/ptn/core/common/diagnostics.hpp - include/ptn/core/common/eval.hpp - include/ptn/core/common/optimize.hpp - include/ptn/core/engine/match.hpp - include/ptn/core/engine/detail/pipeline_match_context.hpp - include/ptn/core/engine/detail/match_impl.hpp - include/ptn/core/dsl/case_expr.hpp - include/ptn/core/dsl/ops.hpp - include/ptn/core/dsl/detail/case_expr_impl.hpp - include/ptn/core/dsl/detail/expression_handler.hpp - - # Meta Utils - include/ptn/meta/meta.hpp - include/ptn/meta/base/traits.hpp - include/ptn/meta/dsa/algorithms.hpp - include/ptn/meta/dsa/type_list.hpp - include/ptn/meta/query/index.hpp - include/ptn/meta/query/template_info.hpp - - # Pattern Base - include/ptn/pattern/base/fwd.h - include/ptn/pattern/base/binding_base.hpp - include/ptn/pattern/base/binding_traits.hpp - include/ptn/pattern/base/pattern_base.hpp - include/ptn/pattern/base/pattern_kind.hpp - include/ptn/pattern/base/pattern_traits.hpp - - # Pattern Module Headers - include/ptn/pattern/lit.hpp - include/ptn/pattern/bind.hpp - include/ptn/pattern/type.hpp - include/ptn/pattern/wildcard.hpp - include/ptn/pattern/structural.hpp - include/ptn/pattern/combinator.hpp - include/ptn/pattern/pred.hpp - include/ptn/pattern/negation.hpp - include/ptn/pattern/modifiers/guard.hpp - include/ptn/pattern/modifiers/placeholder.hpp - include/ptn/pattern/modifiers/fwd.h +# Collected from the tree so that every header is installed. A +# hand-written list missed four headers in v0.9.6. +file(GLOB_RECURSE PTN_HEADERS + CONFIGURE_DEPENDS + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/include/ptn/*.hpp" + "${CMAKE_CURRENT_SOURCE_DIR}/include/ptn/*.h" ) +list(SORT PTN_HEADERS) # ========== Public interface target ========== add_library(patternia INTERFACE) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1fe95c16..f3291631 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -229,3 +229,21 @@ if(Python3_Interpreter_FOUND ) endforeach() endif() + +# Install the package into a scratch prefix and build a consumer +# against it with find_package(), so a header left out of the install +# fails here rather than for users of the package. +if(PTN_INSTALL AND NOT CMAKE_VERSION VERSION_LESS 3.15) + add_test( + NAME install.consumer + COMMAND + ${CMAKE_COMMAND} + -DBUILD_DIR=${PROJECT_BINARY_DIR} + -DSOURCE_DIR=${PROJECT_SOURCE_DIR} + -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/install_test + -DCXX_COMPILER=${CMAKE_CXX_COMPILER} + "-DGENERATOR=${CMAKE_GENERATOR}" + -DCONFIG=$ + -P ${CMAKE_CURRENT_LIST_DIR}/install/run_install_test.cmake + ) +endif() diff --git a/tests/install/consumer/CMakeLists.txt b/tests/install/consumer/CMakeLists.txt new file mode 100644 index 00000000..1a05e7e9 --- /dev/null +++ b/tests/install/consumer/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.14) +project(ptn_install_consumer LANGUAGES CXX) + +find_package(patternia CONFIG REQUIRED) + +add_executable(ptn_install_consumer main.cpp) +target_link_libraries(ptn_install_consumer PRIVATE patternia::patternia) diff --git a/tests/install/consumer/main.cpp b/tests/install/consumer/main.cpp new file mode 100644 index 00000000..259e9282 --- /dev/null +++ b/tests/install/consumer/main.cpp @@ -0,0 +1,23 @@ +// Compiled against an installed copy of Patternia, not the source +// tree. +#include + +#include +#include +#include + +int main() { + using namespace ptn; + + int x = 3; + int dense = match(x) + | on(val<1> >> 1, val<2> >> 2, val<3> >> 3, _ >> 0); + + std::variant v = std::string("ok"); + int alt = match(v) + | on(is() >> 0, is() >> 1, _ >> 2); + + int owned = match(std::make_unique(7)) | on($ >> 1); + + return dense == 3 && alt == 1 && owned == 1 ? 0 : 1; +} diff --git a/tests/install/run_install_test.cmake b/tests/install/run_install_test.cmake new file mode 100644 index 00000000..2275582d --- /dev/null +++ b/tests/install/run_install_test.cmake @@ -0,0 +1,67 @@ +# Installs the build tree into a scratch prefix, checks that every +# header under include/ was installed, then builds and runs a consumer +# that finds the package with find_package(patternia). +# +# Inputs: BUILD_DIR, SOURCE_DIR, WORK_DIR, CXX_COMPILER, GENERATOR, +# CONFIG (may be empty). + +set(_prefix "${WORK_DIR}/prefix") +set(_consumer_build "${WORK_DIR}/consumer") +file(REMOVE_RECURSE "${WORK_DIR}") + +set(_config_args "") +if(CONFIG) + set(_config_args --config "${CONFIG}") +endif() + +execute_process( + COMMAND "${CMAKE_COMMAND}" --install "${BUILD_DIR}" + --prefix "${_prefix}" ${_config_args} + RESULT_VARIABLE _rc OUTPUT_QUIET) +if(NOT _rc EQUAL 0) + message(FATAL_ERROR "cmake --install failed: ${_rc}") +endif() + +file(GLOB_RECURSE _source_headers RELATIVE "${SOURCE_DIR}/include" + "${SOURCE_DIR}/include/ptn/*") +set(_missing "") +foreach(_h IN LISTS _source_headers) + if(NOT EXISTS "${_prefix}/include/${_h}") + list(APPEND _missing "${_h}") + endif() +endforeach() +if(_missing) + string(REPLACE ";" "\n " _missing "${_missing}") + message(FATAL_ERROR "Headers not installed:\n ${_missing}") +endif() + +execute_process( + COMMAND "${CMAKE_COMMAND}" + -S "${SOURCE_DIR}/tests/install/consumer" + -B "${_consumer_build}" + -G "${GENERATOR}" + "-DCMAKE_CXX_COMPILER=${CXX_COMPILER}" + "-DCMAKE_PREFIX_PATH=${_prefix}" + "-DCMAKE_BUILD_TYPE=Release" + RESULT_VARIABLE _rc) +if(NOT _rc EQUAL 0) + message(FATAL_ERROR "Configuring the consumer failed: ${_rc}") +endif() + +execute_process( + COMMAND "${CMAKE_COMMAND}" --build "${_consumer_build}" --config Release + RESULT_VARIABLE _rc) +if(NOT _rc EQUAL 0) + message(FATAL_ERROR "Building the consumer failed: ${_rc}") +endif() + +find_program(_exe ptn_install_consumer + PATHS "${_consumer_build}" "${_consumer_build}/Release" + NO_DEFAULT_PATH) +if(NOT _exe) + message(FATAL_ERROR "Consumer executable not found") +endif() +execute_process(COMMAND "${_exe}" RESULT_VARIABLE _rc) +if(NOT _rc EQUAL 0) + message(FATAL_ERROR "Consumer returned ${_rc}") +endif()