Skip to content

Commit

Permalink
Add find_package test when pfs is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrugman committed Apr 9, 2024
1 parent 110eeba commit a8e2158
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmake/pfs-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
@PACKAGE_INIT@
check_required_components(pfs)

set(pfs_FOUND TRUE)

set(pfs_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include")

set(pfs_LIBRARIES pfs)
set(pfs_LIBRARY_DIR "${CMAKE_CURRENT_LIST_DIR}/lib")

set(pfs_INCLUDE_DIRS "${pfs_INCLUDE_DIRS}" CACHE STRING "pfs include directories" FORCE)
set(pfs_LIBRARIES "${pfs_LIBRARIES}" CACHE STRING "pfs libraries" FORCE)
set(pfs_LIBRARY_DIR "${pfs_LIBRARY_DIR}" CACHE STRING "pfs library dirs" FORCE)
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions test/cmake/find_package_source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required (VERSION 3.5)

project (find_package)

find_package (pfs PATHS /pfs NO_DEFUALT_PATH REQUIRED)

set (SOURCES find_package.cpp)

add_executable (find_package ${SOURCES})

target_link_libraries (find_package -L${pfs_LIBRARY_DIR} ${pfs_LIBRARIES})
target_include_directories (find_package PRIVATE ${pfs_INCLUDE_DIRS})
41 changes: 41 additions & 0 deletions test/cmake/run_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -eu

main() {
if [[ "$#" -ne 1 ]]; then
echo "Usage: $0 <test_name>"
return 2
fi
declare -r test_name="$1"

declare -r project_name="find_package"

declare -r pfs_dir="/pfs"
declare -r cmake_tests_dir="$pfs_dir/test/cmake"

declare -r source_file="$cmake_tests_dir/$project_name.cpp"
if [[ ! -f "$source_file" ]]; then
echo "[!] Cannot find test source file [$source_file]"
return 1
fi

declare -r test_dir="$cmake_tests_dir/${project_name}_${test_name}"
if [[ ! -d "$test_dir" ]]; then
echo "[!] Cannot find test [$test_dir]"
return 1
fi

declare -r target_dir="/$project_name"
echo "[=] Deleting target dir [$target_dir]"
rm -rf "$target_dir"

echo "[=] Copying test and source file to target dir"
cp -R "$test_dir" "$target_dir"
cp "$source_file" "$target_dir/."

echo "[=] Building..."
(cd "$target_dir"; cmake .; make; "./$project_name" "/dev/pts/0")
}

main "$@"

0 comments on commit a8e2158

Please sign in to comment.