This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Only set deps for an ExternalProject if the type is executable or library
ClosedPublic

Authored by lanza on Apr 1 2020, 8:28 PM.

Details

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.

Diff Detail

Event Timeline

lanza created this revision.Apr 1 2020, 8:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2020, 8:29 PM
This revision was not accepted when it landed; it landed in state Needs Review.Apr 1 2020, 8:42 PM
This revision was automatically updated to reflect the committed changes.