From 5163cb6d3bd6fa72d7be7213f786455778a5e8f7 Mon Sep 17 00:00:00 2001 From: Vollstrecker Date: Sun, 22 Dec 2024 16:10:22 +0100 Subject: CMake: Move testing into test/CMakeLists.txt. Use the right environment to find the libraries. --- test/CMakeLists.txt | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b274553..15e8c75 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,76 @@ +function (ZLIB_findTestEnv testName) + set (testEnv "PATH=") + + if (MSVC OR MINGW) + set (separator "\\\;") + else() + set (separator ":") + endif() + + string (APPEND testEnv "$${separator}") + string (APPEND testEnv "$ENV{PATH}") + + set_tests_properties (${testName} PROPERTIES + ENVIRONMENT "${testEnv}" + ) +endfunction() + +if(ZLIB_BUILD_SHARED) + add_executable(zlib_example example.c) + target_link_libraries(zlib_example ZLIB::ZLIB) + add_test(NAME zlib_example + COMMAND zlib_example) + + add_executable(minigzip minigzip.c) + target_compile_definitions(zlib + PRIVATE + $<$:HAVE_HIDDEN>) + target_link_libraries(minigzip ZLIB::ZLIB) + + if (MSVC OR MSYS OR MINGW OR CYGWIN) + ZLIB_findTestEnv (zlib_example) + endif (MSVC OR MSYS OR MINGW OR CYGWIN) + + if(HAVE_OFF64_T) + add_executable(zlib_example64 example.c) + target_compile_definitions(zlib_example64 + PRIVATE + LARGEFILE64_SOURCE=1 + $<$:HAVE_HIDDEN>) + target_link_libraries(zlib_example64 ZLIB::ZLIB) + add_test(NAME zlib_example64 + COMMAND zlib_example64) + + if (MSVC OR MSYS OR MINGW OR CYGWIN) + ZLIB_findTestEnv (zlib_example64) + endif (MSVC OR MSYS OR MINGW OR CYGWIN) + endif(HAVE_OFF64_T) +endif(ZLIB_BUILD_SHARED) + +if(ZLIB_BUILD_STATIC) + add_executable(zlib_static_example example.c) + target_link_libraries(zlib_static_example ZLIB::ZLIBSTATIC) + target_compile_definitions(zlib_static_example + PRIVATE + $<$:HAVE_HIDDEN>) + add_test(NAME zlib_static_example + COMMAND zlib_static_example) + + add_executable(static_minigzip minigzip.c) + target_link_libraries(static_minigzip ZLIB::ZLIBSTATIC) + + if(HAVE_OFF64_T) + add_executable(zlib_static_example64 example.c) + target_compile_definitions(zlib_static_example64 + PRIVATE + LARGEFILE64_SOURCE=1 + $<$:HAVE_HIDDEN>) + target_link_libraries(zlib_static_example64 ZLIB::ZLIBSTATIC) + add_test(NAME zlib_static_example64 + COMMAND zlib_static_example64) + endif(HAVE_OFF64_T) +endif(ZLIB_BUILD_STATIC) + add_test(NAME zlib_install COMMAND ${CMAKE_COMMAND} --install ${zlib_BINARY_DIR} --prefix ${CMAKE_CURRENT_BINARY_DIR}/test_install -- cgit v1.2.3-55-g6feb