diff options
author | mattkae <mattkae@protonmail.com> | 2022-05-11 09:23:58 -0400 |
---|---|---|
committer | mattkae <mattkae@protonmail.com> | 2022-05-11 09:23:58 -0400 |
commit | 3f4a0d5370ae6c34afe180df96add3b8522f4af1 (patch) | |
tree | ae901409e02bde8ee278475f8cf6818f8f680a60 /elpa/irony-20220110.849/server/cmake |
initial commit
Diffstat (limited to 'elpa/irony-20220110.849/server/cmake')
3 files changed, 243 insertions, 0 deletions
diff --git a/elpa/irony-20220110.849/server/cmake/CheckClangResourceDir.cmake b/elpa/irony-20220110.849/server/cmake/CheckClangResourceDir.cmake new file mode 100644 index 0000000..20bcda9 --- /dev/null +++ b/elpa/irony-20220110.849/server/cmake/CheckClangResourceDir.cmake @@ -0,0 +1,90 @@ +# +# Get the Clang resource directory. +# +# If found the following variable will be set: +# - CLANG_RESOURCE_DIR +# +set(CHECK_CLANG_RESOURCE_DIR_CHECKER_CODE_IN + ${CMAKE_CURRENT_LIST_DIR}/LibClangDiagnosticsChecker.cpp) + +function(check_clang_resource_dir) + if (CLANG_RESOURCE_DIR) + return() # already in cache + endif() + + message(STATUS "Detecting Clang resource directory") + find_package (LibClang REQUIRED) + + set(checker_code + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/LibClangDiagnosticsChecker.cpp) + set(checked_file + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check-libclang-stddef.cpp") + + configure_file(${CHECK_CLANG_RESOURCE_DIR_CHECKER_CODE_IN} + ${checker_code} COPYONLY) + file(WRITE "${checked_file}" "#include <stddef.h>\n") + + # Paths stolen from Rip-Rip/clang_complete#getBuiltinHeaderPath() + find_path(CHECK_CLANG_RESOURCE_DIR include/stddef.h + NO_DEFAULT_PATH + # the default path, favor this one over the other, in case a specific + # libclang has been chosen. + HINTS "${LIBCLANG_LIBRARY_DIR}/../lib/clang" + # other, distribution specific, paths + PATHS + "${LIBCLANG_LIBRARY_DIR}/../clang" # Gentoo + "${LIBCLANG_LIBRARY_DIR}/clang" # openSUSE, Windows + "${LIBCLANG_LIBRARY_DIR}/" # Google + "/usr/lib64/clang" # x86_64 (openSUSE, Fedora) + "/usr/lib/clang" + PATH_SUFFIXES ${LIBCLANG_KNOWN_LLVM_VERSIONS}) + + if (CHECK_CLANG_RESOURCE_DIR) + # On Windows the paths weren't escaped correctly, similar to: + # http://public.kitware.com/pipermail/cmake/2006-February/008473.html + list(APPEND run_args -resource-dir \"${CHECK_CLANG_RESOURCE_DIR}\") + endif() + + list(APPEND run_args ${checked_file}) + + try_run( + CHECK_CLANG_RESOURCE_DIR_NUM_DIAGNOSTICS + CHECK_CLANG_RESOURCE_DIR_COMPILE_RESULT + ${CMAKE_BINARY_DIR} + ${checker_code} + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES:STRING=${LIBCLANG_INCLUDE_DIRS}" + "-DLINK_LIBRARIES:STRING=${LIBCLANG_LIBRARIES}" + COMPILE_OUTPUT_VARIABLE compile_output + RUN_OUTPUT_VARIABLE run_output + ARGS ${run_args} + ) + + if (NOT CHECK_CLANG_RESOURCE_DIR_COMPILE_RESULT) + set(CHECK_CLANG_RESOURCE_DIR_NUM_DIAGNOSTICS 1) + endif() + + if (CHECK_CLANG_RESOURCE_DIR_NUM_DIAGNOSTICS EQUAL 0) + message(STATUS "Detecting libclang builtin headers directory -- success") + if (CHECK_CLANG_RESOURCE_DIR) + set(CLANG_RESOURCE_DIR "${CHECK_CLANG_RESOURCE_DIR}" + CACHE INTERNAL "Clang resource directory.") + endif() + else() + message(STATUS "Detecting Clang resource directory -- fail") + + if (NOT CHECK_CLANG_RESOURCE_DIR_COMPILE_RESULT) + message(WARNING "CheckClangResourceDir: failed to compile checker, please report. + Compile output: + ${compile_output} +") + else() + message(WARNING "CheckClangResourceDir: unsupported configuration, please report. + + Check with args: ${run_args} + Check output: + ${run_output} +") + endif() + endif() +endfunction() diff --git a/elpa/irony-20220110.849/server/cmake/LibClangDiagnosticsChecker.cpp b/elpa/irony-20220110.849/server/cmake/LibClangDiagnosticsChecker.cpp new file mode 100644 index 0000000..64ea7aa --- /dev/null +++ b/elpa/irony-20220110.849/server/cmake/LibClangDiagnosticsChecker.cpp @@ -0,0 +1,47 @@ +/* + This program takes some forward its command line arguments to libclang and + returns the number of diagnostics that occured during the parsing. + + It is used during CMake generation to adjust the default parameters to + libclang. +*/ + +#include <clang-c/Index.h> + +#include <stdio.h> + +int main(int argc, const char *argv[]) { + for (int i = 1; i < argc; ++i) { + fprintf(stdout, "argv[%d]: %s\n", i, argv[i]); + } + + CXIndex Idx = clang_createIndex(0, 0); + CXTranslationUnit TU = clang_parseTranslationUnit( + Idx, NULL, &argv[1], argc - 1, 0, 0, CXTranslationUnit_None); + int NumDiagnostics; + + if (TU == NULL) { + NumDiagnostics = 1; + fprintf(stderr, "failed to create translation unit!\n"); + } else { + int i; + + NumDiagnostics = clang_getNumDiagnostics(TU); + + for (i = 0; i < NumDiagnostics; ++i) { + CXDiagnostic Diag = clang_getDiagnostic(TU, i); + CXString DiagStr = + clang_formatDiagnostic(Diag, clang_defaultDiagnosticDisplayOptions()); + + fprintf(stderr, "%s\n", clang_getCString(DiagStr)); + + clang_disposeString(DiagStr); + clang_disposeDiagnostic(Diag); + } + + clang_disposeTranslationUnit(TU); + } + + clang_disposeIndex(Idx); + return NumDiagnostics; +} diff --git a/elpa/irony-20220110.849/server/cmake/modules/FindLibClang.cmake b/elpa/irony-20220110.849/server/cmake/modules/FindLibClang.cmake new file mode 100644 index 0000000..edc786d --- /dev/null +++ b/elpa/irony-20220110.849/server/cmake/modules/FindLibClang.cmake @@ -0,0 +1,106 @@ +# Find libclang. +# +# This module defines the following variables: +# LIBCLANG_FOUND - true if libclang has been found and can be used +# LIBCLANG_KNOWN_LLVM_VERSIONS - known LLVM release numbers +# LIBCLANG_INCLUDE_DIRS - the libclang include directories +# LIBCLANG_LIBRARIES - the libraries needed to use libclang +# LIBCLANG_LIBRARY_DIR - the path to the directory containing libclang +# +# This module defines the following IMPORTED target: +# - irony_libclang + +# most recent versions come first +# http://llvm.org/apt/ +set(LIBCLANG_KNOWN_LLVM_VERSIONS 9.0.0 9.0 9 + 8.0.0 8.0 8 + 7.0.1 7.0.0 7.0 7 + 6.0.1 6.0.0 6.0 6 + 5.0.2 5.0.1 5.0.0 5.0 5 + 4.0.1 4.0.0 4.0 4 + 3.9.1 3.9.0 3.9 + 3.8.1 3.8.0 3.8 + 3.7.1 3.7.0 3.7 + 3.6.2 3.6.1 3.6.0 3.6 + 3.5.2 3.5.1 3.5.0 3.5 + 3.4.2 3.4.1 3.4 + 3.3 + 3.2 + 3.1) + +set(libclang_llvm_header_search_paths) +set(libclang_llvm_lib_search_paths + # LLVM Fedora + /usr/lib/llvm + ) + +foreach (version ${LIBCLANG_KNOWN_LLVM_VERSIONS}) + string(REPLACE "." "" undotted_version "${version}") + list(APPEND libclang_llvm_header_search_paths + # LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/ + "/usr/lib/llvm-${version}/include/" + # LLVM MacPorts + "/opt/local/libexec/llvm-${version}/include" + # LLVM Homebrew + "/usr/local/Cellar/llvm/${version}/include" + # LLVM Homebrew/versions + "/usr/local/lib/llvm-${version}/include" + # FreeBSD ports versions + "/usr/local/llvm${undotted_version}/include" + # Gentoo clang-4 + "/usr/lib/llvm/${version}/include" + ) + + list(APPEND libclang_llvm_lib_search_paths + # LLVM Debian/Ubuntu nightly packages: http://llvm.org/apt/ + "/usr/lib/llvm-${version}/lib/" + # LLVM MacPorts + "/opt/local/libexec/llvm-${version}/lib" + # LLVM Homebrew + "/usr/local/Cellar/llvm/${version}/lib" + # LLVM Homebrew/versions + "/usr/local/lib/llvm-${version}/lib" + # FreeBSD ports versions + "/usr/local/llvm${undotted_version}/lib" + # Gentoo clang-4 + "/usr/lib/llvm/${version}/lib" + ) +endforeach() + +find_path(LIBCLANG_INCLUDE_DIR clang-c/Index.h + PATHS ${libclang_llvm_header_search_paths} + PATH_SUFFIXES LLVM/include #Windows package from http://llvm.org/releases/ + DOC "The path to the directory that contains clang-c/Index.h") + +find_library(LIBCLANG_LIBRARY + NAMES + # On Windows with MSVC, the import library uses the ".imp" file extension + # instead of the comon ".lib" + libclang.imp + libclang + clang + PATHS ${libclang_llvm_lib_search_paths} + PATH_SUFFIXES LLVM/lib #Windows package from http://llvm.org/releases/ + DOC "The file that corresponds to the libclang library.") + +get_filename_component(LIBCLANG_LIBRARY_DIR ${LIBCLANG_LIBRARY} PATH) + +set(LIBCLANG_LIBRARIES ${LIBCLANG_LIBRARY}) +set(LIBCLANG_INCLUDE_DIRS ${LIBCLANG_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBCLANG_FOUND to TRUE if +# all listed variables are TRUE +find_package_handle_standard_args(LibClang DEFAULT_MSG + LIBCLANG_LIBRARY LIBCLANG_INCLUDE_DIR) + +mark_as_advanced(LIBCLANG_INCLUDE_DIR LIBCLANG_LIBRARY) + +if (LIBCLANG_FOUND AND NOT TARGET irony_libclang) + add_library(irony_libclang UNKNOWN IMPORTED) + set_target_properties(irony_libclang PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LOCATION "${LIBCLANG_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBCLANG_INCLUDE_DIR}" + ) +endif() |