Skip to content

Commit

Permalink
Clean up install files and add install/find_package testing to ci wor…
Browse files Browse the repository at this point in the history
…kflow (#155)

Co-authored-by: Stephen Berry <stephenberry.developer@gmail.com>
  • Loading branch information
mwalcott3 and stephenberry authored Feb 6, 2023
1 parent ed8ae2a commit a12ef30
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cmake/install-rules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include(GNUInstallDirs)
set(package glaze)

install(
DIRECTORY include/
DIRECTORY include/glaze/

This comment has been minimized.

Copy link
@friendlyanon

friendlyanon Mar 2, 2023

Contributor

This is wrong and breaks compatibility with vendoring (eg. FetchContent)! Vendoring projects now will install glaze directly to /usr/local/include if /usr/local is their install prefix and wish to install glaze themselves. Explanation why there is an additional subdir when installing: friendlyanon/cmake-init#43

Example where this could go wrong:

set(CMAKE_SKIP_INSTALL_RULES OFF)
add_subdirectory(third-party/glaze)
$ cmake -B build -DCMAKE_INSTALL_PATH=/foo
...
$ cmake --build build -t install
...
-- Installing: /foo/include/glaze.hpp
...

This breaks #include <glaze/glaze.hpp> includes!

This comment has been minimized.

Copy link
@friendlyanon

friendlyanon Mar 2, 2023

Contributor

Created #180 to fix this.

DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT glaze_Development
)
Expand Down
6 changes: 4 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/find_package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*build/
15 changes: 15 additions & 0 deletions tests/find_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions tests/find_package/include/example.hpp
Original file line number Diff line number Diff line change
@@ -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<example::person>
{
using T = example::person;
static constexpr auto value = object("first_name", &T::first_name, "last_name", &T::last_name, "age", &T::age);
};
26 changes: 26 additions & 0 deletions tests/find_package/src/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "example.hpp"

int main()
{
using namespace example;
std::vector<person> 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<person, 2> 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;
}

0 comments on commit a12ef30

Please sign in to comment.