Skip to content

Commit

Permalink
runtime/CMakeLists.txt: Depend only on the full path to the ldc binary
Browse files Browse the repository at this point in the history
For custom commands that require a built ldc2 specify only an absolute
path to compiler binary, not the target name. This is because cmake
handles file paths and target dependencies differently. In the case of
a target dependency the dependency doesn't actually apply to the
`add_custom_command`, it only affects future targets.

As an example, we want to built libruntime.a from a D file foo.d. What
we need to describe is:
1. compile foo.o from foo.d (depends on LDC)
2. archive libruntime.a from foo.o

If we use ${LDC_EXE} as a dependency (only the target name) cmake
would generate:
1. compile foo.o from foo.d
2. archive libruntime.a from foo.o (depends on LDC)

Using an absolute path for the LDC dependency does what we want it to do.

Signed-off-by: Andrei Horodniceanu <[email protected]>
  • Loading branch information
the-horo committed Sep 11, 2024
1 parent 1f0c36e commit dad1df5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ if(LDC_EXE)
"$<$<BOOL:${SHARED_LIBS_SUPPORTED}>:${MULTILIB_DIR}>"
${conf_path}.in
${conf_path}
DEPENDS ${LDC_EXE} ${LDC_EXE_FULL}
DEPENDS ${LDC_EXE_FULL}
)
add_custom_command(OUTPUT ${install_conf_path} VERBATIM
COMMAND ${PROJECT_PARENT_DIR}/tools/add-multilib-section.sh
Expand All @@ -347,7 +347,7 @@ if(LDC_EXE)
"$<$<BOOL:${SHARED_LIBS_SUPPORTED}>:${MULTILIB_INSTALL_DIR}>"
${install_conf_path}.in
${install_conf_path}
DEPENDS ${LDC_EXE} ${LDC_EXE_FULL}
DEPENDS ${LDC_EXE_FULL}
)
add_custom_target(add-multilib-section ALL
DEPENDS ${conf_path} ${install_conf_path}
Expand Down Expand Up @@ -437,7 +437,9 @@ macro(dc src_files src_basedir d_flags output_basedir emit_bc all_at_once single
list(APPEND dc_flags -flto=thin --output-bc)
endif()

set(dc_deps ${LDC_EXE} ${LDC_EXE_FULL} ${GCCBUILTINS})
# dc_deps can only contain paths, otherwise cmake will ignore the dependency.
# See: https://github.com/ldc-developers/ldc/pull/4743#issuecomment-2323156173
set(dc_deps ${LDC_EXE_FULL} ${GCCBUILTINS})
if(TARGET add-multilib-section)
# Make sure the config files are available before invoking LDC.
set(dc_deps ${dc_deps} add-multilib-section)
Expand Down

0 comments on commit dad1df5

Please sign in to comment.