Skip to content

Commit

Permalink
"Modernize" FindZlib
Browse files Browse the repository at this point in the history
Summary: reserved

Differential Revision: D68047031
  • Loading branch information
agampe authored and facebook-github-bot committed Jan 11, 2025
1 parent 66c8ea4 commit 956a435
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 6 additions & 14 deletions cmake_modules/Commons.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions cmake_modules/FindZlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ")
Expand Down

0 comments on commit 956a435

Please sign in to comment.