Skip to content

Commit

Permalink
Use CMake's built-in zlib finder
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Ehlert committed Jul 11, 2021
1 parent 165773e commit 0949c41
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ set(LFORTRAN_STATIC_BIN no CACHE BOOL "Build LFortran as a static binary")
set(WITH_LFORTRAN_BINARY_MODFILES YES
CACHE BOOL "Use binary modfiles")

#ZLIB
find_package(ZLIB REQUIRED)
# Find ZLIB with our custom finder before including LLVM since the finder for LLVM
# might search for ZLIB again and find the shared libraries instead of the static ones
find_package(StaticZLIB REQUIRED)

# LLVM
set(WITH_LLVM no CACHE BOOL "Build with LLVM support")
Expand Down
12 changes: 12 additions & 0 deletions cmake/FindStaticZLIB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Backup the original value of the requested library suffixes
set(_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
# Static libraries end with .a on Unix and .lib on Windows
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib)

# Now use CMake's built-in ZLIB finder
find_package(ZLIB REQUIRED)

# Reset the library suffixes to the original value
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_CMAKE_FIND_LIBRARY_SUFFIXES})
# Unset the temporary to not pollute the global namespace
unset(_CMAKE_FIND_LIBRARY_SUFFIXES)
14 changes: 0 additions & 14 deletions cmake/FindZLIB.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion src/lfortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if (WITH_LLVM)
endif()
endif()
add_library(lfortran_lib ${SRC})
target_link_libraries(lfortran_lib lfortran_runtime_static p::zlib)
target_link_libraries(lfortran_lib lfortran_runtime_static ZLIB::ZLIB)
target_include_directories(lfortran_lib BEFORE PUBLIC ${lfortran_SOURCE_DIR}/src)
target_include_directories(lfortran_lib BEFORE PUBLIC ${lfortran_BINARY_DIR}/src)
if (WITH_XEUS)
Expand Down

0 comments on commit 0949c41

Please sign in to comment.