@@ -61,6 +61,10 @@ if (RT_SUPPORT_SANITIZERS)
61
61
list (APPEND D_FLAGS -d-version=SupportSanitizers )
62
62
endif ()
63
63
64
+ if (PHOBOS_SYSTEM_ZLIB )
65
+ message (STATUS "-- Building PHOBOS against system zlib" )
66
+ endif ()
67
+
64
68
# Auto-detect TARGET_SYSTEM from host
65
69
if ("${TARGET_SYSTEM} " STREQUAL "AUTO" )
66
70
set (TARGET_SYSTEM ${CMAKE_SYSTEM_NAME} )
@@ -243,14 +247,22 @@ if(PHOBOS2_DIR)
243
247
list (REMOVE_ITEM PHOBOS2_D ${PHOBOS2_D_WINDOWS} )
244
248
endif ()
245
249
246
- # Phobos C parts
247
- file (GLOB_RECURSE PHOBOS2_C ${PHOBOS2_DIR} /etc/*.c )
248
- # remove zlib test modules
249
- list (REMOVE_ITEM PHOBOS2_C
250
- ${PHOBOS2_DIR} /etc/c/zlib/test/example.c
251
- ${PHOBOS2_DIR} /etc/c/zlib/test/infcover.c
252
- ${PHOBOS2_DIR} /etc/c/zlib/test/minigzip.c
253
- )
250
+ if (PHOBOS_SYSTEM_ZLIB )
251
+ find_package (ZLIB REQUIRED )
252
+ else ()
253
+ # Phobos C parts
254
+ file (GLOB_RECURSE PHOBOS2_C ${PHOBOS2_DIR} /etc/*.c )
255
+ # remove zlib test modules
256
+ list (REMOVE_ITEM PHOBOS2_C
257
+ ${PHOBOS2_DIR} /etc/c/zlib/test/example.c
258
+ ${PHOBOS2_DIR} /etc/c/zlib/test/infcover.c
259
+ ${PHOBOS2_DIR} /etc/c/zlib/test/minigzip.c
260
+ )
261
+ CHECK_INCLUDE_FILE (unistd.h HAVE_UNISTD_H )
262
+ if (HAVE_UNISTD_H )
263
+ append ("-DHAVE_UNISTD_H" CMAKE_C_FLAGS )
264
+ endif ()
265
+ endif ()
254
266
endif ()
255
267
256
268
#
@@ -397,11 +409,6 @@ if("${TARGET_SYSTEM}" MATCHES "MSVC")
397
409
# warning C4996: zlib uses 'deprecated' POSIX names
398
410
append ("/wd4100 /wd4127 /wd4131 /wd4206 /wd4244 /wd4245 /wd4267 /wd4996" CMAKE_C_FLAGS_RELEASE )
399
411
endif ()
400
- CHECK_INCLUDE_FILE (unistd.h HAVE_UNISTD_H )
401
- if (HAVE_UNISTD_H )
402
- # Needed for zlib
403
- append ("-DHAVE_UNISTD_H" CMAKE_C_FLAGS )
404
- endif ()
405
412
# 2) Set all other CMAKE_C_FLAGS variants to CMAKE_C_FLAGS_RELEASE
406
413
set (variables
407
414
CMAKE_C_FLAGS_DEBUG
@@ -412,6 +419,16 @@ foreach(variable ${variables})
412
419
set (${variable} "${CMAKE_C_FLAGS_RELEASE} " )
413
420
endforeach ()
414
421
422
+ function (link_zlib phobos_target library_type )
423
+ if (PHOBOS_SYSTEM_ZLIB )
424
+ if (${library_type} STREQUAL "SHARED" )
425
+ target_link_libraries (${phobos_target} ZLIB::ZLIB )
426
+ endif ()
427
+ else ()
428
+ target_sources (${phobos_target} PRIVATE ${PHOBOS2_C} )
429
+ endif ()
430
+ endfunction ()
431
+
415
432
# Compiles the given D modules to object files, and if enabled, bitcode files.
416
433
# The paths of the output files are appended to outlist_o and outlist_bc, respectively.
417
434
macro (dc src_files src_basedir d_flags output_basedir emit_bc all_at_once single_obj_name outlist_o outlist_bc )
@@ -638,8 +655,8 @@ macro(build_runtime_libs druntime_o druntime_bc phobos2_o phobos2_bc c_flags ld_
638
655
list (APPEND ${outlist_targets} druntime-ldc${target_suffix} )
639
656
640
657
if (PHOBOS2_DIR )
641
- add_library (phobos2-ldc${target_suffix} ${library_type}
642
- ${phobos2_o } ${PHOBOS2_C } )
658
+ add_library (phobos2-ldc${target_suffix} ${library_type} ${phobos2_o} )
659
+ link_zlib ( phobos2-ldc${target_suffix } ${library_type } )
643
660
set_common_library_properties (phobos2-ldc${target_suffix}
644
661
phobos2-ldc${lib_suffix} ${output_path}
645
662
"${c_flags} " "${ld_flags} " ${is_shared}
@@ -669,8 +686,8 @@ macro(build_runtime_libs druntime_o druntime_bc phobos2_o phobos2_bc c_flags ld_
669
686
"${c_flags} " "${ld_flags} " OFF
670
687
)
671
688
672
- add_library (phobos2-ldc-lto${target_suffix} STATIC
673
- ${phobos2_bc} ${PHOBOS2_C} )
689
+ add_library (phobos2-ldc-lto${target_suffix} STATIC ${phobos2_bc} )
690
+ link_zlib ( phobos2-ldc-lto${target_suffix} STATIC )
674
691
set_common_library_properties (phobos2-ldc-lto${target_suffix}
675
692
phobos2-ldc-lto${lib_suffix} ${output_path}
676
693
"${c_flags} " "${ld_flags} " OFF
@@ -1004,6 +1021,9 @@ function(build_test_runners name_suffix path_suffix d_flags linkflags is_shared)
1004
1021
LINK_FLAGS ${linkflags}
1005
1022
LINK_DEPENDS ${tested_lib_path}
1006
1023
)
1024
+ if (PHOBOS_SYSTEM_ZLIB AND "${is_shared} " STREQUAL "OFF" )
1025
+ target_link_libraries (${phobos_name} ZLIB::ZLIB )
1026
+ endif ()
1007
1027
add_test (build -${phobos_name} "${CMAKE_COMMAND} " --build ${CMAKE_BINARY_DIR} --target ${phobos_name} )
1008
1028
set (_GLOBAL_TESTRUNNERS "${_GLOBAL_TESTRUNNERS} ;${phobos_name} " CACHE INTERNAL "" )
1009
1029
endif ()
0 commit comments