diff options
| author | Vollstrecker <werner@vollstreckernet.de> | 2025-12-24 14:17:25 +0100 |
|---|---|---|
| committer | Mark Adler <git@madler.net> | 2026-01-31 20:10:58 -0800 |
| commit | d3e5c539ed8a761137354208fe557edaa2059054 (patch) | |
| tree | 751812a1235eeabdba818e2cc4c3a22302a1ba26 /test | |
| parent | 88c13334882d3a3007ff5f5e708e216bc9c4b155 (diff) | |
| download | zlib-d3e5c539ed8a761137354208fe557edaa2059054.tar.gz zlib-d3e5c539ed8a761137354208fe557edaa2059054.tar.bz2 zlib-d3e5c539ed8a761137354208fe557edaa2059054.zip | |
CMake: Add components tests for zlib.
Diffstat (limited to 'test')
| -rw-r--r-- | test/CMakeLists.txt | 53 | ||||
| -rw-r--r-- | test/find_package_no_components_test.cmake.in | 27 | ||||
| -rw-r--r-- | test/find_package_test.cmake.in | 3 | ||||
| -rw-r--r-- | test/find_package_wrong_components_test.cmake.in | 27 |
4 files changed, 109 insertions, 1 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 098472eb..61da30d6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt | |||
| @@ -134,6 +134,8 @@ add_test( | |||
| 134 | set_tests_properties(zlib_install PROPERTIES FIXTURES_SETUP zlib_install) | 134 | set_tests_properties(zlib_install PROPERTIES FIXTURES_SETUP zlib_install) |
| 135 | 135 | ||
| 136 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test) | 136 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test) |
| 137 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/find_package_no_components_test) | ||
| 138 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/find_package_wrong_components_test) | ||
| 137 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test) | 139 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test) |
| 138 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test) | 140 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_exclude_test) |
| 139 | 141 | ||
| @@ -142,6 +144,14 @@ configure_file( | |||
| 142 | ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test/CMakeLists.txt @ONLY) | 144 | ${CMAKE_CURRENT_BINARY_DIR}/findpackage_test/CMakeLists.txt @ONLY) |
| 143 | 145 | ||
| 144 | configure_file( | 146 | configure_file( |
| 147 | ${CMAKE_CURRENT_SOURCE_DIR}/find_package_no_components_test.cmake.in | ||
| 148 | ${CMAKE_CURRENT_BINARY_DIR}/findpackage_no_components_test/CMakeLists.txt @ONLY) | ||
| 149 | |||
| 150 | configure_file( | ||
| 151 | ${CMAKE_CURRENT_SOURCE_DIR}/find_package_wrong_components_test.cmake.in | ||
| 152 | ${CMAKE_CURRENT_BINARY_DIR}/findpackage_wrong_components_test/CMakeLists.txt @ONLY) | ||
| 153 | |||
| 154 | configure_file( | ||
| 145 | ${CMAKE_CURRENT_SOURCE_DIR}/add_subdirectory_test.cmake.in | 155 | ${CMAKE_CURRENT_SOURCE_DIR}/add_subdirectory_test.cmake.in |
| 146 | ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test/CMakeLists.txt @ONLY) | 156 | ${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory_test/CMakeLists.txt @ONLY) |
| 147 | 157 | ||
| @@ -192,6 +202,49 @@ set_tests_properties( | |||
| 192 | CTEST_OUTPUT_ON_FAILURE=1) | 202 | CTEST_OUTPUT_ON_FAILURE=1) |
| 193 | 203 | ||
| 194 | # | 204 | # |
| 205 | # findpackage_no_components_test | ||
| 206 | # | ||
| 207 | add_test( | ||
| 208 | NAME zlib_find_package_no_components_configure | ||
| 209 | COMMAND | ||
| 210 | ${CMAKE_COMMAND} ${PLATFORM} | ||
| 211 | -B${CMAKE_CURRENT_BINARY_DIR}/findpackage_no_components_test_build | ||
| 212 | -DCMAKE_BUILD_TYPE=$<CONFIG> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} | ||
| 213 | -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} | ||
| 214 | -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_install --fresh | ||
| 215 | -G "${CMAKE_GENERATOR}" | ||
| 216 | -S${CMAKE_CURRENT_BINARY_DIR}/findpackage_no_components_test) | ||
| 217 | |||
| 218 | set_tests_properties( | ||
| 219 | zlib_find_package_no_components_configure | ||
| 220 | PROPERTIES FIXTURES_REQUIRED zlib_install) | ||
| 221 | |||
| 222 | if(NOT ZLIB_BUILD_SHARED OR NOT ZLIB_BUILD_STATIC) | ||
| 223 | set_tests_properties( | ||
| 224 | zlib_find_package_no_components_configure | ||
| 225 | PROPERTIES WILL_FAIL TRUE) | ||
| 226 | endif(NOT ZLIB_BUILD_SHARED OR NOT ZLIB_BUILD_STATIC) | ||
| 227 | |||
| 228 | # | ||
| 229 | # findpackage_no_component_test | ||
| 230 | # | ||
| 231 | add_test( | ||
| 232 | NAME zlib_find_package_wrong_components_configure | ||
| 233 | COMMAND | ||
| 234 | ${CMAKE_COMMAND} ${PLATFORM} | ||
| 235 | -B${CMAKE_CURRENT_BINARY_DIR}/findpackage_wrong_components_test_build | ||
| 236 | -DCMAKE_BUILD_TYPE=$<CONFIG> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} | ||
| 237 | -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} | ||
| 238 | -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_install --fresh | ||
| 239 | -G "${CMAKE_GENERATOR}" | ||
| 240 | -S${CMAKE_CURRENT_BINARY_DIR}/findpackage_wrong_components_test) | ||
| 241 | |||
| 242 | set_tests_properties( | ||
| 243 | zlib_find_package_wrong_components_configure | ||
| 244 | PROPERTIES FIXTURES_REQUIRED zlib_install | ||
| 245 | WILL_FAIL TRUE) | ||
| 246 | |||
| 247 | # | ||
| 195 | # add_subdirectory_test | 248 | # add_subdirectory_test |
| 196 | # | 249 | # |
| 197 | add_test( | 250 | add_test( |
diff --git a/test/find_package_no_components_test.cmake.in b/test/find_package_no_components_test.cmake.in new file mode 100644 index 00000000..7c54386d --- /dev/null +++ b/test/find_package_no_components_test.cmake.in | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | cmake_minimum_required(VERSION 3.12...3.31) | ||
| 2 | |||
| 3 | project( | ||
| 4 | zlib_find_package_test | ||
| 5 | LANGUAGES C | ||
| 6 | VERSION @zlib_VERSION@) | ||
| 7 | |||
| 8 | enable_testing() | ||
| 9 | option(ZLIB_BUILD_SHARED "" @ZLIB_BUILD_SHARED@) | ||
| 10 | option(ZLIB_BUILD_STATIC "" @ZLIB_BUILD_STATIC@) | ||
| 11 | |||
| 12 | find_package(ZLIB @zlib_VERSION@ CONFIG REQUIRED) | ||
| 13 | |||
| 14 | if(ZLIB_BUILD_SHARED) | ||
| 15 | add_executable(test_example @zlib_SOURCE_DIR@/test/example.c) | ||
| 16 | target_link_libraries(test_example ZLIB::ZLIB) | ||
| 17 | |||
| 18 | if(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll") | ||
| 19 | add_test(NAME zlib_test_example_shared COMMAND test_example) | ||
| 20 | endif(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll") | ||
| 21 | endif(ZLIB_BUILD_SHARED) | ||
| 22 | |||
| 23 | if(ZLIB_BUILD_STATIC) | ||
| 24 | add_executable(test_example_static @zlib_SOURCE_DIR@/test/example.c) | ||
| 25 | target_link_libraries(test_example_static ZLIB::ZLIBSTATIC) | ||
| 26 | add_test(NAME zlib_test_example_static COMMAND test_example_static) | ||
| 27 | endif(ZLIB_BUILD_STATIC) | ||
diff --git a/test/find_package_test.cmake.in b/test/find_package_test.cmake.in index 0f77d497..be5486d8 100644 --- a/test/find_package_test.cmake.in +++ b/test/find_package_test.cmake.in | |||
| @@ -6,11 +6,11 @@ project( | |||
| 6 | VERSION @zlib_VERSION@) | 6 | VERSION @zlib_VERSION@) |
| 7 | 7 | ||
| 8 | enable_testing() | 8 | enable_testing() |
| 9 | find_package(ZLIB @zlib_VERSION@ CONFIG REQUIRED) | ||
| 10 | option(ZLIB_BUILD_SHARED "" @ZLIB_BUILD_SHARED@) | 9 | option(ZLIB_BUILD_SHARED "" @ZLIB_BUILD_SHARED@) |
| 11 | option(ZLIB_BUILD_STATIC "" @ZLIB_BUILD_STATIC@) | 10 | option(ZLIB_BUILD_STATIC "" @ZLIB_BUILD_STATIC@) |
| 12 | 11 | ||
| 13 | if(ZLIB_BUILD_SHARED) | 12 | if(ZLIB_BUILD_SHARED) |
| 13 | find_package(ZLIB @zlib_VERSION@ CONFIG COMPONENTS shared REQUIRED) | ||
| 14 | add_executable(test_example @zlib_SOURCE_DIR@/test/example.c) | 14 | add_executable(test_example @zlib_SOURCE_DIR@/test/example.c) |
| 15 | target_link_libraries(test_example ZLIB::ZLIB) | 15 | target_link_libraries(test_example ZLIB::ZLIB) |
| 16 | 16 | ||
| @@ -20,6 +20,7 @@ if(ZLIB_BUILD_SHARED) | |||
| 20 | endif(ZLIB_BUILD_SHARED) | 20 | endif(ZLIB_BUILD_SHARED) |
| 21 | 21 | ||
| 22 | if(ZLIB_BUILD_STATIC) | 22 | if(ZLIB_BUILD_STATIC) |
| 23 | find_package(ZLIB @zlib_VERSION@ CONFIG COMPONENTS static REQUIRED) | ||
| 23 | add_executable(test_example_static @zlib_SOURCE_DIR@/test/example.c) | 24 | add_executable(test_example_static @zlib_SOURCE_DIR@/test/example.c) |
| 24 | target_link_libraries(test_example_static ZLIB::ZLIBSTATIC) | 25 | target_link_libraries(test_example_static ZLIB::ZLIBSTATIC) |
| 25 | add_test(NAME zlib_test_example_static COMMAND test_example_static) | 26 | add_test(NAME zlib_test_example_static COMMAND test_example_static) |
diff --git a/test/find_package_wrong_components_test.cmake.in b/test/find_package_wrong_components_test.cmake.in new file mode 100644 index 00000000..fff4601c --- /dev/null +++ b/test/find_package_wrong_components_test.cmake.in | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | cmake_minimum_required(VERSION 3.12...3.31) | ||
| 2 | |||
| 3 | project( | ||
| 4 | zlib_find_package_test | ||
| 5 | LANGUAGES C | ||
| 6 | VERSION @zlib_VERSION@) | ||
| 7 | |||
| 8 | enable_testing() | ||
| 9 | option(ZLIB_BUILD_SHARED "" @ZLIB_BUILD_SHARED@) | ||
| 10 | option(ZLIB_BUILD_STATIC "" @ZLIB_BUILD_STATIC@) | ||
| 11 | |||
| 12 | find_package(ZLIB @zlib_VERSION@ CONFIG COMPONENTS wrong REQUIRED) | ||
| 13 | |||
| 14 | if(ZLIB_BUILD_SHARED) | ||
| 15 | add_executable(test_example @zlib_SOURCE_DIR@/test/example.c) | ||
| 16 | target_link_libraries(test_example ZLIB::ZLIB) | ||
| 17 | |||
| 18 | if(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll") | ||
| 19 | add_test(NAME zlib_test_example_shared COMMAND test_example) | ||
| 20 | endif(NOT ${CMAKE_SHARED_LIBRARY_SUFFIX} STREQUAL ".dll") | ||
| 21 | endif(ZLIB_BUILD_SHARED) | ||
| 22 | |||
| 23 | if(ZLIB_BUILD_STATIC) | ||
| 24 | add_executable(test_example_static @zlib_SOURCE_DIR@/test/example.c) | ||
| 25 | target_link_libraries(test_example_static ZLIB::ZLIBSTATIC) | ||
| 26 | add_test(NAME zlib_test_example_static COMMAND test_example_static) | ||
| 27 | endif(ZLIB_BUILD_STATIC) | ||
