Skip to content

Commit 5d90b16

Browse files
authored
Avoid leaking pthread flags from zlib-ng.cmake (dotnet#119487)
See comment at the start of the file, add_compile_options() and add_linker_flag() will leak to the cmake projects which include zlib-ng.cmake.
1 parent 0001e1c commit 5d90b16

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/native/external/zlib-ng.cmake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ endif()
2323
if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
2424
# 'aligned_alloc' is not available in browser/wasi, yet it is set by zlib-ng/CMakeLists.txt.
2525
set(HAVE_ALIGNED_ALLOC FALSE CACHE BOOL "have aligned_alloc" FORCE)
26-
27-
# zlib-ng uses atomics, so we need to enable threads when requested for browser/wasi, otherwise the wasm target won't have thread support.
28-
if (CMAKE_USE_PTHREADS)
29-
add_compile_options(-pthread)
30-
add_linker_flag(-pthread)
31-
endif()
3226
endif()
3327

3428
if (MSVC)
@@ -49,4 +43,12 @@ target_compile_options(zlib PRIVATE $<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:
4943
target_compile_options(zlib PRIVATE $<$<COMPILE_LANG_AND_ID:C,MSVC>:/wd4127>) # warning C4127: conditional expression is constant
5044
target_compile_options(zlib PRIVATE $<$<COMPILE_LANG_AND_ID:C,MSVC>:/guard:cf>) # Enable CFG always for zlib-ng so we don't need to build two flavors.
5145

46+
if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
47+
# zlib-ng uses atomics, so we need to enable threads when requested for browser/wasi, otherwise the wasm target won't have thread support.
48+
if (CMAKE_USE_PTHREADS)
49+
target_compile_options(zlib PRIVATE -pthread)
50+
target_link_options(zlib PRIVATE -pthread)
51+
endif()
52+
endif()
53+
5254
set_target_properties(zlib PROPERTIES DEBUG_POSTFIX "") # Workaround: zlib's debug lib name is zlibd.lib

0 commit comments

Comments
 (0)