ldc
ldc copied to clipboard
Make ExtractDMDSystemLinker.cmake compatible with `-target`
I need this fix when the system D compiler has -target
in its default linker line
I just hit this when trying to build LDC locally with LDC 1.36.0 universal, because our ldc2.conf contains:
"-Xcc=-target",
"-Xcc=arm64-apple-macos",
Updated the PR to use target_link_options. This increases the CMake requirement from 3.4 to 3.13. Note that LLVM requires v3.20.
reverted to the old solution if CI likes that better; perhaps somehow the flags are not passed correctly for some of the CI cases with more complex flag setups
This patch without using target_link_options
does not work with the -arch
flag that LDC 1.37 universal macOS package uses. (although CI does like that version)
The difference between target_link_options
and target_link_libraries
is that the first adds flags at start of commandline, the latter at the end.
There are some other small deltas:
target_link_options
[108/1132] : && /usr/bin/c++ -DDMDV2 -O3 -DNDEBUG -m64 -Xlinker --export-dynamic -L/opt/hostedtoolcache/dc/dmd-2.107.1-rc.1/x64/dmd2/linux/bin64/../lib64 -Bstatic -lphobos2 -Bdynamic -lpthread -lm -lrt -ldl obj/ldc2.o -o bin/ldc2 lib/libldc.a <LLVM libs> -lz -lrt -ldl -lpthread -lm -Wl,--export-dynamic -ldl && :
target_link_libraries
[108/1132] : && /usr/bin/c++ -DDMDV2 -O3 -DNDEBUG obj/ldc2.o -o bin/ldc2 lib/libldc.a <LLVM libs> -lz -lrt -ldl -lpthread -lm -Wl,--export-dynamic -m64 -Xlinker --export-dynamic -L/opt/hostedtoolcache/dc/dmd-2.107.1-rc.1/x64/dmd2/linux/bin64/../lib64 -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl -ldl -lpthread -lm && :
There is also this note in CMake documentation about target_link_options
, that I do not yet know whether it is important for us:
Note This command cannot be used to add options for static library targets, since they do not use a linker.
I think I have it working well now. Will clean up after CI confirms.
Thx, just in time for v1.37. :)