[cfe-dev] Out-of-tree CMake dependencies
Kim Gräsman via cfe-dev
cfe-dev at lists.llvm.org
Sun Oct 8 02:57:54 PDT 2017
Hi all,
I now have a draft version that seems to be working:
https://github.com/kimgr/include-what-you-use/blob/re-cmake/CMakeLists.txt
I needed to add `include (HandleLLVMOptions)` to get CFLAGS/CXXFLAGS
in place, otherwise I was able to use your example almost verbatim.
Both the build and FreeBSD packaging seem to put the LLVM and Clang
CMake modules in $PREFIX/lib/cmake, but the apt packages for Ubuntu
seem to scatter them:
$ find /usr -name "ClangConfig.cmake" -o -name "LLVMConfig.cmake" 2> /dev/null
/usr/lib/llvm-4.0/lib/cmake/llvm/LLVMConfig.cmake
/usr/share/llvm-4.0/cmake/ClangConfig.cmake
The corresponding layout on FreeBSD is:
$ find /usr/local -name "ClangConfig.cmake" -o -name
"LLVMConfig.cmake" 2> /dev/null
/usr/local/llvm40/lib/cmake/llvm/LLVMConfig.cmake
/usr/local/llvm40/lib/cmake/clang/ClangConfig.cmake
/usr/local/llvm39/lib/cmake/clang/ClangConfig.cmake
/usr/local/llvm39/lib/cmake/llvm/LLVMConfig.cmake
/usr/local/llvm-devel/lib/cmake/clang/ClangConfig.cmake
/usr/local/llvm-devel/lib/cmake/llvm/LLVMConfig.cmake
This makes the UX for IWYU's CMake painful, as we have to specify both
CMake search paths:
$ cmake -DIWYU_LLVM_CMAKE_DIR=/usr/lib/llvm-4.0/cmake
-DIWYU_CLANG_CMAKE_DIR=/usr/share/llvm-4.0/cmake
Could this be improved in the packaging, or is there a benefit to
keeping them separate? Am I missing some trick to make system packages
easier to pick up?
Thanks,
- Kim
On Thu, Oct 5, 2017 at 7:45 PM, Don Hinton <hintonda at gmail.com> wrote:
> You might also want to look at clang's CMakeLists.txt file. I can be build
> either in or out of tree (llvm tree), and handles a lot of this via
> llvm-config.
>
> hth...
> don
>
> On Wed, Oct 4, 2017 at 10:13 PM, Kim Gräsman <kim.grasman at gmail.com> wrote:
>>
>> Hi Don,
>>
>> Thanks, that looks like it might work! I'll post back with results
>> when I have them.
>>
>> - Kim
>>
>> On Wed, Oct 4, 2017 at 9:31 PM, Don Hinton <hintonda at gmail.com> wrote:
>> > This might help you get started (this is for out of tree pointing to my
>> > development build, but you could also point to the installed version if
>> > you
>> > have one).
>> >
>> > # if you only have/need LLVM:
>> > # export
>> > LLVM_DIR=/Users/dhinton/projects/llvm_project/build/Debug/lib/cmake/llvm
>> > # if you also have/need clang:
>> > # export
>> >
>> > CLANG_DIR=/Users/dhinton/projects/llvm_project/build/Debug/lib/cmake/clang
>> >
>> > # While just setting LLVM_DIR will make find_package work, you need to
>> > # add it to CMAKE_MODULE_PATH if you want to include AddLLVM, e.g., if
>> > # you want to use add_llvm_loadable_module.
>> > set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
>> > "$ENV{LLVM_DIR};$ENV{Clang_DIR}")
>> > #find_package(LLVM REQUIRED CONFIG)
>> > find_package(Clang REQUIRED CONFIG)
>> > include(AddLLVM)
>> > add_definitions(${LLVM_DEFINITIONS})
>> > include_directories(${LLVM_INCLUDE_DIRS})
>> > include_directories(${CLANG_INCLUDE_DIRS})
>> > link_directories(${LLVM_LIBRARY_DIRS})
>> >
>> > message("LLVM_DEFINITIONS = ${LLVM_DEFINITIONS}")
>> > message("LLVM_INCLUDE_DIRS = ${LLVM_INCLUDE_DIRS}")
>> > message("LLVM_LIBRARY_DIRS = ${LLVM_LIBRARY_DIRS}")
>> > message("CLANG_INCLUDE_DIRS = ${CLANG_INCLUDE_DIRS}")
>> >
>> > On Wed, Oct 4, 2017 at 11:39 AM, Kim Gräsman via cfe-dev
>> > <cfe-dev at lists.llvm.org> wrote:
>> >>
>> >> Hi all,
>> >>
>> >> In include-what-you-use, we recently had this bug report:
>> >> https://github.com/include-what-you-use/include-what-you-use/pull/465
>> >>
>> >> And it's symptomatic for a whole class of problems where we're
>> >> duplicating knowledge from the LLVM/Clang CMake systems to allow both
>> >> in-tree and out-of-tree IWYU development.
>> >>
>> >> (in our terminology, in-tree == cloning the include-what-you-use repo
>> >> into a full LLVM and Clang checkout/clone under
>> >> llvm/tools/clang/tools/include-what-you-use and out-of-tree == cloning
>> >> include-what-you-use anywhere, and giving CMake information about
>> >> where to find LLVM/Clang headers and libraries)
>> >>
>> >> Looking around my system, I see a lot of CMake modules in
>> >> /usr/lib/llvm-4.0 and /usr/share/llvm-4.0, but it's not clear to me
>> >> how to use them. Also, it would be nice to allow a "next-to-tree"
>> >> configuration instead of in-tree, where I can point IWYU at a trunk
>> >> checkout of LLVM and Clang and use its CMake modules.
>> >>
>> >> Is there a correct way to accomplish this?
>> >>
>> >> Thanks,
>> >> - Kim
>> >> _______________________________________________
>> >> cfe-dev mailing list
>> >> cfe-dev at lists.llvm.org
>> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>> >
>> >
>
>
More information about the cfe-dev
mailing list