Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
added test for header only, though it works only in github workflow

added some folders to gitignore

made github workflow to install not on a system but in a folder `install_dir`

formatted some CMakeLists.txt with `cmake-format`
  • Loading branch information
Arniiiii committed Aug 21, 2024
1 parent 9f9872d commit 84b59e5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 6 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ jobs:
cmake -S test -B build/local
cmake --build build/local
cmake --build build/local --target test
sudo -E cmake --build build/local --target install
cmake --install build/local --prefix ./install_dir
- name: test installed build
run: |
cmake -S test -B build/installed -D TEST_INSTALLED_VERSION=1
sudo apt install fzf ripgrep
fzf --walker-root=./install_dir -f "lib /cmake/ /dependencyConfig.cmake" | rg lib | rg cmake | rg Config.cmake
fzf --walker-root=./install_dir -f header_onlyConfig.cmake | rg share/cmake
cmake -S test -B build/installed -DCMAKE_INSTALL_PREFIX=./install_dir -D TEST_INSTALLED_VERSION=1
cmake --build build/installed
cmake --build build/installed --target test
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/build
/out
/.vs
/.vs
.cache/
compile_commands.json
install_dir/
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ function(packageProject)
endif()
endif()

set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_LIBDIR})
if(PROJECT_ARCH_INDEPENDENT)
set(wbpvf_extra_args ARCH_INDEPENDENT)
set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_DATADIR}) # share
# install to architecture independent (share) directory
set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_DATADIR})
else()
# if x32 or multilib->x32 , install to (lib) directory. if x64, install to (lib64) directory
set(INSTALL_DIR_FOR_CMAKE_CONFIGS ${CMAKE_INSTALL_LIBDIR})
endif()

write_basic_package_version_file(
Expand Down
5 changes: 4 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ project(

if(TEST_INSTALLED_VERSION)
find_package(dependency 1.2 REQUIRED)
find_package(header_only 1.0 REQUIRED)
find_package(namespaced_dependency 4.5.6 REQUIRED)
find_package(transitive_dependency 7.8.9 REQUIRED)
else()
if(TEST_CPACK)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Foo Bar <foo@bar.local>")
endif()
add_subdirectory(dependency)
add_subdirectory(header_only)
add_subdirectory(namespaced_dependency)
add_subdirectory(transitive_dependency)
endif()

add_executable(main main.cpp)

target_link_libraries(
main dependency ns::namespaced_dependency transitive_dependency::transitive_dependency
main dependency header_only ns::namespaced_dependency
transitive_dependency::transitive_dependency
)

enable_testing()
Expand Down
28 changes: 28 additions & 0 deletions test/header_only/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.14...3.22)

project(
header_only
VERSION 1.0
LANGUAGES CXX
DESCRIPTION "A header only dependency for testing PackageProject.cmake"
)

add_library(${PROJECT_NAME} INTERFACE)

target_include_directories(
dependency PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../.. PackageProject)

packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
BINARY_DIR ${PROJECT_BINARY_DIR}
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${PROJECT_NAME}/version.h"
DEPENDENCIES ""
CPACK "${TEST_CPACK}"
)
5 changes: 5 additions & 0 deletions test/header_only/include/header_only/adder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

inline constexpr long add(int a, int b) {
return a + b;
}
8 changes: 8 additions & 0 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <namespaced_dependency/version.h>
#include <transitive_dependency/transitive_dependency.h>
#include <transitive_dependency/version.h>
#include <header_only/adder.h>
#include <header_only/version.h>

#include <string>

Expand All @@ -27,5 +29,11 @@ int main() {
result &= TRANSITIVE_DEPENDENCY_VERSION_MINOR == 8;
result &= TRANSITIVE_DEPENDENCY_VERSION_PATCH == 9;
result &= TRANSITIVE_DEPENDENCY_VERSION_TWEAK == 21948124;
result &= (5 == add(2,3));
result &= HEADER_ONLY_VERSION == std::string("1.2");
result &= HEADER_ONLY_VERSION_MAJOR == 1;
result &= HEADER_ONLY_VERSION_MINOR == 2;
result &= HEADER_ONLY_VERSION_PATCH == 0;
result &= HEADER_ONLY_VERSION_TWEAK == 0;
return result ? 0 : 1;
}

0 comments on commit 84b59e5

Please sign in to comment.