diff --git a/CMakeLists.txt b/CMakeLists.txt index e1a2485eef..3f3e73bb2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,7 +132,7 @@ target_link_libraries(redex-all ${STATIC_LINK_FLAG} ${Boost_LIBRARIES} ${REDEX_JSONCPP_LIBRARY} - ${REDEX_ZLIB_LIBRARY} + ZLIB::ZLIB ${CMAKE_DL_LIBS} redex resource diff --git a/cmake_modules/Commons.cmake b/cmake_modules/Commons.cmake index 0a0d3a5311..f93e1e85b4 100644 --- a/cmake_modules/Commons.cmake +++ b/cmake_modules/Commons.cmake @@ -45,8 +45,14 @@ macro(add_dependent_packages_for_redex) set(Boost_USE_STATIC_RUNTIME ON) endif() set(Boost_USE_MULTITHREADED ON) + set(ZLIB_USE_STATIC_LIBS ON) endif() + find_package(Zlib REQUIRED) + + print_dirs("${ZLIB_INCLUDE_DIRS}" "ZLIB_INCLUDE_DIRS") + print_dirs("${ZLIB_LIBRARIES}" "ZLIB_LIBRARIES") + find_package(Boost 1.71.0 REQUIRED COMPONENTS regex filesystem program_options iostreams thread) print_dirs("${Boost_INCLUDE_DIRS}" "Boost_INCLUDE_DIRS") print_dirs("${Boost_LIBRARIES}" "Boost_LIBRARIES") @@ -73,20 +79,6 @@ macro(add_dependent_packages_for_redex) set(ZLIB_HOME "/usr/local/opt/zlib/") endif () - find_package(Zlib REQUIRED) - - print_dirs(${ZLIB_STATIC_LIB} "ZLIB_STATIC_LIB") - print_dirs(${ZLIB_SHARED_LIB} "ZLIB_SHARED_LIB") - - if (ENABLE_STATIC) - set(REDEX_ZLIB_LIBRARY ${ZLIB_STATIC_LIB}) - else () - set(REDEX_ZLIB_LIBRARY ${ZLIB_SHARED_LIB}) - endif () - - print_dirs("${ZLIB_INCLUDE_DIRS}" "ZLIB_INCLUDE_DIRS") - print_dirs("${REDEX_ZLIB_LIBRARY}" "REDEX_ZLIB_LIBRARY") - endmacro() function(set_link_whole target_name lib_name) diff --git a/cmake_modules/FindZlib.cmake b/cmake_modules/FindZlib.cmake index 0ef800af06..e350c77137 100644 --- a/cmake_modules/FindZlib.cmake +++ b/cmake_modules/FindZlib.cmake @@ -83,6 +83,24 @@ if (ZLIB_FOUND) message(STATUS "Found the ZLIB library: ${ZLIB_LIBRARIES}") endif () endif () + + # Need to export as target as modern cmake does it. + set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) + + # Fix up ZLIB_LIBRARIES for the static result if necessary. + if (ZLIB_USE_STATIC_LIBS) + set(ZLIB_LIBRARIES ${ZLIB_STATIC_LIB}) + else() + set(ZLIB_LIBRARIES ${ZLIB_SHARED_LIB}) + endif() + + if(NOT TARGET ZLIB::ZLIB) + add_library(ZLIB::ZLIB UNKNOWN IMPORTED) + set_target_properties(ZLIB::ZLIB PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}") + set_property(TARGET ZLIB::ZLIB APPEND PROPERTY + IMPORTED_LOCATION "${ZLIB_LIBRARIES}") + endif() else () if (NOT ZLIB_FIND_QUIETLY) set(ZLIB_ERR_MSG "Could not find the ZLIB library. Looked in ")