Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 8 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=$<CONFIG>
-P ${CMAKE_CURRENT_LIST_DIR}/install/run_install_test.cmake
)
endif()
7 changes: 7 additions & 0 deletions tests/install/consumer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions tests/install/consumer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Compiled against an installed copy of Patternia, not the source
// tree.
#include <ptn/patternia.hpp>

#include <memory>
#include <string>
#include <variant>

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<int, std::string> v = std::string("ok");
int alt = match(v)
| on(is<int>() >> 0, is<std::string>() >> 1, _ >> 2);

int owned = match(std::make_unique<int>(7)) | on($ >> 1);

return dense == 3 && alt == 1 && owned == 1 ? 0 : 1;
}
67 changes: 67 additions & 0 deletions tests/install/run_install_test.cmake
Original file line number Diff line number Diff line change
@@ -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()
Loading