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