This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Replace list(FIND) by if(IN_LIST) where index isn't used
ClosedPublic

Authored by aaronpuchert on Jan 23 2023, 2:34 PM.

Details

Summary

If we don't use the index otherwise, if(IN_LIST) is more readable and
doesn't clutter the local scope with index variables.

This was pointed out by @beanz in D96670.

Diff Detail

Event Timeline

aaronpuchert created this revision.Jan 23 2023, 2:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 2:34 PM
Herald added a subscriber: arphaman. · View Herald Transcript
aaronpuchert requested review of this revision.Jan 23 2023, 2:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 2:34 PM
beanz accepted this revision.Jan 23 2023, 2:44 PM

LGTM. Thank you for the nice cleanup :D

This revision is now accepted and ready to land.Jan 23 2023, 2:44 PM
aaronpuchert added inline comments.Jan 23 2023, 2:48 PM
llvm/cmake/modules/TableGen.cmake
45–54
beanz added inline comments.Jan 23 2023, 2:52 PM
llvm/cmake/modules/TableGen.cmake
45–54

You're inside a function here, so that should be fine...

aaronpuchert marked an inline comment as done.Jan 23 2023, 2:58 PM
aaronpuchert added inline comments.
llvm/cmake/modules/TableGen.cmake
45–54

Right, this isn't a macro. Thanks for clarifying that.

This revision was landed with ongoing or failed builds.Jan 23 2023, 2:59 PM
This revision was automatically updated to reflect the committed changes.
aaronpuchert marked an inline comment as done.

@beanz, a configuration error caused by this in a third-party project has been reported to me:

CMake Warning (dev) at /usr/lib/llvm-16/lib/cmake/llvm/LLVM-Config.cmake:230 (if):
  Policy CMP0057 is not set: Support new IN_LIST if() operator.  Run "cmake
  --help-policy CMP0057" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  IN_LIST will be interpreted as an operator when the policy is set to NEW.
  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  clang_delta/CMakeLists.txt:465 (llvm_map_components_to_libnames)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at /usr/lib/llvm-16/lib/cmake/llvm/LLVM-Config.cmake:230 (if):
  if given arguments:

    "engine" "IN_LIST" "link_components"

The project has cmake_minimum_required(VERSION 2.8.12) and is now running afoul CMP0057:

CMake 3.3 adds support for the new IN_LIST operator.

The OLD behavior for this policy is to ignore the IN_LIST operator. The NEW behavior is to interpret the IN_LIST operator.

This policy was introduced in CMake version 3.3. CMake version 3.25.2 warns when the policy is not set and uses OLD behavior. Use the cmake_policy() command to set it to OLD or NEW explicitly.

This doesn't affect us internally because we have cmake_minimum_required(VERSION 3.13.4), but should we add cmake_policy(SET CMP0057 NEW) to the exported files? Perhaps in a PUSH/POP?

This doesn't affect us internally because we have cmake_minimum_required(VERSION 3.13.4), but should we add cmake_policy(SET CMP0057 NEW) to the exported files? Perhaps in a PUSH/POP?

IMO, this is a problem for the downstream project.

We require CMake 3.13.4 for building LLVM which allows us to use CMake 3.13 features in our CMake modules. Any project using LLVM’s CMake modules _should_ have the same requirement. If we were going to do anything to address this, the approach I would take would be to make importing the LLVM CMake modules a fatal error if CMAKE_MINIMUM_REQUIRED_VERSION is less than 3.13.4.

Supporting some parts of LLVM’s CMake on older required versions is not going to be trivial, and I don’t think we should do it.

Not sure if @phosek, @smeenai, @compnerd, or @ldionne have different thoughts.

This doesn't affect us internally because we have cmake_minimum_required(VERSION 3.13.4), but should we add cmake_policy(SET CMP0057 NEW) to the exported files? Perhaps in a PUSH/POP?

IMO, this is a problem for the downstream project.

We require CMake 3.13.4 for building LLVM which allows us to use CMake 3.13 features in our CMake modules. Any project using LLVM’s CMake modules _should_ have the same requirement. If we were going to do anything to address this, the approach I would take would be to make importing the LLVM CMake modules a fatal error if CMAKE_MINIMUM_REQUIRED_VERSION is less than 3.13.4.

Supporting some parts of LLVM’s CMake on older required versions is not going to be trivial, and I don’t think we should do it.

Not sure if @phosek, @smeenai, @compnerd, or @ldionne have different thoughts.

I agree, supporting older CMake versions has never been our goal, the fact that it works today is just a coincidence. I also support including an explicit version check in exported files.