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 Mar 30 2020, 5:30 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 LIBRARY type (e.g. added via add_library or add_executable).

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.Mar 30 2020, 5:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2020, 5:30 PM
smeenai requested changes to this revision.Mar 31 2020, 10:29 AM
smeenai added reviewers: phosek, compnerd.
smeenai added inline comments.
llvm/cmake/modules/LLVMExternalProjectUtils.cmake
68

Should be STREQUAL instead of SREQUAL on the second one.

68

Nit: it's more common in LLVM to have no space after the if, i.e. if( instead of if (

68

https://cmake.org/cmake/help/latest/prop_tgt/TYPE.html says the library types are "SHARED_LIBRARY", "STATIC_LIBRARY", etc. Does just "LIBRARY" work?

To be fair, I don't know if we even want libraries in this list. But if you wanna fix the CMake issue while having the least chance of changing existing behavior, a blacklist might be easier than a whitelist?

This revision now requires changes to proceed.Mar 31 2020, 10:29 AM
lanza updated this revision to Diff 254263.Apr 1 2020, 11:44 AM
lanza marked 4 inline comments as done.

update

llvm/cmake/modules/LLVMExternalProjectUtils.cmake
68

The actual implementation that causes this problem is.

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;
    }
...

So I guess I'll just replicate this check.

lanza updated this revision to Diff 254265.Apr 1 2020, 11:49 AM

fix message

Harbormaster completed remote builds in B51322: Diff 254263.
smeenai accepted this revision.Apr 1 2020, 4:32 PM

Sure, works for me.

Might be worth adding a comment that this is mirroring logic in CMake, and that CMake 3.17+ error out if you try to use $<TARGET_FILE:...> on an unsupported target.

This revision is now accepted and ready to land.Apr 1 2020, 4:32 PM