cppit/libclangmm

LibClang error when used as submodule

minexew opened this issue · 5 comments

On Fedora 26, CMake fails with the following output: (note: i'm using libclangmm as a submodule -- not that it should make any difference)

Searcing for libclang
CMake Error at libclangmm/src/CMakeLists.txt:12 (find_package):
  By not providing "FindLibClang.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "LibClang",
  but CMake did not find one.

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

    LibClangConfig.cmake
    libclang-config.cmake

  Add the installation prefix of "LibClang" to CMAKE_PREFIX_PATH or set
  "LibClang_DIR" to a directory containing one of the above files.  If
  "LibClang" provides a separate development package or SDK, be sure it has
  been installed.


-- Configuring incomplete, errors occurred!
See also "clang-experiments/CMakeFiles/CMakeOutput.log".

Curiously enough, Fedora provides ClangConfig.cmake (without the Lib). After modifying libclangmm's CMakeFiles to find_package(Clang), the build is successful, though I assume that breaks it for other distros.

For some reason, ClangConfig.cmake also pulls in static libLLVM as a dependency (130 MB!), although this isn't required if I link against libclang manually. Is there a way to bypass the find_package altogether and specify libclang include/lib paths manually? (preferably without modifying libclangmm's CMakeLists)

You need to run cmake against the top level CMakeLists.txt file of a project. For instance, this will result in the above error:

git clone https://github.com/cppit/libclangmm
cd libclangmm
mkdir build
cd build
cmake ../src

However, this is the correct way:

git clone https://github.com/cppit/libclangmm
cd libclangmm
mkdir build
cd build
cmake ..

Consider this:

mkdir my_project && cd my_project
git submodule add https://github.com/cppit/libclangmm
echo 'add_subdirectory(libclangmm)' >CMakeLists.txt
cmake .

What's the solution in that case?

I am not a CMake expert, but this is one way to do it:
image

Yeah, but that's a very non-CMake way to do it.

I guess that adding

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")

to clangmm's top-level CMakeLists would fix the error.

In the end I just went with the plain libclang.

Thank you, I did a cleanup of the CMakeLists.txt files now