This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Use absolute paths for modules search
ClosedPublic

Authored by rovka on Sep 3 2020, 4:58 AM.

Details

Summary

For out of tree builds, the user generally needs to specify LLVM_DIR and
MLIR_DIR on the command line so that the correct LLVM and MLIR
installations are picked up.

If the provided paths are absolute, everything works fine, however for
buildbots it is customary to work with relative paths, and that makes it
difficult for CMake to find the right modules to include.

This patch changes CMakeLists.txt to convert LLVM_DIR and MLIR_DIR to
absolute paths before adding them to CMAKE_MODULE_PATH. The inputs are
assumed to be relative to the source directory (llvm-project/flang).

Diff Detail

Event Timeline

rovka created this revision.Sep 3 2020, 4:58 AM
rovka requested review of this revision.Sep 3 2020, 4:58 AM
PeteSteinfeld requested changes to this revision.Sep 3 2020, 8:02 AM

Thanks for working on this!

But I couldn't get it working for me. Here's what I tried.

I started with an existing full build that includes llvm and mlir. The full path of this build is /local/home/psteinfeld/master/b4/build/. I have a script that does an out-of tree build based on this full build. Here's the script:

#!/bin/bash
cmake -G Ninja \
  -DFLANG_ENABLE_WERROR=On \
  -D LLVM_DIR=/local/home/psteinfeld/master/b4/build/lib/cmake/llvm \
  -D MLIR_DIR=/local/home/psteinfeld/master/b4/build/lib/cmake/mlir \
  -DCMAKE_BUILD_TYPE=Release ..

I then created a script that uses relative paths. Here's the contents of my new script:

#!/bin/bash
cmake -G Ninja \
  -DFLANG_ENABLE_WERROR=On \
  -D LLVM_DIR=../../../b4/build/lib/cmake/llvm \
  -D MLIR_DIR=../../../b4/build/lib/cmake/mlir \
  -DCMAKE_BUILD_TYPE=Release ..

I then downloaded the source into the directory /local/home/psteinfeld/master/diana/. I then "cd"ed to the "flang" directory and created a directory called "build" and did a "cd build". At this point, doing "pwd" yields "/local/home/psteinfeld/master/diana/flang/build". I then ran my new script. Running it produced the following errors:

...

  • Performing Test C_SUPPORTS_FDATA_SECTIONS
  • Performing Test C_SUPPORTS_FDATA_SECTIONS - Success
  • Performing Test CXX_SUPPORTS_FDATA_SECTIONS
  • Performing Test CXX_SUPPORTS_FDATA_SECTIONS - Success

CMake Error at CMakeLists.txt:81 (find_package):

Could not find a package configuration file provided by "MLIR" with any of
the following names:

  MLIRConfig.cmake
  mlir-config.cmake

Add the installation prefix of "MLIR" to CMAKE_PREFIX_PATH or set
"MLIR_DIR" to a directory containing one of the above files.  If "MLIR"
provides a separate development package or SDK, be sure it has been
installed.
  • Configuring incomplete, errors occurred!

See also "/local/home/psteinfeld/master/diana/flang/build/CMakeFiles/CMakeOutput.log".
See also "/local/home/psteinfeld/master/diana/flang/build/CMakeFiles/CMakeError.log".

This revision now requires changes to proceed.Sep 3 2020, 8:02 AM
rovka added a comment.Sep 4 2020, 2:05 AM

Thanks for trying this out!

That's a very surprising error, especially since the LLVM side of things seems to work just fine. I'll try to reproduce on my end.

rovka added a comment.Sep 7 2020, 4:16 AM

Hi Pete,

I can't seem to reproduce this on my end. Could you please tell me how you obtain the build in /local/home/psteinfeld/master/b4/build/ ?

For my testing I've been using something like this:

cmake -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_CXX_STANDARD=17 -DLLVM_ENABLE_WERROR=OFF -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=Release -GNinja '-DLLVM_ENABLE_PROJECTS=llvm;mlir' -DCMAKE_INSTALL_PREFIX=../install_llvm '-DLLVM_LIT_ARGS=-v -vv' ../llvm/llvm
tskeith added a subscriber: tskeith.Sep 8 2020, 8:05 AM

This worked fine for me.

Pete, it might be helpful to add these lines after MLIR_DIR_ABSOLUTE is set and see if it looks correct.

message("MLIR_DIR=${MLIR_DIR}")
message("MLIR_DIR_ABSOLUTE=${MLIR_DIR_ABSOLUTE}")
PeteSteinfeld accepted this revision.Sep 8 2020, 1:38 PM

I just tried again using paths relative to the location of CMakeLists.txt rather than the build directory, which for me is one level lower, and everything worked perfectly.

This revision is now accepted and ready to land.Sep 8 2020, 1:38 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2020, 5:00 AM
rovka added a comment.Sep 9 2020, 5:00 AM

Great, thanks! :)