Skip to content

Commit

Permalink
cmake: allow building liblphobos with system zlib
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuyu committed Jul 31, 2024
1 parent 48c1dff commit 1fa09c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ include(HandleLTOPGOBuildOptions)
#
set(LDC_DYNAMIC_COMPILE "AUTO" CACHE STRING "Support dynamic compilation (ON|OFF). Enabled by default; not supported for LLVM >= 12.")
option(LDC_DYNAMIC_COMPILE_USE_CUSTOM_PASSES "Use custom LDC passes in jit" ON)
option(LDC_PHOBOS_USE_SYSTEM_ZLIB "Use system zlib instead of bundled zlib in libphobos" OFF)
if(LDC_DYNAMIC_COMPILE STREQUAL "AUTO")
if(LDC_LLVM_VER LESS 1200)
set(LDC_DYNAMIC_COMPILE ON)
Expand All @@ -461,6 +462,10 @@ if(LDC_DYNAMIC_COMPILE)
add_definitions(-DLDC_DYNAMIC_COMPILE)
add_definitions(-DLDC_DYNAMIC_COMPILE_API_VERSION=3)
endif()
if(LDC_PHOBOS_USE_SYSTEM_ZLIB)
find_package(ZLIB 1.3 REQUIRED)
message(STATUS "Building LDC with system zlib version ${ZLIB_VERSION}")
endif()

#
# Includes, defines.
Expand Down
8 changes: 8 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ if("${C_SYSTEM_LIBS}" STREQUAL "AUTO")
else()
set(C_SYSTEM_LIBS_SHARED ${C_SYSTEM_LIBS})
endif()
if(LDC_PHOBOS_USE_SYSTEM_ZLIB)
list(APPEND C_SYSTEM_LIBS ZLIB::ZLIB)
list(APPEND C_SYSTEM_LIBS_SHARED ZLIB::ZLIB)
endif()

message(STATUS "-- LDC runtime configuration:")
message(STATUS "-- - Building 32/64-bit libraries (MULTILIB): ${MULTILIB}")
Expand Down Expand Up @@ -252,6 +256,10 @@ if(PHOBOS2_DIR)
${PHOBOS2_DIR}/etc/c/zlib/test/minigzip.c
)
endif()
if(LDC_PHOBOS_USE_SYSTEM_ZLIB)
# filter out zlib C parts if system zlib is used
list(FILTER PHOBOS2_C EXCLUDE REGEX ".*/etc/c/zlib/.*\\.c")
endif()

#
# Create configuration files.
Expand Down

0 comments on commit 1fa09c5

Please sign in to comment.