ldc icon indicating copy to clipboard operation
ldc copied to clipboard

Make ExtractDMDSystemLinker.cmake compatible with `-target`

Open JohanEngelen opened this issue 1 year ago • 3 comments

I need this fix when the system D compiler has -target in its default linker line

JohanEngelen avatar Jul 06 '23 21:07 JohanEngelen

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",

JohanEngelen avatar Feb 27 '24 20:02 JohanEngelen

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.

JohanEngelen avatar Feb 27 '24 21:02 JohanEngelen

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

JohanEngelen avatar Feb 27 '24 22:02 JohanEngelen

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)

JohanEngelen avatar Feb 29 '24 19:02 JohanEngelen

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.

JohanEngelen avatar Mar 01 '24 10:03 JohanEngelen

I think I have it working well now. Will clean up after CI confirms.

JohanEngelen avatar Mar 01 '24 11:03 JohanEngelen

Thx, just in time for v1.37. :)

kinke avatar Mar 01 '24 12:03 kinke