1 1.1 christos cmake_minimum_required(VERSION 3.12...3.31) 2 1.1 christos 3 1.1 christos project( 4 1.1 christos iostreamV3 5 1.1 christos VERSION 1.0.0 6 1.1 christos LANGUAGES CXX 7 1.1 christos DESCRIPTION "A library for using C++ IOStreams with zlib V3" 8 1.1 christos HOMEPAGE_URL "https://www.zlib.net") 9 1.1 christos 10 1.1 christos option(ZLIB_IOSTREAM3_BUILD_SHARED "Enable building blast shared library" ON) 11 1.1 christos option(ZLIB_IOSTREAM3_BUILD_STATIC "Enable building blast static library" ON) 12 1.1 christos option(ZLIB_IOSTREAM3_BUILD_TESTING "Enable building tests for blast" ON) 13 1.1 christos option(ZLIB_IOSTREAM3_INSTALL "Enable installation of iostream" ON) 14 1.1 christos 15 1.1 christos include(GNUInstallDirs) 16 1.1 christos include(CMakePackageConfigHelpers) 17 1.1 christos 18 1.1 christos if(NOT DEFINED ZLIB_BUILD_IOSTREAM3) 19 1.1 christos if(ZLIB_IOSTREAM3_BUILD_SHARED) 20 1.1 christos list(APPEND REQUIRED_COMPONENTS "shared") 21 1.1 christos endif(ZLIB_IOSTREAM3_BUILD_SHARED) 22 1.1 christos 23 1.1 christos if(ZLIB_IOSTREAM3_BUILD_STATIC) 24 1.1 christos list(APPEND REQUIRED_COMPONENTS "static") 25 1.1 christos endif(ZLIB_IOSTREAM3_BUILD_STATIC) 26 1.1 christos 27 1.1 christos find_package(ZLIB REQUIRED COMPONENTS ${REQUIRED_COMPONENTS} CONFIG) 28 1.1 christos endif(NOT DEFINED ZLIB_BUILD_IOSTREAM3) 29 1.1 christos 30 1.1 christos if(WIN32 OR CYGWIN) 31 1.1 christos set(zlibIOStream3_static_suffix "s") 32 1.1 christos set(CMAKE_DEBUG_POSTFIX "d") 33 1.1 christos endif(WIN32 OR CYGWIN) 34 1.1 christos 35 1.1 christos 36 1.1 christos function(iostreamv3_findTestEnv testName) 37 1.1 christos set(testEnv "PATH=") 38 1.1 christos 39 1.1 christos if(MSVC OR MINGW) 40 1.1 christos set(separator "\\\;") 41 1.1 christos else() 42 1.1 christos set(separator ":") 43 1.1 christos endif() 44 1.1 christos 45 1.1 christos string(APPEND testEnv "$<TARGET_FILE_DIR:zlib_iostream3_iostreamv3>${separator}") 46 1.1 christos string(APPEND testEnv "$<TARGET_FILE_DIR:ZLIB::ZLIB>${separator}") 47 1.1 christos string(APPEND testEnv "$ENV{PATH}") 48 1.1 christos 49 1.1 christos set_tests_properties(${testName} PROPERTIES ENVIRONMENT "${testEnv}") 50 1.1 christos endfunction(iostreamv3_findTestEnv testName) 51 1.1 christos 52 1.1 christos if(ZLIB_IOSTREAM3_BUILD_SHARED) 53 1.1 christos add_library(zlib_iostream3_iostreamv3 SHARED 54 1.1 christos zfstream.cc 55 1.1 christos zfstream.h) 56 1.1 christos 57 1.1 christos add_library(IOSTREAMV3::IOSTREAMV3 ALIAS zlib_iostream3_iostreamv3) 58 1.1 christos 59 1.1 christos if(NOT CYGWIN) 60 1.1 christos set_target_properties(zlib_iostream3_iostreamv3 61 1.1 christos PROPERTIES 62 1.1 christos SOVERSION ${iostreamV3_VERSION_MAJOR} 63 1.1 christos VERSION ${iostreamV3_VERSION}) 64 1.1 christos endif(NOT CYGWIN) 65 1.1 christos 66 1.1 christos set_target_properties(zlib_iostream3_iostreamv3 67 1.1 christos PROPERTIES 68 1.1 christos EXPORT_NAME IOSTREAMV3 69 1.1 christos OUTPUT_NAME iostream3) 70 1.1 christos 71 1.1 christos target_link_libraries(zlib_iostream3_iostreamv3 72 1.1 christos PUBLIC ZLIB::ZLIB) 73 1.1 christos 74 1.1 christos if(ZLIB_IOSTREAM3_BUILD_TESTING) 75 1.1 christos enable_testing() 76 1.1 christos 77 1.1 christos add_executable(zlib_iostream3_test test.cc zfstream.h) 78 1.1 christos 79 1.1 christos target_link_libraries(zlib_iostream3_test 80 1.1 christos PRIVATE zlib_iostream3_iostreamv3) 81 1.1 christos 82 1.1 christos add_test(NAME zlib_iostream3_test COMMAND zlib_iostream3_test) 83 1.1 christos 84 1.1 christos set_tests_properties(zlib_iostream3_test 85 1.1 christos PROPERTIES 86 1.1 christos FIXTURES_REQUIRED zlib_iostream3_cleanup) 87 1.1 christos 88 1.1 christos if(MSVC 89 1.1 christos OR MSYS 90 1.1 christos OR MINGW 91 1.1 christos OR CYGWIN) 92 1.1 christos iostreamv3_findtestenv(zlib_iostream3_test) 93 1.1 christos endif( 94 1.1 christos MSVC 95 1.1 christos OR MSYS 96 1.1 christos OR MINGW 97 1.1 christos OR CYGWIN) 98 1.1 christos endif(ZLIB_IOSTREAM3_BUILD_TESTING) 99 1.1 christos endif(ZLIB_IOSTREAM3_BUILD_SHARED) 100 1.1 christos 101 1.1 christos if(ZLIB_IOSTREAM3_BUILD_STATIC) 102 1.1 christos add_library(zlib_iostream3_iostreamv3Static STATIC 103 1.1 christos zfstream.cc 104 1.1 christos zfstream.h) 105 1.1 christos 106 1.1 christos add_library(IOSTREAMV3::IOSTREAMV3STATIC 107 1.1 christos ALIAS zlib_iostream3_iostreamv3Static) 108 1.1 christos 109 1.1 christos target_link_libraries(zlib_iostream3_iostreamv3Static 110 1.1 christos PUBLIC ZLIB::ZLIBSTATIC) 111 1.1 christos 112 1.1 christos set_target_properties(zlib_iostream3_iostreamv3Static 113 1.1 christos PROPERTIES 114 1.1 christos EXPORT_NAME IOSTREAMV3STATIC 115 1.1 christos OUTPUT_NAME iostream3${zlib_IOStream3_static_suffix}) 116 1.1 christos 117 1.1 christos if(ZLIB_IOSTREAM3_BUILD_TESTING) 118 1.1 christos enable_testing() 119 1.1 christos 120 1.1 christos add_executable(zlib_iostream3_testStatic test.cc zfstream.h) 121 1.1 christos 122 1.1 christos target_link_libraries(zlib_iostream3_testStatic 123 1.1 christos PRIVATE zlib_iostream3_iostreamv3Static) 124 1.1 christos 125 1.1 christos add_test(NAME zlib_iostream3_testStatic 126 1.1 christos COMMAND zlib_iostream3_testStatic) 127 1.1 christos 128 1.1 christos set_tests_properties(zlib_iostream3_testStatic 129 1.1 christos PROPERTIES 130 1.1 christos FIXTURES_REQUIRED zlib_iostream3_cleanup) 131 1.1 christos endif(ZLIB_IOSTREAM3_BUILD_TESTING) 132 1.1 christos endif(ZLIB_IOSTREAM3_BUILD_STATIC) 133 1.1 christos 134 1.1 christos if(ZLIB_IOSTREAM3_BUILD_TESTING) 135 1.1 christos add_test(NAME zlib_iostream3_cleanup COMMAND ${CMAKE_COMMAND} -E rm 136 1.1 christos ${CMAKE_CURRENT_BINARY_DIR}/test1.txt.gz 137 1.1 christos ${CMAKE_CURRENT_BINARY_DIR}/test2.txt.gz) 138 1.1 christos 139 1.1 christos set_tests_properties(zlib_iostream3_cleanup 140 1.1 christos PROPERTIES 141 1.1 christos FIXTURES_CLEANUP zlib_iostream3_cleanup) 142 1.1 christos 143 1.1 christos add_subdirectory(test) 144 1.1 christos endif(ZLIB_IOSTREAM3_BUILD_TESTING) 145 1.1 christos 146 1.1 christos if(ZLIB_IOSTREAM3_INSTALL) 147 1.1 christos if(ZLIB_IOSTREAM3_BUILD_SHARED) 148 1.1 christos install( 149 1.1 christos TARGETS zlib_iostream3_iostreamv3 150 1.1 christos COMPONENT Runtime 151 1.1 christos EXPORT zlibiostream3SharedExport 152 1.1 christos RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 153 1.1 christos ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") 154 1.1 christos install( 155 1.1 christos EXPORT zlibiostream3SharedExport 156 1.1 christos FILE iostreamv3-shared.cmake 157 1.1 christos NAMESPACE IOSTREAMV3:: 158 1.1 christos DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/iostreamv3) 159 1.1 christos 160 1.1 christos if(MSVC) 161 1.1 christos install( 162 1.1 christos FILES $<TARGET_PDB_FILE:zlib_iostream3_iostreamv3> 163 1.1 christos COMPONENT Development 164 1.1 christos DESTINATION ${CMAKE_INSTALL_BINDIR} 165 1.1 christos CONFIGURATIONS Debug OR RelWithDebInfo 166 1.1 christos OPTIONAL) 167 1.1 christos endif(MSVC) 168 1.1 christos endif(ZLIB_IOSTREAM3_BUILD_SHARED) 169 1.1 christos 170 1.1 christos if(ZLIB_IOSTREAM3_BUILD_STATIC) 171 1.1 christos install( 172 1.1 christos TARGETS zlib_iostream3_iostreamv3Static 173 1.1 christos COMPONENT Development 174 1.1 christos EXPORT iostream3StaticExport 175 1.1 christos ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") 176 1.1 christos install( 177 1.1 christos EXPORT iostream3StaticExport 178 1.1 christos FILE iostreamv3-static.cmake 179 1.1 christos NAMESPACE IOSTREAMV3:: 180 1.1 christos DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/iostreamv3) 181 1.1 christos endif(ZLIB_IOSTREAM3_BUILD_STATIC) 182 1.1 christos 183 1.1 christos configure_package_config_file( 184 1.1 christos ${iostreamV3_SOURCE_DIR}/iostream3Config.cmake.in 185 1.1 christos ${iostreamV3_BINARY_DIR}/iostreamv3Config.cmake 186 1.1 christos INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/iostreamv3) 187 1.1 christos 188 1.1 christos write_basic_package_version_file( 189 1.1 christos "${iostreamV3_BINARY_DIR}/iostreamv3ConfigVersion.cmake" 190 1.1 christos VERSION "${iostream3_VERSION}" 191 1.1 christos COMPATIBILITY AnyNewerVersion) 192 1.1 christos 193 1.1 christos install(FILES ${iostreamV3_BINARY_DIR}/iostreamv3Config.cmake 194 1.1 christos ${iostreamV3_BINARY_DIR}/iostreamv3ConfigVersion.cmake 195 1.1 christos DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/iostreamv3) 196 1.1 christos install( 197 1.1 christos FILES zfstream.h 198 1.1 christos COMPONENT Development 199 1.1 christos DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") 200 1.1 christos endif(ZLIB_IOSTREAM3_INSTALL) 201