From a12ef304eb5baea7fb65c0099e7e97c56a87ec21 Mon Sep 17 00:00:00 2001 From: mwalcott3 Date: Mon, 6 Feb 2023 15:37:33 -0500 Subject: [PATCH] Clean up install files and add install/find_package testing to ci workflow (#155) Co-authored-by: Stephen Berry --- .github/workflows/gcc.yml | 7 +++++++ cmake/install-rules.cmake | 2 +- tests/CMakeLists.txt | 6 ++++-- tests/find_package/.gitignore | 1 + tests/find_package/CMakeLists.txt | 15 +++++++++++++++ tests/find_package/include/example.hpp | 20 ++++++++++++++++++++ tests/find_package/src/example.cpp | 26 ++++++++++++++++++++++++++ 7 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 tests/find_package/.gitignore create mode 100644 tests/find_package/CMakeLists.txt create mode 100644 tests/find_package/include/example.hpp create mode 100644 tests/find_package/src/example.cpp diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index ae7400b737..b4cc6ce82f 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -35,3 +35,10 @@ jobs: - name: Test working-directory: build run: ctest -j 2 --output-on-failure + + - name: Test Install/find_package + working-directory: build + run: | + sudo cmake --build . --target install + cmake -S ${{github.workspace}}/tests/find_package -B ${{github.workspace}}/tests/find_package/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + cmake --build ${{github.workspace}}/tests/find_package/build -j 2 diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 1951625a61..2ae3b47808 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -12,7 +12,7 @@ include(GNUInstallDirs) set(package glaze) install( - DIRECTORY include/ + DIRECTORY include/glaze/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT glaze_Development ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7260b05fb1..6a3a3372e4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,9 +11,11 @@ FetchContent_Declare( ) message(STATUS "Fetching dependencies...") - +set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL TRUE) +set(CMAKE_SKIP_INSTALL_RULES ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(ut) - +set(CMAKE_SKIP_INSTALL_RULES OFF CACHE BOOL "" FORCE) +set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL FALSE) message(STATUS "...finished fetching dependencies.") include(../cmake/code-coverage.cmake) diff --git a/tests/find_package/.gitignore b/tests/find_package/.gitignore new file mode 100644 index 0000000000..c2f3501d57 --- /dev/null +++ b/tests/find_package/.gitignore @@ -0,0 +1 @@ +*build/ diff --git a/tests/find_package/CMakeLists.txt b/tests/find_package/CMakeLists.txt new file mode 100644 index 0000000000..59d7119dac --- /dev/null +++ b/tests/find_package/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.18) + +project( + glaze_example + VERSION 0.0.1 + LANGUAGES CXX +) + +file(GLOB srcs src/*.cpp include/*.hpp) + +find_package(glaze REQUIRED) + +add_executable(${PROJECT_NAME} ${srcs}) +target_include_directories(${PROJECT_NAME} PRIVATE include) +target_link_libraries(${PROJECT_NAME} PRIVATE glaze::glaze) \ No newline at end of file diff --git a/tests/find_package/include/example.hpp b/tests/find_package/include/example.hpp new file mode 100644 index 0000000000..fb1a37b5b1 --- /dev/null +++ b/tests/find_package/include/example.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "glaze/glaze.hpp" + +namespace example +{ + struct person + { + std::string first_name{}; + std::string last_name{}; + uint32_t age{}; + }; +} + +template <> +struct glz::meta +{ + using T = example::person; + static constexpr auto value = object("first_name", &T::first_name, "last_name", &T::last_name, "age", &T::age); +}; diff --git a/tests/find_package/src/example.cpp b/tests/find_package/src/example.cpp new file mode 100644 index 0000000000..18da24b0fe --- /dev/null +++ b/tests/find_package/src/example.cpp @@ -0,0 +1,26 @@ +#include "example.hpp" + +int main() +{ + using namespace example; + std::vector directory; + directory.emplace_back(person{"John", "Doe", 33}); + directory.emplace_back(person{"Alice", "Right", 22}); + + std::string buffer{}; + glz::write_json(directory, buffer); + + std::cout << buffer << "\n\n"; + + std::array another_directory; + glz::read_json(another_directory, buffer); + + std::string another_buffer{}; + glz::write_json(another_directory, another_buffer); + + if (buffer == another_buffer) { + std::cout << "Directories are the same!\n"; + } + + return 0; +}