diff options
author | Vollstrecker <werner@vollstreckernet.de> | 2024-12-03 15:23:19 +0100 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2025-01-31 19:59:10 -0800 |
commit | 7dc2b782067d746aac2a348e411004135fb5fbda (patch) | |
tree | b530e18cd39f7d314ec9c046c108fe5946c22fd4 | |
parent | a794225144c335a0efe5a97ef7013746613eea46 (diff) | |
download | zlib-7dc2b782067d746aac2a348e411004135fb5fbda.tar.gz zlib-7dc2b782067d746aac2a348e411004135fb5fbda.tar.bz2 zlib-7dc2b782067d746aac2a348e411004135fb5fbda.zip |
CMake: Add test for usage with find_package.
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/CMakeLists.txt | 44 | ||||
-rw-r--r-- | test/find_package_test.cmake.in | 24 |
3 files changed, 70 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a4a0439..545dafe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -242,4 +242,6 @@ if(ZLIB_BUILD_TESTING) | |||
242 | target_compile_definitions(minigzip64 PRIVATE LARGEFILE64_SOURCE=1) | 242 | target_compile_definitions(minigzip64 PRIVATE LARGEFILE64_SOURCE=1) |
243 | target_link_libraries(minigzip64 ZLIB::ZLIB) | 243 | target_link_libraries(minigzip64 ZLIB::ZLIB) |
244 | endif(HAVE_OFF64_T) | 244 | endif(HAVE_OFF64_T) |
245 | |||
246 | add_subdirectory(test) | ||
245 | endif(ZLIB_BUILD_TESTING) | 247 | endif(ZLIB_BUILD_TESTING) |
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..4758230 --- /dev/null +++ b/test/CMakeLists.txt | |||
@@ -0,0 +1,44 @@ | |||
1 | add_test(NAME zlib_test_install | ||
2 | COMMAND ${CMAKE_COMMAND} --install ${zlib_BINARY_DIR} | ||
3 | --prefix ${CMAKE_CURRENT_BINARY_DIR}/test_install | ||
4 | --config $<CONFIG> | ||
5 | WORKING_DIRECTORY ${zlib_BINARY_DIR}) | ||
6 | |||
7 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test) | ||
8 | |||
9 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/find_package_test.cmake.in | ||
10 | ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test/CMakeLists.txt) | ||
11 | |||
12 | add_test(NAME zlib_test_configure_find_package | ||
13 | COMMAND ${CMAKE_COMMAND} | ||
14 | -B${CMAKE_CURRENT_BINARY_DIR}/findpackage_test_build | ||
15 | -DCMAKE_BUILD_TYPE=$<CONFIG> | ||
16 | -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_install | ||
17 | -DZDIR=${CMAKE_CURRENT_BINARY_DIR}/test_install/${CMAKE_INSTALL_LIBDIR} | ||
18 | --fresh | ||
19 | -G "${CMAKE_GENERATOR}" | ||
20 | -S${CMAKE_CURRENT_BINARY_DIR}/findpackage_test) | ||
21 | |||
22 | |||
23 | add_test(NAME zlib_test_build_find_package | ||
24 | COMMAND ${CMAKE_COMMAND} --build | ||
25 | ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test_build | ||
26 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test_build) | ||
27 | |||
28 | add_test(NAME zlib_test_test_find_package | ||
29 | COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG> | ||
30 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test_build) | ||
31 | |||
32 | set_tests_properties(zlib_test_install PROPERTIES | ||
33 | FIXTURES_SETUP install) | ||
34 | |||
35 | set_tests_properties(zlib_test_configure_find_package PROPERTIES | ||
36 | FIXTURES_REQUIRED install | ||
37 | FIXTURES_SETUP config) | ||
38 | |||
39 | set_tests_properties(zlib_test_build_find_package PROPERTIES | ||
40 | FIXTURES_REQUIRED config | ||
41 | FIXTURES_SETUP build) | ||
42 | |||
43 | set_tests_properties(zlib_test_test_find_package PROPERTIES | ||
44 | FIXTURES_REQUIRED build) | ||
diff --git a/test/find_package_test.cmake.in b/test/find_package_test.cmake.in new file mode 100644 index 0000000..c1c11d0 --- /dev/null +++ b/test/find_package_test.cmake.in | |||
@@ -0,0 +1,24 @@ | |||
1 | cmake_minimum_required(VERSION 3.5) | ||
2 | |||
3 | project(zlib_find_package_test | ||
4 | LANGUAGES C | ||
5 | VERSION 1.3.1.1) | ||
6 | |||
7 | enable_testing() | ||
8 | find_package(zlib CONFIG REQUIRED) | ||
9 | |||
10 | if(${ZLIB_BUILD_SHARED}) | ||
11 | add_executable(test_example ${zlib_SOURCE_DIR}/test/example.c) | ||
12 | target_link_libraries(test_example ZLIB::ZLIB) | ||
13 | |||
14 | if(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll") | ||
15 | add_test(NAME zlib_test_example_shared COMMAND test_example) | ||
16 | endif(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll") | ||
17 | endif(${ZLIB_BUILD_SHARED}) | ||
18 | |||
19 | if(${ZLIB_BUILD_STATIC}) | ||
20 | add_executable(test_example_static ${zlib_SOURCE_DIR}/test/example.c) | ||
21 | target_link_libraries(test_example_static ZLIB::ZLIBSTATIC) | ||
22 | add_test(NAME zlib_test_example_static | ||
23 | COMMAND test_example_static) | ||
24 | endif(${ZLIB_BUILD_STATIC}) | ||