zlib/contrib/iostream3/CMakeLists.txt
2026-01-12 11:08:59 -08:00

150 lines
4.9 KiB
CMake

cmake_minimum_required(VERSION 3.12...3.31)
project(
iostreamV3
VERSION 1.0.0
LANGUAGES CXX
DESCRIPTION "A library for using C++ IOStreams with zlib V3"
HOMEPAGE_URL "https://www.zlib.net")
option(ZLIB_IOSTREAM3_BUILD_SHARED "Enable building blast shared library" ON)
option(ZLIB_IOSTREAM3_BUILD_STATIC "Enable building blast static library" ON)
option(ZLIB_IOSTREAM3_BUILD_TESTING "Enable building tests for blast" ON)
option(ZLIB_IOSTREAM3_INSTALL "Enable installation of iostream" ON)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
if(NOT DEFINED ZLIB_BUILD_IOSTREAM3)
if(ZLIB_IOSTREAM3_BUILD_SHARED)
list(APPEND REQUIRED_COMPONENTS "shared")
endif(ZLIB_IOSTREAM3_BUILD_SHARED)
if(ZLIB_IOSTREAM3_BUILD_STATIC)
list(APPEND REQUIRED_COMPONENTS "static")
endif(ZLIB_IOSTREAM3_BUILD_STATIC)
find_package(ZLIB REQUIRED COMPONENTS ${REQUIRED_COMPONENTS} CONFIG)
endif(NOT DEFINED ZLIB_BUILD_IOSTREAM3)
if(WIN32 OR CYGWIN)
set(zlibIOStream3_static_suffix "s")
set(CMAKE_DEBUG_POSTFIX "d")
endif(WIN32 OR CYGWIN)
if(ZLIB_IOSTREAM3_BUILD_SHARED)
add_library(zlib-iostream3 SHARED
zfstream.cc
zfstream.h)
target_link_libraries(zlib-iostream3
PUBLIC ZLIB::ZLIB)
if(ZLIB_IOSTREAM3_BUILD_TESTING)
enable_testing()
add_executable(iostream-test test.cc)
target_link_libraries(iostream-test
PRIVATE zlib-iostream3)
add_test(NAME zlib_iostream3_test COMMAND iostream-test)
set_tests_properties(zlib_iostream3_test
PROPERTIES
FIXTURES_REQUIRED iostream3_cleanup)
endif(ZLIB_IOSTREAM3_BUILD_TESTING)
endif(ZLIB_IOSTREAM3_BUILD_SHARED)
if(ZLIB_IOSTREAM3_BUILD_STATIC)
add_library(zlib-iostream3Static STATIC
zfstream.cc
zfstream.h)
target_link_libraries(zlib-iostream3Static
INTERFACE ZLIB::ZLIBSTATIC)
set_target_properties(zlib-iostream3Static
PROPERTIES
OUTPUT_NAME zlib-iostream3${zlib_IOStream3_static_suffix})
if(ZLIB_IOSTREAM3_BUILD_TESTING)
enable_testing()
add_executable(iostream-testStatic test.cc)
target_link_libraries(iostream-testStatic
PRIVATE zlib-iostream3Static)
add_test(NAME zlib_iostream3_testStatic COMMAND iostream-testStatic)
set_tests_properties(zlib_iostream3_testStatic
PROPERTIES
FIXTURES_REQUIRED iostream3_cleanup)
endif(ZLIB_IOSTREAM3_BUILD_TESTING)
endif(ZLIB_IOSTREAM3_BUILD_STATIC)
if(ZLIB_IOSTREAM3_BUILD_TESTING)
add_test(NAME zlib_iostream3_cleanup COMMAND ${CMAKE_COMMAND} -E rm
${CMAKE_CURRENT_BINARY_DIR}/test1.txt.gz
${CMAKE_CURRENT_BINARY_DIR}/test2.txt.gz)
set_tests_properties(zlib_iostream3_cleanup
PROPERTIES
FIXTURES_CLEANUP zlib_iostream3_cleanup)
endif(ZLIB_IOSTREAM3_BUILD_TESTING)
if(ZLIB_IOSTREAM3_INSTALL)
if(ZLIB_IOSTREAM3_BUILD_SHARED)
install(
TARGETS zlib_iostream3_iostreamv3
COMPONENT Runtime
EXPORT zlibiostream3SharedExport
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(
EXPORT zlibiostream3SharedExport
FILE iostreamv3-shared.cmake
NAMESPACE IOSTREAMV3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/iostreamv3)
if(MSVC)
install(
FILES $<TARGET_PDB_FILE:zlib_iostream3_iostream3>
COMPONENT Development
DESTINATION ${CMAKE_INSTALL_BINDIR}
CONFIGURATIONS Debug OR RelWithDebInfo
OPTIONAL)
endif(MSVC)
endif(ZLIB_IOSTREAM3_BUILD_SHARED)
if(ZLIB_IOSTREAM3_BUILD_STATIC)
install(
TARGETS zlib_iostream3_iostreamv3Static
COMPONENT Development
EXPORT iostream3StaticExport
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(
EXPORT iostream3StaticExport
FILE iostreamv3-static.cmake
NAMESPACE IOSTREAMV3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/iostreamv3)
endif(ZLIB_IOSTREAM3_BUILD_STATIC)
configure_package_config_file(
${iostreamV3_SOURCE_DIR}/iostream3Config.cmake.in
${iostreamV3_BINARY_DIR}/iostreamv3Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/iostreamv3)
write_basic_package_version_file(
"${iostreamV3_BINARY_DIR}/iostreamv3ConfigVersion.cmake"
VERSION "${iostream3_VERSION}"
COMPATIBILITY AnyNewerVersion)
install(FILES ${iostreamV3_BINARY_DIR}/iostreamv3Config.cmake
${iostreamV3_BINARY_DIR}/iostreamv3ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/iostreamv3)
install(
FILES zfstream.h
COMPONENT Development
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
endif(ZLIB_IOSTREAM3_INSTALL)