|
1 | | -# Copies the zlib-ng static library to a fixed filename. |
| 1 | +# Copies the zlib-ng static library to a fixed path. |
2 | 2 | # |
3 | 3 | # zlib-ng names its output differently across platforms and configurations (libz.a, libz-ng.a, |
4 | 4 | # zlib.lib, zlibstatic.lib, ...), but ITK and DCMTK need an explicit ZLIB_LIBRARY path that |
5 | 5 | # the superbuild can compute at configure time, before zlib has been built. Resolving the |
6 | 6 | # real name here and copying it to a canonical one lets the dependents be configured with a |
7 | 7 | # path that is known up front. |
8 | 8 | # |
9 | | -# Invoked as: cmake -DZLIB_LIB_DIR=... -DOUTPUT_NAME=... -P canonicalize_zlib.cmake |
| 9 | +# Both lib/ and lib64/ are searched. The superbuild passes CMAKE_INSTALL_LIBDIR=lib so this |
| 10 | +# should not be necessary, but a project that ignores it would otherwise fail here with a |
| 11 | +# confusing "not found" -- and on RHEL-family systems, which is what the manylinux images |
| 12 | +# are, lib64 is the default that gets ignored *to*. |
| 13 | +# |
| 14 | +# Invoked as: cmake -DZLIB_PREFIX=... -DTARGET_PATH=... -P canonicalize_zlib.cmake |
10 | 15 |
|
11 | | -if(NOT ZLIB_LIB_DIR OR NOT OUTPUT_NAME) |
12 | | - message(FATAL_ERROR "ZLIB_LIB_DIR and OUTPUT_NAME must both be set") |
| 16 | +if(NOT ZLIB_PREFIX OR NOT TARGET_PATH) |
| 17 | + message(FATAL_ERROR "ZLIB_PREFIX and TARGET_PATH must both be set") |
13 | 18 | endif() |
14 | 19 |
|
15 | | -set(_target "${ZLIB_LIB_DIR}/${OUTPUT_NAME}") |
16 | | - |
17 | | -file(GLOB _candidates "${ZLIB_LIB_DIR}/*.a" "${ZLIB_LIB_DIR}/*.lib") |
18 | | -list(REMOVE_ITEM _candidates "${_target}") |
| 20 | +file(GLOB _candidates |
| 21 | + "${ZLIB_PREFIX}/lib/*.a" |
| 22 | + "${ZLIB_PREFIX}/lib/*.lib" |
| 23 | + "${ZLIB_PREFIX}/lib64/*.a" |
| 24 | + "${ZLIB_PREFIX}/lib64/*.lib" |
| 25 | + ) |
| 26 | +list(REMOVE_ITEM _candidates "${TARGET_PATH}") |
19 | 27 |
|
20 | 28 | list(LENGTH _candidates _count) |
21 | 29 | if(_count EQUAL 0) |
22 | 30 | message(FATAL_ERROR |
23 | | - "No static zlib library found in ${ZLIB_LIB_DIR}. zlib-ng did not install what was " |
24 | | - "expected -- check that BUILD_SHARED_LIBS was OFF.") |
| 31 | + "No static zlib library found under ${ZLIB_PREFIX} (searched lib/ and lib64/). " |
| 32 | + "zlib-ng did not install what was expected -- check that BUILD_SHARED_LIBS was OFF.") |
25 | 33 | endif() |
26 | 34 | if(_count GREATER 1) |
27 | 35 | # More than one archive means the naming assumption has drifted, and silently picking the |
28 | 36 | # first would be how a subtly wrong zlib gets linked into every downstream project. |
29 | 37 | message(FATAL_ERROR |
30 | | - "Expected exactly one static zlib library in ${ZLIB_LIB_DIR}, found ${_count}: " |
| 38 | + "Expected exactly one static zlib library under ${ZLIB_PREFIX}, found ${_count}: " |
31 | 39 | "${_candidates}") |
32 | 40 | endif() |
33 | 41 |
|
34 | 42 | list(GET _candidates 0 _source) |
35 | | -file(COPY_FILE "${_source}" "${_target}" ONLY_IF_DIFFERENT) |
36 | | -message(STATUS "zlib: ${_source} -> ${_target}") |
| 43 | +get_filename_component(_target_dir "${TARGET_PATH}" DIRECTORY) |
| 44 | +file(MAKE_DIRECTORY "${_target_dir}") |
| 45 | +file(COPY_FILE "${_source}" "${TARGET_PATH}" ONLY_IF_DIFFERENT) |
| 46 | +message(STATUS "zlib: ${_source} -> ${TARGET_PATH}") |
0 commit comments