woboq / moc-ng

A reimplementation of Qt's moc using libclang. Contains both a drop-in remplacement, and a plugin for the clang compiler.
https://woboq.com/blog/moc-with-clang.html
GNU General Public License v3.0
204 stars 24 forks source link

Could not find any clang builtins headers in /usr/lib/llvm/7/lib64/clang/7.0.1/include #12

Closed Petross404 closed 5 years ago

Petross404 commented 5 years ago

I get the following output when I try to compile moc-ng with portage :

* checking ebuild checksums ;-) ...                                                                                                                                                                            [ ok ]
>>> Unpacking source...
 * Repository id: woboq_moc-ng.git
 * To override fetched repository properties, use:
 *   EGIT_OVERRIDE_REPO_WOBOQ_MOC_NG
 *   EGIT_OVERRIDE_BRANCH_WOBOQ_MOC_NG
 *   EGIT_OVERRIDE_COMMIT_WOBOQ_MOC_NG
 *   EGIT_OVERRIDE_COMMIT_DATE_WOBOQ_MOC_NG
 * 
 * Fetching https://github.com/woboq/moc-ng.git ...
git fetch https://github.com/woboq/moc-ng.git +HEAD:refs/git-r3/HEAD
git symbolic-ref refs/git-r3/dev-util/moc-ng/0/__main__ refs/git-r3/HEAD
 * Checking out https://github.com/woboq/moc-ng.git to /tmp/portage/dev-util/moc-ng-9999/work/moc-ng-9999 ...
git checkout --quiet refs/git-r3/HEAD
GIT update -->
   repository:               https://github.com/woboq/moc-ng.git
   at the commit:            4ceabc808071b50bf6ae5ccd6b2e481e5be91656
>>> Source unpacked in /tmp/portage/dev-util/moc-ng-9999/work
>>> Preparing source in /tmp/portage/dev-util/moc-ng-9999/work/moc-ng-9999 ...
>>> Source prepared.
>>> Configuring source in /tmp/portage/dev-util/moc-ng-9999/work/moc-ng-9999 ...
>>> Working in BUILD_DIR: "/tmp/portage/dev-util/moc-ng-9999/work/moc-ng-9999_build"
cmake -C /tmp/portage/dev-util/moc-ng-9999/work/moc-ng-9999_build/gentoo_common_config.cmake -G Unix Makefiles -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_CXX_COMPILER=/usr/lib/llvm/7/bin/clang++ -DLLVM_CONFIG_EXECUTABLE=/usr/lib/llvm/7/bin/llvm-config -DCMAKE_BUILD_TYPE=Gentoo -DCMAKE_TOOLCHAIN_FILE=/tmp/portage/dev-util/moc-ng-9999/work/moc-ng-9999_build/gentoo_toolchain.cmake  /tmp/portage/dev-util/moc-ng-9999/work/moc-ng-9999
loading initial cache file /tmp/portage/dev-util/moc-ng-9999/work/moc-ng-9999_build/gentoo_common_config.cmake
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/x86_64-pc-linux-gnu-gcc
-- Check for working C compiler: /usr/bin/x86_64-pc-linux-gnu-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/x86_64-pc-linux-gnu-g++
-- Check for working CXX compiler: /usr/bin/x86_64-pc-linux-gnu-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found LLVM 7.0.1
-- Using LLVMConfig.cmake in: /usr/lib/llvm/7/lib64/cmake/llvm
-- Found Clang in /usr/lib/llvm/7
CMake Error at src/CMakeLists.txt:81 (message):
  **Could not find any clang builtins headers in
  /usr/lib/llvm/7/lib64/clang/7.0.1/include**

-- Configuring incomplete, errors occurred!
See also "/tmp/portage/dev-util/moc-ng-9999/work/moc-ng-9999_build/CMakeFiles/CMakeOutput.log".
 * ERROR: dev-util/moc-ng-9999::testing failed (configure phase):
 *   cmake failed

And CMakeLists.txt is right because there is no such directory as /usr/lib/llvm/7/lib64/clang/7.0.1/include on my Gentoo system.

All there is under /usr/lib/llvm is this. It's a tree-representation of 5, 6 and 7th version of llvm/clang that are installed for me. Check under 7/ at Line 4021

I can create a patch but I will have to know what header files is cmake looking for so I can locate them correctly.

Thanks ;)

Petross404 commented 5 years ago

The following snippet works but I think it's not elegant :

# Embed the clang header into the binary:
string(REPLACE "svn" "" LLVM_VERSION "${LLVM_VERSION}")
string(REGEX REPLACE "git.*$" "" LLVM_VERSION "${LLVM_VERSION}")
if(NOT CLANG_BUILTIN_HEADERS_DIR)
    #Gentoo Linux systems use a different directory layout
    if(${CMAKE_BUILD_TYPE} MATCHES "Gentoo")
    set(CLANG_BUILTIN_HEADERS_DIR "${LLVM_LIBRARY_DIR}/../include/clang-c")
    else()
    set(CLANG_BUILTIN_HEADERS_DIR "${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION}/include")
    endif()
endif()

file(GLOB BUILTINS_HEADERS "${CLANG_BUILTIN_HEADERS_DIR}/*.h")

if(NOT BUILTINS_HEADERS)
    message(FATAL_ERROR "Could not find any clang builtins headers in ${CLANG_BUILTIN_HEADERS_DIR}")
endif()

You will notice that I use path/../. That's because ${LLVM_LIBRARY_DIR} points to /usr/lib/llvm/7/lib64/ but it's /usr/lib/llvm/7/ that contains a directory named include. Any idea to do this better?

EDIT: Further info from bash :

$pwd ; ls include/clang-c/
/usr/lib/llvm/7
BuildSystem.h            CXErrorCode.h  Documentation.h  Platform.h
CXCompilationDatabase.h  CXString.h     Index.h
ogoffart commented 5 years ago

What i'm trying to find here is not the libclang header, but the builtins header that need to be there for compilation. It is includes such as: inttypes.h avx2intrin.h stdarg.h stddef.h x86intrin.h ...

They are usually found in ../lib/clang/x.x/include , relative to the clang binary. Maybe then the cmake script should try to find the clang binary location, or find these particular headers

Petross404 commented 5 years ago
$ ls /usr/lib/clang/7.0.1/
include  lib  share

Yes you are right, I will re-adjust my patch. Thank you.