KDAB / codebrowser

Woboq CodeBrowser
http://woboq.com/codebrowser.html
Other
1.1k stars 161 forks source link

CMake Error: Could not find any clang builtins headers #107

Closed qaqland closed 12 months ago

qaqland commented 1 year ago
localhost:~/codebrowser$ cmake . -DCMAKE_BUILD_TYPE=Release
-- The CXX compiler identification is GNU 12.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The C compiler identification is GNU 12.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test HAVE_FFI_CALL
-- Performing Test HAVE_FFI_CALL - Success
-- Found FFI: /usr/lib/libffi.so
-- Found ZLIB: /lib/libz.so (found version "1.2.13")
-- Found zstd: /usr/lib/libzstd.so
-- Found LibXml2: /usr/lib/libxml2.so (found version "2.10.3")
-- Found LLVM 15.0.7 in /usr/lib/llvm15
-- Using LLVMConfig.cmake in: /usr/lib/cmake/llvm15
-- Found Clang in /usr
CMake Error at generator/CMakeLists.txt:77 (message):
  Could not find any clang builtins headers in
  /usr/lib/llvm15/lib/clang/15.0.7/include

-- Configuring incomplete, errors occurred!
See also "/home/qaq/codebrowser/CMakeFiles/CMakeOutput.log".

My system is Alpine Linux 3.17.1 x86_64 with all(maybe) dependences installed.

It seems that headers are not put at here:

localhost:/usr/lib/llvm15$ ls -al
total 80
drwxr-xr-x    5 root     root          4096 Feb  8 21:27 .
drwxr-xr-x   32 root     root         36864 Feb  8 22:01 ..
drwxr-xr-x    2 root     root         12288 Feb  8 21:27 bin
lrwxrwxrwx    1 root     root            20 Feb  8 21:27 include -> ../../include/llvm15
drwxr-xr-x    3 root     root         20480 Feb  8 21:33 lib
drwxr-xr-x    3 root     root          4096 Feb  8 21:24 share
qaqland commented 1 year ago

Following changes work!

cmake_minimum_required(VERSION 3.1)
project(codebrowser_generator)

Find_Package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} in ${LLVM_INSTALL_PREFIX}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
Find_Package(Clang REQUIRED CONFIG HINTS "${LLVM_INSTALL_PREFIX}/lib/cmake/clang")
message(STATUS "Found Clang in ${CLANG_INSTALL_PREFIX}")

##### Mod here #####
include_directories(${LLVM_INCLUDE_DIRS})

add_executable(codebrowser_generator main.cpp projectmanager.cpp annotator.cpp generator.cpp preprocessorcallback.cpp
               filesystem.cpp qtsupport.cpp commenthandler.cpp ${CMAKE_CURRENT_BINARY_DIR}/projectmanager_systemprojects.cpp)
target_include_directories(codebrowser_generator PRIVATE "${CMAKE_CURRENT_LIST_DIR}")

if (${LLVM_VERSION} VERSION_LESS "10.0.0")
    target_link_libraries(codebrowser_generator PRIVATE
        clangFrontend
        clangParse
        clangSema
        clangAST
        clangBasic
        clangLex
        clangTooling
        clangSerialization
    )
else()
    target_link_libraries(codebrowser_generator PRIVATE clang-cpp)
endif()

if(TARGET LLVM)
  target_link_libraries(codebrowser_generator PRIVATE LLVM)
else()
  # We cannot use llvm_config() here because in some versions it uses PRIVATE when calling target_link_libraries
  # and in some it doesn't. If our calls of target_link_libraries don't do it the same way, we get a
  # fatal error.
  llvm_map_components_to_libnames(llvm_libs core support)
  target_link_libraries(codebrowser_generator PRIVATE ${llvm_libs})
endif()

install(TARGETS codebrowser_generator RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
target_include_directories(codebrowser_generator SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
set_property(TARGET codebrowser_generator PROPERTY CXX_STANDARD 14)

if (NOT APPLE AND NOT MSVC)
    #  Don't link with libs that overlaps our options
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed" )
endif()

# System include dirs
if(WIN32)
    message(STATUS "Adding the following dirs as system projects")
    foreach(dir $ENV{INCLUDE})
        list(APPEND SYSTEM_INCLUDE_DIRS "include;${dir}")
    endforeach()
else()
    list(APPEND SYSTEM_INCLUDE_DIRS "include;/usr/include/")
endif()
string(REPLACE "\\" "/" SYSTEM_INCLUDE_DIRS "${SYSTEM_INCLUDE_DIRS}")
configure_file(projectmanager_systemprojects.cpp.in projectmanager_systemprojects.cpp)

# if(NOT MSVC)
# # Flags not supported by MSVC
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")

# TODO: Split up files and insert them row by row because
# MSVC only accepts strings of 2^16 bytes length (~65kb)

# 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)
#     set(CLANG_BUILTIN_HEADERS_DIR "${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION}/include")
# 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()
# foreach(BUILTIN_HEADER ${BUILTINS_HEADERS})
#     #filter files that are way to big
#     if(NOT BUILTIN_HEADER MATCHES ".*/(arm_neon.h|altivec.h|vecintrin.h|avx512.*intrin.h)")
#         file(READ ${BUILTIN_HEADER} BINARY_DATA)
#         string(REPLACE "\\" "\\\\" BINARY_DATA "${BINARY_DATA}")
#         string(REPLACE "\"" "\\\"" BINARY_DATA "${BINARY_DATA}")
#         string(REPLACE "\n" "\\n\"\n\"" BINARY_DATA "${BINARY_DATA}")
#         #workaround the fact that stdint.h includes itself
#         string(REPLACE "__CLANG_STDINT_H" "__CLANG_STDINT_H2" BINARY_DATA "${BINARY_DATA}")
#         string(REPLACE "${CLANG_BUILTIN_HEADERS_DIR}/" "/builtins/" FN "${BUILTIN_HEADER}"  )
#         set(EMBEDDED_DATA "${EMBEDDED_DATA} { \"${FN}\" , \"${BINARY_DATA}\" } , \n")
#     endif()
# endforeach()
# endif()

configure_file(embedded_includes.h.in embedded_includes.h)
target_include_directories(codebrowser_generator PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
Waqar144 commented 1 year ago

Not really, you disabled the embedded includes. Resulting website will be not very usable and will have tons of errors

qaqland commented 1 year ago
diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt
index c65cf97..b86dc23 100644
--- a/generator/CMakeLists.txt
+++ b/generator/CMakeLists.txt
@@ -37,7 +37,7 @@ else()
 endif()

 install(TARGETS codebrowser_generator RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-target_include_directories(codebrowser_generator SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS})
+target_include_directories(codebrowser_generator SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS})
 set_property(TARGET codebrowser_generator PROPERTY CXX_STANDARD 14)

@@ -70,7 +70,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
 string(REPLACE "svn" "" LLVM_VERSION "${LLVM_VERSION}")
 string(REGEX REPLACE "git.*$" "" LLVM_VERSION "${LLVM_VERSION}")
 if(NOT CLANG_BUILTIN_HEADERS_DIR)
-    set(CLANG_BUILTIN_HEADERS_DIR "${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION}/include")
+    set(CLANG_BUILTIN_HEADERS_DIR "/usr/lib/clang/${LLVM_VERSION}/include")
 endif()
 file(GLOB BUILTINS_HEADERS "${CLANG_BUILTIN_HEADERS_DIR}/*.h")
 if(NOT BUILTINS_HEADERS)

CLANG_BUILTIN_HEADERS_DIR always fall back to llvm's. This should fix :)

(help from psykose)

qaqland commented 12 months ago

alpine linux user could have a look at my fork: https://github.com/qaqland/codebrowser-alpinelinux

hope it useful