Skip to content

Commit c2bfd71

Browse files
committed
CMake: Link Windows druntime & Phobos DLLs against *dynamic* MSVCRT
And add oldnames.lib and legacy_stdio_definitions.lib for the Phobos DLL, which are linked automatically with static druntime via pragma(lib) directives.
1 parent 5b5ada9 commit c2bfd71

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

runtime/CMakeLists.txt

+14-8
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,20 @@ endif()
115115
# Auto-detect C system libraries
116116
if("${C_SYSTEM_LIBS}" STREQUAL "AUTO")
117117
if("${TARGET_SYSTEM}" MATCHES "MSVC")
118-
set(C_SYSTEM_LIBS libvcruntime libcmt)
119-
elseif("${TARGET_SYSTEM}" MATCHES "Android")
120-
set(C_SYSTEM_LIBS m c)
121-
elseif("${TARGET_SYSTEM}" MATCHES "Linux")
122-
set(C_SYSTEM_LIBS m pthread rt dl)
118+
set(C_SYSTEM_LIBS libcmt libvcruntime)
119+
set(C_SYSTEM_LIBS_SHARED msvcrt vcruntime oldnames legacy_stdio_definitions)
123120
else()
124-
set(C_SYSTEM_LIBS m pthread)
121+
if("${TARGET_SYSTEM}" MATCHES "Android")
122+
set(C_SYSTEM_LIBS m c)
123+
elseif("${TARGET_SYSTEM}" MATCHES "Linux")
124+
set(C_SYSTEM_LIBS m pthread rt dl)
125+
else()
126+
set(C_SYSTEM_LIBS m pthread)
127+
endif()
128+
set(C_SYSTEM_LIBS_SHARED ${C_SYSTEM_LIBS})
125129
endif()
130+
else()
131+
set(C_SYSTEM_LIBS_SHARED ${C_SYSTEM_LIBS})
126132
endif()
127133

128134
message(STATUS "-- LDC runtime configuration:")
@@ -590,7 +596,7 @@ macro(build_runtime_libs druntime_o druntime_bc phobos2_o phobos2_bc c_flags ld_
590596
# libraries otherwise implicitly added by LDC to make it loadable from
591597
# C executables.
592598
if("${is_shared}" STREQUAL "ON")
593-
target_link_libraries(druntime-ldc${target_suffix} ${C_SYSTEM_LIBS})
599+
target_link_libraries(druntime-ldc${target_suffix} ${C_SYSTEM_LIBS_SHARED})
594600
endif()
595601

596602
list(APPEND ${outlist_targets} druntime-ldc${target_suffix})
@@ -608,7 +614,7 @@ macro(build_runtime_libs druntime_o druntime_bc phobos2_o phobos2_bc c_flags ld_
608614
# in order to exclude the druntime tests for the Phobos test runner.
609615
string(REPLACE "-unittest" "" target_suffix_without_unittest "${target_suffix}")
610616
target_link_libraries(phobos2-ldc${target_suffix}
611-
druntime-ldc${target_suffix_without_unittest} ${C_SYSTEM_LIBS})
617+
druntime-ldc${target_suffix_without_unittest} ${C_SYSTEM_LIBS_SHARED})
612618
endif()
613619

614620
list(APPEND ${outlist_targets} phobos2-ldc${target_suffix})

0 commit comments

Comments
 (0)