Skip to content

Commit 73699b1

Browse files
committed
Add find-package-test
1 parent 2242945 commit 73699b1

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

examples/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3+
cmake_minimum_required(VERSION 3.25...3.31)
4+
5+
project(beman_inplace_vector_example LANGUAGES CXX)
6+
7+
if(PROJECT_IS_TOP_LEVEL)
8+
find_package(beman_inplace_vector 1.0.0 EXACT REQUIRED)
9+
enable_testing()
10+
endif()
11+
312
set(ALL_EXAMPLES fibonacci)
413

5-
message("Examples to be built: ${ALL_EXAMPLES}")
14+
message(STATUS "Examples to be built: ${ALL_EXAMPLES}")
615

716
foreach(example ${ALL_EXAMPLES})
817
add_executable(beman.inplace_vector.examples.${example})
@@ -12,6 +21,7 @@ foreach(example ${ALL_EXAMPLES})
1221
)
1322
target_link_libraries(
1423
beman.inplace_vector.examples.${example}
15-
beman.inplace_vector
24+
beman::inplace_vector
1625
)
26+
add_test(NAME ${example} COMMAND beman.inplace_vector.examples.${example})
1727
endforeach()

tests/beman/inplace_vector/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
# Tests
77
add_executable(beman.inplace_vector.test inplace_vector.test.cpp)
88

9-
target_link_libraries(beman.inplace_vector.test PRIVATE beman.inplace_vector)
9+
target_link_libraries(beman.inplace_vector.test PRIVATE beman::inplace_vector)
1010

1111
add_test(NAME beman.inplace_vector.test COMMAND beman.inplace_vector.test)
12+
13+
# test if the targets are findable from the build directory
14+
# NOTE: For an INTERFACE library and multi config generators, we may always use
15+
# the -C Debug config type instead of $<CONFIG> to prevent problems! CK
16+
if(CMAKE_BUILD_TYPE STREQUAL Debug)
17+
add_test(
18+
NAME find-package-test
19+
COMMAND
20+
${CMAKE_CTEST_COMMAND} --verbose --output-on-failure -C Debug
21+
--build-and-test "${PROJECT_SOURCE_DIR}/examples"
22+
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator
23+
${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM}
24+
--build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
25+
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
26+
"-DCMAKE_BUILD_TYPE=Debug"
27+
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
28+
)
29+
endif()

0 commit comments

Comments
 (0)