diff --git a/Makefile b/Makefile index bcbd968..6a33656 100755 --- a/Makefile +++ b/Makefile @@ -78,6 +78,12 @@ compile-headers: $(_build_path)/CMakeCache.txt ## Compile the headers install: $(_build_path)/CMakeCache.txt compile ## Install the project cmake --install $(_build_path) --config $(CONFIG) --component beman.optional --verbose +.PHONY: clean-install +clean-install: + -rm -rf .install + +realclean: clean-install + ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build cd $(_build_path) && ctest --output-on-failure -C $(CONFIG) @@ -195,6 +201,18 @@ mrdocs: ## Build the docs with Doxygen cd docs && NO_COLOR=1 mrdocs mrdocs.yml 2>&1 | sed 's/\x1b\[[0-9;]*m//g' find docs/adoc -name '*.adoc' | xargs asciidoctor +.PHONY: testinstall +testinstall: install +testinstall: ## Test the installed package + cmake -S installtest -B installtest/.build + cmake --build installtest/.build --target test + +.PHONY: clean-testinstall +clean-testinstall: + -rm -rf installtest/.build + +realclean: clean-testinstall + # Help target .PHONY: help help: ## Show this help. diff --git a/installtest/CMakeLists.txt b/installtest/CMakeLists.txt new file mode 100644 index 0000000..dc1c07e --- /dev/null +++ b/installtest/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.30) +project(ConsumerBemanOptional) + +set(CMAKE_CXX_STANDARD 20) + +# Enable testing in this separate project +enable_testing() + +# Find the installed package +set(OPTIONAL_INSTALL_DIR "../.install/lib/cmake/beman.optional") +find_package( + beman.optional + REQUIRED + PATHS ${OPTIONAL_INSTALL_DIR} + NO_DEFAULT_PATH +) + +# Add your test executable +add_executable(TestInstalledOptional test.cpp) + +# Link against the imported target +target_link_libraries(TestInstalledOptional beman::optional) + +# Register the test with CTest +add_test(NAME RunInstalledTest COMMAND TestInstalledOptional) + +# Ensure 'make test' first builds the 'all' target +set(CMAKE_SKIP_TEST_ALL_DEPENDENCY FALSE) diff --git a/installtest/test.cpp b/installtest/test.cpp new file mode 100644 index 0000000..d19ba46 --- /dev/null +++ b/installtest/test.cpp @@ -0,0 +1,19 @@ +// testinstall/test.cpp -*-C++-*- +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include + +int main() { + beman::optional::optional empty_opt{}; + if (!empty_opt) { + std::cout << "empty_opt is empty!\n"; + } + + beman::optional::optional opt{26}; + if (opt) { + std::cout << "opt = " << *opt << "\n"; + } + + return 0; +}