[llvm] 7f5fe30 - [cmake] Only set deps for an ExternalProject if the type is executable or library
Nathan Lanza via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 1 20:32:14 PDT 2020
Author: Nathan Lanza
Date: 2020-04-01T23:29:01-04:00
New Revision: 7f5fe30a150e7e87d3fbe4da4ab0e76ec38b40b9
URL: https://github.com/llvm/llvm-project/commit/7f5fe30a150e7e87d3fbe4da4ab0e76ec38b40b9
DIFF: https://github.com/llvm/llvm-project/commit/7f5fe30a150e7e87d3fbe4da4ab0e76ec38b40b9.diff
LOG: [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
Added:
Modified:
llvm/cmake/modules/LLVMExternalProjectUtils.cmake
Removed:
################################################################################
diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
index 29f4fcbf8aba..4eb5fad85634 100644
--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -62,7 +62,17 @@ function(llvm_ExternalProject_Add name source_dir)
foreach(tool ${ARG_TOOLCHAIN_TOOLS})
if(TARGET ${tool})
list(APPEND TOOLCHAIN_TOOLS ${tool})
- list(APPEND TOOLCHAIN_BINS $<TARGET_FILE:${tool}>)
+
+ # $<TARGET_FILE:tgt> only works on add_executable or add_library targets
+ # The below logic mirrors cmake's own implementation
+ get_target_property(target_type "${tool}" TYPE)
+ if(NOT target_type STREQUAL "OBJECT_LIBRARY" AND
+ NOT target_type STREQUAL "UTILITY" AND
+ NOT target_type STREQUAL "GLOBAL_TARGET" AND
+ NOT target_type STREQUAL "INTERFACE_LIBRARY")
+ list(APPEND TOOLCHAIN_BINS $<TARGET_FILE:${tool}>)
+ endif()
+
endif()
endforeach()
More information about the llvm-commits
mailing list