This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Fix incorrect handling of get_target_property failure
ClosedPublic

Authored by ctetreau on Jun 12 2020, 1:12 PM.

Details

Summary

add_unittest was checking that the result of get_target_property was not
"NOTFOUND", but despite what the documentation says, get_target_property
returns <the var>-NOTFOUND on failure.

Diff Detail

Event Timeline

ctetreau created this revision.Jun 12 2020, 1:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2020, 1:12 PM

Can you share the setup that triggers the error, so that we can reproduce it locally to test the patch?

ctetreau added a comment.EditedJun 16 2020, 10:59 AM

The following CMake invocation causes the issue for me:

cmake -G "Visual Studio 16 2019" -A x64 -Thost=x64 -DLLVM_TARGETS_TO_BUILD="all" -DLLVM_LIT_ARGS=-v -DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_ASSERTIONS:BOOL=ON -DLLVM_ENABLE_PROJECTS='all' [llvm repo dir]/llvm

I'm using CMake 3.15.5. Even assuming that this is a behavior change in CMake (nothing in my research while debugging this issue indicates to me that this is the case), "NOTFOUND" and "<varname>-NOTFOUND" are both falsey, and I would assume we aren't naming test suites any of the magic CMake falsey values (0, OFF, NO, FALSE, N, IGNORE, NOTFOUND, the empty string, or ends in the suffix -NOTFOUND), so this should be fine.

ctetreau planned changes to this revision.Jun 16 2020, 4:14 PM

It looks like after this patch CMake is dumping all the tests at the project root

ctetreau updated this revision to Diff 271244.Jun 16 2020, 4:28 PM

Apparently some falsey values are used elsewhere and it is not safe to just check if (NOT ${test_suite_folder})

llvm/cmake/modules/AddLLVM.cmake
1425

If I understand https://cmake.org/cmake/help/latest/command/if.html correctly,

if(test_suite_folder)

should work too. Can you test that?

ctetreau updated this revision to Diff 274201.Jun 29 2020, 12:26 PM

address code review issues

ctetreau marked an inline comment as done.Jun 29 2020, 12:28 PM
ctetreau added inline comments.
llvm/cmake/modules/AddLLVM.cmake
1425

I had originally put if(${test_suite_folder}), but it looks like the CMake language treats the string in the if as a variable and dereferences it instead of just checking to see if it's truthy.

Your version works just fine.

LGTM, under the assumption you validated it under the relevant setup.

This revision is now accepted and ready to land.Jun 29 2020, 1:48 PM
This revision was automatically updated to reflect the committed changes.

Hi, your git commit contains extra Phabricator tags. You can drop Reviewers: Subscribers: Tags: and the text Summary: from the git commit with the following script:

arcfilter () {
        arc amend
        git log -1 --pretty=%B | awk '/Reviewers:|Subscribers:/{p=1} /Reviewed By:|Differential Revision:/{p=0} !p && !/^Summary:$/ {sub(/^Summary: /,"");print}' | git commit --amend --date=now -F -
}

Reviewed By: is considered important by some people. Please keep the tag. (--date=now is my personal preference (author dates are usually not useful. Using committer dates can make log almost monotonic in time))

https://reviews.llvm.org/D80978 contains a git pre-push hook to automate this.