Skip to content

Commit 7f5fe30

Browse files
committed
[cmake] Only set deps for an ExternalProject if the type is executable or library
Summary: cmake fails with an error when attempting to evaluate $<TARGET_FILE:tgt> where `tgt` is defined via an `add_custom_target` and thus the `TYPE` is `UTILITY`. Requesting a TARGET_FILE only works on an `EXECUTABLE` or one of a few differetnt types of `X_LIBRARY` (e.g. added via `add_library` or `add_executable`). The logic as implemented in cmake is below: enum TargetType { EXECUTABLE, STATIC_LIBRARY, SHARED_LIBRARY, MODULE_LIBRARY, OBJECT_LIBRARY, UTILITY, GLOBAL_TARGET, INTERFACE_LIBRARY, UNKNOWN_LIBRARY }; if (target->GetType() >= cmStateEnums::OBJECT_LIBRARY && target->GetType() != cmStateEnums::UNKNOWN_LIBRARY) { ::reportError(context, content->GetOriginalExpression(), "Target \"" + name + "\" is not an executable or library."); return nullptr; } This has always been the case back to at least 3.12 (furthest I checked) but this is causing a new failure in cmake 3.17 while evaluating ExternalProjectAdd. Subscribers: mgorny, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77284
1 parent bcd8009 commit 7f5fe30

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

llvm/cmake/modules/LLVMExternalProjectUtils.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ function(llvm_ExternalProject_Add name source_dir)
6262
foreach(tool ${ARG_TOOLCHAIN_TOOLS})
6363
if(TARGET ${tool})
6464
list(APPEND TOOLCHAIN_TOOLS ${tool})
65-
list(APPEND TOOLCHAIN_BINS $<TARGET_FILE:${tool}>)
65+
66+
# $<TARGET_FILE:tgt> only works on add_executable or add_library targets
67+
# The below logic mirrors cmake's own implementation
68+
get_target_property(target_type "${tool}" TYPE)
69+
if(NOT target_type STREQUAL "OBJECT_LIBRARY" AND
70+
NOT target_type STREQUAL "UTILITY" AND
71+
NOT target_type STREQUAL "GLOBAL_TARGET" AND
72+
NOT target_type STREQUAL "INTERFACE_LIBRARY")
73+
list(APPEND TOOLCHAIN_BINS $<TARGET_FILE:${tool}>)
74+
endif()
75+
6676
endif()
6777
endforeach()
6878

0 commit comments

Comments
 (0)