diff options
Diffstat (limited to '')
-rw-r--r-- | CMakeLists.txt | 76 |
1 files changed, 61 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e8e89c..4b80bc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -31,6 +31,30 @@ include(CheckCSourceCompiles) | |||
31 | include(CMakePackageConfigHelpers) | 31 | include(CMakePackageConfigHelpers) |
32 | include(GNUInstallDirs) | 32 | include(GNUInstallDirs) |
33 | 33 | ||
34 | if(NOT ZLIB_CONF_WRITTEN) | ||
35 | set(Z_PREFIX ${ZLIB_PREFIX}) | ||
36 | set(CONF_OUT_FILE ${zlib_BINARY_DIR}/zconf.h.cmakein) | ||
37 | file(READ ${zlib_SOURCE_DIR}/zconf.h.in ZCONF_CONTENT LIMIT 245) | ||
38 | file(WRITE ${CONF_OUT_FILE} ${ZCONF_CONTENT}) | ||
39 | file(APPEND ${CONF_OUT_FILE} "#cmakedefine01 Z_PREFIX\n") | ||
40 | file(APPEND ${CONF_OUT_FILE} "#cmakedefine01 HAVE_STDARG_H\n") | ||
41 | file(APPEND ${CONF_OUT_FILE} "#cmakedefine01 HAVE_UNISTD_H\n") | ||
42 | file(READ ${zlib_SOURCE_DIR}/zconf.h.in ZCONF_CONTENT OFFSET 244) | ||
43 | set(FIRST_ITEM TRUE) | ||
44 | |||
45 | foreach(item IN LISTS ZCONF_CONTENT) | ||
46 | if(FIRST_ITEM) | ||
47 | string(APPEND OUT_CONTENT ${item}) | ||
48 | set(FIRST_ITEM FALSE) | ||
49 | else(FIRST_ITEM) | ||
50 | string(APPEND OUT_CONTENT "\;" ${item}) | ||
51 | endif(FIRST_ITEM) | ||
52 | endforeach(item IN LISTS ${ZCONF_CONTENT}) | ||
53 | |||
54 | file(APPEND ${CONF_OUT_FILE} ${OUT_CONTENT}) | ||
55 | set(ZLIB_CONF_WRITTEN TRUE CACHE BOOL "zconf.h.cmakein was created") | ||
56 | mark_as_advanced(ZLIB_CONF_WRITTEN) | ||
57 | endif(NOT ZLIB_CONF_WRITTEN) | ||
34 | # | 58 | # |
35 | # Check to see if we have large file support | 59 | # Check to see if we have large file support |
36 | # | 60 | # |
@@ -44,15 +68,30 @@ set(CMAKE_REQUIRED_DEFINITIONS) # clear variable | |||
44 | check_function_exists(fseeko HAVE_FSEEKO) | 68 | check_function_exists(fseeko HAVE_FSEEKO) |
45 | 69 | ||
46 | # | 70 | # |
71 | # Check for stdarg.h | ||
72 | # | ||
73 | check_include_file(stdarg.h HAVE_STDARG_H) | ||
74 | |||
75 | # | ||
47 | # Check for unistd.h | 76 | # Check for unistd.h |
48 | # | 77 | # |
49 | check_include_file(unistd.h Z_HAVE_UNISTD_H) | 78 | check_include_file(unistd.h HAVE_UNISTD_H) |
79 | |||
80 | # | ||
81 | # Check visibility attribute is supported | ||
82 | check_c_source_compiles( | ||
83 | " | ||
84 | #include <stdlib.h> | ||
85 | static void f(void) __attribute__ ((visibility(\"hidden\"))); | ||
86 | int main(void) {return 0;} | ||
87 | " | ||
88 | HAVE___ATTR__VIS_HIDDEN) | ||
50 | 89 | ||
51 | set(ZLIB_PC ${zlib_BINARY_DIR}/zlib.pc) | 90 | set(ZLIB_PC ${zlib_BINARY_DIR}/zlib.pc) |
52 | configure_file(${zlib_SOURCE_DIR}/zlib.pc.cmakein | 91 | configure_file(${zlib_SOURCE_DIR}/zlib.pc.cmakein |
53 | ${ZLIB_PC} @ONLY) | 92 | ${ZLIB_PC} @ONLY) |
54 | configure_file(${zlib_SOURCE_DIR}/zconf.h.cmakein | 93 | configure_file(${zlib_BINARY_DIR}/zconf.h.cmakein |
55 | ${zlib_BINARY_DIR}/zconf.h @ONLY) | 94 | ${zlib_BINARY_DIR}/zconf.h) |
56 | include_directories(${zlib_BINARY_DIR} ${zlib_SOURCE_DIR}) | 95 | include_directories(${zlib_BINARY_DIR} ${zlib_SOURCE_DIR}) |
57 | 96 | ||
58 | #============================================================================ | 97 | #============================================================================ |
@@ -113,10 +152,12 @@ if(ZLIB_BUILD_SHARED) | |||
113 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) | 152 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
114 | target_compile_definitions(zlib | 153 | target_compile_definitions(zlib |
115 | PRIVATE | 154 | PRIVATE |
116 | $<$<BOOL:${HAVE_OFF64_T}>:_LARGEFILE64_SOURCE=1> | ||
117 | $<$<BOOL:NOT:${HAVE_FSEEKO}>:NO_FSEEKO> | 155 | $<$<BOOL:NOT:${HAVE_FSEEKO}>:NO_FSEEKO> |
156 | $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN> | ||
118 | $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_DEPRECATE> | 157 | $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_DEPRECATE> |
119 | $<$<BOOL:${MSVC}>:_CRT_NONSTDC_NO_DEPRECATE>) | 158 | $<$<BOOL:${MSVC}>:_CRT_NONSTDC_NO_DEPRECATE> |
159 | PUBLIC | ||
160 | $<$<BOOL:${HAVE_OFF64_T}>:_LARGEFILE64_SOURCE=1>) | ||
120 | set(INSTALL_VERSION ${zlib_VERSION_MAJOR}) | 161 | set(INSTALL_VERSION ${zlib_VERSION_MAJOR}) |
121 | 162 | ||
122 | if(NOT CYGWIN) | 163 | if(NOT CYGWIN) |
@@ -149,6 +190,7 @@ if(ZLIB_BUILD_STATIC) | |||
149 | target_compile_definitions(zlibstatic | 190 | target_compile_definitions(zlibstatic |
150 | PRIVATE | 191 | PRIVATE |
151 | $<$<BOOL:NOT:${HAVE_FSEEKO}>:NO_FSEEKO> | 192 | $<$<BOOL:NOT:${HAVE_FSEEKO}>:NO_FSEEKO> |
193 | $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN> | ||
152 | $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_DEPRECATE> | 194 | $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_DEPRECATE> |
153 | $<$<BOOL:${MSVC}>:_CRT_NONSTDC_NO_DEPRECATE> | 195 | $<$<BOOL:${MSVC}>:_CRT_NONSTDC_NO_DEPRECATE> |
154 | PUBLIC | 196 | PUBLIC |
@@ -242,23 +284,28 @@ if(ZLIB_BUILD_TESTING) | |||
242 | add_test(zlib_example zlib_example) | 284 | add_test(zlib_example zlib_example) |
243 | 285 | ||
244 | add_executable(minigzip test/minigzip.c) | 286 | add_executable(minigzip test/minigzip.c) |
287 | target_compile_definitions(zlib | ||
288 | PRIVATE | ||
289 | $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>) | ||
245 | target_link_libraries(minigzip ZLIB::ZLIB) | 290 | target_link_libraries(minigzip ZLIB::ZLIB) |
246 | 291 | ||
247 | if(HAVE_OFF64_T) | 292 | if(HAVE_OFF64_T) |
248 | add_executable(zlib_example64 test/example.c) | 293 | add_executable(zlib_example64 test/example.c) |
249 | target_compile_definitions(zlib_example64 PRIVATE LARGEFILE64_SOURCE=1) | 294 | target_compile_definitions(zlib_example64 |
295 | PRIVATE | ||
296 | LARGEFILE64_SOURCE=1 | ||
297 | $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>) | ||
250 | target_link_libraries(zlib_example64 ZLIB::ZLIB) | 298 | target_link_libraries(zlib_example64 ZLIB::ZLIB) |
251 | add_test(zlib_example64 zlib_example64) | 299 | add_test(zlib_example64 zlib_example64) |
252 | |||
253 | add_executable(minigzip64 test/minigzip.c) | ||
254 | target_compile_definitions(minigzip64 PRIVATE LARGEFILE64_SOURCE=1) | ||
255 | target_link_libraries(minigzip64 ZLIB::ZLIB) | ||
256 | endif(HAVE_OFF64_T) | 300 | endif(HAVE_OFF64_T) |
257 | endif(ZLIB_BUILD_SHARED) | 301 | endif(ZLIB_BUILD_SHARED) |
258 | 302 | ||
259 | if(ZLIB_BUILD_STATIC) | 303 | if(ZLIB_BUILD_STATIC) |
260 | add_executable(zlib_static_example test/example.c) | 304 | add_executable(zlib_static_example test/example.c) |
261 | target_link_libraries(zlib_static_example ZLIB::ZLIBSTATIC) | 305 | target_link_libraries(zlib_static_example ZLIB::ZLIBSTATIC) |
306 | target_compile_definitions(zlib_static_example | ||
307 | PRIVATE | ||
308 | $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>) | ||
262 | add_test(zlib_static_example zlib_static_example) | 309 | add_test(zlib_static_example zlib_static_example) |
263 | 310 | ||
264 | add_executable(static_minigzip test/minigzip.c) | 311 | add_executable(static_minigzip test/minigzip.c) |
@@ -266,13 +313,12 @@ if(ZLIB_BUILD_TESTING) | |||
266 | 313 | ||
267 | if(HAVE_OFF64_T) | 314 | if(HAVE_OFF64_T) |
268 | add_executable(zlib_static_example64 test/example.c) | 315 | add_executable(zlib_static_example64 test/example.c) |
269 | target_compile_definitions(zlib_static_example64 PRIVATE LARGEFILE64_SOURCE=1) | 316 | target_compile_definitions(zlib_static_example64 |
317 | PRIVATE | ||
318 | LARGEFILE64_SOURCE=1 | ||
319 | $<$<BOOL:${HAVE___ATTR__VIS_HIDDEN}>:HAVE_HIDDEN>) | ||
270 | target_link_libraries(zlib_static_example64 ZLIB::ZLIBSTATIC) | 320 | target_link_libraries(zlib_static_example64 ZLIB::ZLIBSTATIC) |
271 | add_test(zlib_static_example64 zlib_static_example64) | 321 | add_test(zlib_static_example64 zlib_static_example64) |
272 | |||
273 | add_executable(static_minigzip64 test/minigzip.c) | ||
274 | target_compile_definitions(static_minigzip64 PRIVATE LARGEFILE64_SOURCE=1) | ||
275 | target_link_libraries(static_minigzip64 ZLIB::ZLIBSTATIC) | ||
276 | endif(HAVE_OFF64_T) | 322 | endif(HAVE_OFF64_T) |
277 | endif(ZLIB_BUILD_STATIC) | 323 | endif(ZLIB_BUILD_STATIC) |
278 | 324 | ||