diff options
author | Dimitri van Heesch <dimitri@stack.nl> | 2017-08-20 09:22:30 (GMT) |
---|---|---|
committer | Dimitri van Heesch <dimitri@stack.nl> | 2017-08-20 09:22:30 (GMT) |
commit | 104acb4bac5da39814a7e30310f66e1e26d099ff (patch) | |
tree | 467f8a07e0757e0658de96bb37101b8c065f6359 | |
parent | daa2c0960aa5044990c3e06afe8c15694e8be48d (diff) | |
parent | b0aae61c97966cb9d424b500d7ced5bdf500d8db (diff) | |
download | Doxygen-104acb4bac5da39814a7e30310f66e1e26d099ff.zip Doxygen-104acb4bac5da39814a7e30310f66e1e26d099ff.tar.gz Doxygen-104acb4bac5da39814a7e30310f66e1e26d099ff.tar.bz2 |
Merge branch 'dvj-master'
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | cmake/FindLibClang.cmake | 55 | ||||
-rw-r--r-- | src/CMakeLists.txt | 20 | ||||
-rw-r--r-- | src/clangparser.cpp | 35 | ||||
-rw-r--r-- | src/config.xml | 14 | ||||
-rw-r--r-- | src/portable.cpp | 1 |
6 files changed, 78 insertions, 59 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d75659..ed63320 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,14 +35,20 @@ set(clang "0" CACHE INTERNAL "used in settings.h") if (use_sqlite3) set(sqlite3 "1" CACHE INTERNAL "used in settings.h") endif() + +set(MACOS_VERSION_MIN 10.5) if (use_libclang) set(clang "1" CACHE INTERNAL "used in settings.h") - find_package(LibClang REQUIRED) + find_package(LLVM CONFIG REQUIRED) + find_package(Clang CONFIG REQUIRED) + if (${CMAKE_SYSTEM} MATCHES "Darwin") + set(MACOS_VERSION_MIN 10.11) + endif() endif() if (${CMAKE_SYSTEM} MATCHES "Darwin") - set(CMAKE_CXX_FLAGS "-Wno-deprecated-register -mmacosx-version-min=10.5 ${CMAKE_CXX_FLAGS}") - set(CMAKE_C_FLAGS "-Wno-deprecated-register -mmacosx-version-min=10.5 ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-Wno-deprecated-register -mmacosx-version-min=${MACOS_VERSION_MIN} ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "-Wno-deprecated-register -mmacosx-version-min=${MACOS_VERSION_MIN} ${CMAKE_C_FLAGS}") find_library(CORESERVICES_LIB CoreServices) set(EXTRA_LIBS ${CORESERVICES_LIB}) endif() diff --git a/cmake/FindLibClang.cmake b/cmake/FindLibClang.cmake deleted file mode 100644 index e7462d4..0000000 --- a/cmake/FindLibClang.cmake +++ /dev/null @@ -1,55 +0,0 @@ -if (NOT CLANG_ROOT) - set(CLANG_ROOT $ENV{CLANG_ROOT}) -endif () - -if (NOT LLVM_CONFIG) - set(LLVM_CONFIG $ENV{LLVM_CONFIG}) - if (NOT LLVM_CONFIG) - set(llvm_config_names llvm-config) - foreach(minor RANGE 9 1) - list(APPEND llvm_config_names "llvm-config3${minor}" "llvm-config-3.${minor}" "llvm-config-mp-3.${minor}") - endforeach () - find_program(LLVM_CONFIG NAMES ${llvm_config_names}) - endif () -endif () - -if (LLVM_CONFIG) - message(STATUS "llvm-config found at: ${LLVM_CONFIG}") -else () - message(FATAL_ERROR "Could NOT find llvm-config executable.") -endif () - -if (NOT EXISTS ${CLANG_INCLUDEDIR}) - execute_process(COMMAND ${LLVM_CONFIG} --includedir OUTPUT_VARIABLE CLANG_INCLUDEDIR OUTPUT_STRIP_TRAILING_WHITESPACE) - if (NOT EXISTS ${CLANG_INCLUDEDIR}) - message(FATAL_ERROR "Could NOT find clang includedir. You can fix this by setting CLANG_INCLUDEDIR in your shell or as a cmake variable.") - endif () -endif () - -if (NOT EXISTS ${CLANG_LIBDIR}) - execute_process(COMMAND ${LLVM_CONFIG} --libdir OUTPUT_VARIABLE CLANG_LIBDIR OUTPUT_STRIP_TRAILING_WHITESPACE) - if (NOT EXISTS ${CLANG_LIBDIR}) - message(FATAL_ERROR "Could NOT find clang libdir. You can fix this by setting CLANG_LIBDIR in your shell or as a cmake variable.") - endif () -endif () - -if (NOT CLANG_LIBS) - find_library(CLANG_LIB_HACK_CMAKECACHE_DOT_TEXT_BULLSHIT NAMES clang libclang ${CLANG_ROOT}/lib ${CLANG_LIBDIR} NO_DEFAULT_PATH) - if (NOT EXISTS ${CLANG_CLANG_LIB_HACK_CMAKECACHE_DOT_TEXT_BULLSHIT}) - find_library(CLANG_LIBS NAMES clang libclang) - if (NOT EXISTS ${CLANG_LIBS}) - if (MSVC) - set (CLANG_LIBS "${CLANG_LIBDIR}/libclang.lib") - else() - set (CLANG_LIBS "-L${CLANG_LIBDIR}" "-lclang" "-Wl,-rpath,${CLANG_LIBDIR}") - endif() - endif () - else () - set(CLANG_LIBS "${CLANG_LIB_HACK_CMAKECACHE_DOT_TEXT_BULLSHIT}") - endif () -endif () - -execute_process(COMMAND ${LLVM_CONFIG} --version OUTPUT_VARIABLE CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) -message("-- Using Clang ${CLANG_VERSION} from ${CLANG_LIBDIR} with LIBS ${CLANG_LIBS} and CXXFLAGS ${CLANG_CXXFLAGS}") - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08c8439..be395f4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -244,6 +244,26 @@ add_library(_doxygen STATIC ) add_executable(doxygen main.cpp) + +if (use_libclang) + find_package(LLVM REQUIRED CONFIG) + find_package(Clang REQUIRED CONFIG) + if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") + target_compile_features(_doxygen PRIVATE cxx_alignof) + target_compile_features(doxygen PRIVATE cxx_alignof) + target_compile_options(_doxygen PRIVATE -stdlib=libc++ -std=c++11) + target_compile_options(doxygen PRIVATE -stdlib=libc++ -std=c++11) + elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") + target_compile_options(_doxygen PRIVATE -std=c++11) + target_compile_options(doxygen PRIVATE -std=c++11) + endif() + include_directories(${LLVM_INCLUDE_DIRS}) + add_definitions(${LLVM_DEFINITIONS}) + llvm_map_components_to_libnames(llvm_libs support core option) + target_compile_definitions(doxygen PRIVATE ${LLVM_DEFINITIONS}) + set(CLANG_LIBS libclang clangTooling ${llvm_libs}) +endif() + target_link_libraries(doxygen _doxygen doxycfg diff --git a/src/clangparser.cpp b/src/clangparser.cpp index 67e754b..77151d6 100644 --- a/src/clangparser.cpp +++ b/src/clangparser.cpp @@ -4,6 +4,7 @@ #if USE_LIBCLANG #include <clang-c/Index.h> +#include "clang/Tooling/Tooling.h" #include <qfileinfo.h> #include <stdlib.h> #include "message.h" @@ -160,15 +161,46 @@ void ClangParser::start(const char *fileName,QStrList &filesInTranslationUnit) static bool clangAssistedParsing = Config_getBool(CLANG_ASSISTED_PARSING); static QStrList &includePath = Config_getList(INCLUDE_PATH); static QStrList clangOptions = Config_getList(CLANG_OPTIONS); + static QCString clangCompileDatabase = Config_getList(CLANG_COMPILATION_DATABASE_PATH); if (!clangAssistedParsing) return; //printf("ClangParser::start(%s)\n",fileName); p->fileName = fileName; p->index = clang_createIndex(0, 0); p->curLine = 1; p->curToken = 0; - char **argv = (char**)malloc(sizeof(char*)*(4+Doxygen::inputPaths.count()+includePath.count()+clangOptions.count())); QDictIterator<void> di(Doxygen::inputPaths); int argc=0; + std::string error; + // load a clang compilation database (https://clang.llvm.org/docs/JSONCompilationDatabase.html) + // this only needs to be loaded once, and could be refactored to a higher level function + static std::unique_ptr<clang::tooling::CompilationDatabase> db = + clang::tooling::CompilationDatabase::loadFromDirectory(clangCompileDatabase.data(), error); + int clang_option_len = 0; + std::vector<clang::tooling::CompileCommand> command; + if (strcmp(clangCompileDatabase, "0") != 0) { + if (db == nullptr) { + // user specified a path, but DB file was not found + err("%s using clang compilation database path of: \"%s\"\n", error.c_str(), + clangCompileDatabase.data()); + } else { + // check if the file we are parsing is in the DB + command = db->getCompileCommands(fileName); + if (!command.empty() ) { + // it's possible to have multiple entries for the same file, so use the last entry + clang_option_len = command[command.size()-1].CommandLine.size(); + } + } + } + char **argv = (char**)malloc(sizeof(char*)*(4+Doxygen::inputPaths.count()+includePath.count()+clangOptions.count()+clang_option_len)); + if (!command.empty() ) { + std::vector<std::string> options = command[command.size()-1].CommandLine; + // copy each compiler option used from the database. Skip the first which is compiler exe. + for (auto option = options.begin()+1; option != options.end(); option++) { + argv[argc++] = strdup(option->c_str()); + } + // this extra addition to argv is accounted for as we are skipping the first entry in + argv[argc++]=strdup("-w"); // finally, turn off warnings. + } else { // add include paths for input files for (di.toFirst();di.current();++di,++argc) { @@ -230,6 +262,7 @@ void ClangParser::start(const char *fileName,QStrList &filesInTranslationUnit) // provide the input and and its dependencies as unsaved files so we can // pass the filtered versions argv[argc++]=strdup(fileName); + } static bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES); //printf("source %s ----------\n%s\n-------------\n\n", // fileName,p->source.data()); diff --git a/src/config.xml b/src/config.xml index 8bb6add..6cd7997 100644 --- a/src/config.xml +++ b/src/config.xml @@ -1637,6 +1637,20 @@ to disable this feature. ]]> </docs> </option> + <option type='string' id='CLANG_COMPILATION_DATABASE_PATH' setting='USE_LIBCLANG' defval='0'> + <docs> +<![CDATA[ + If clang assisted parsing is enabled you can provide the clang parser with the + path to the <a href="http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html"> + compilation database</a> used when the files were built. This is equivalent to + specifying the "-p" option to a clang tool, such as clang-check. These options + will then be pased to the parser. + + @note The availability of this option depends on whether or not doxygen + was generated with the `-Duse-libclang=ON` option for CMake. + ]]> + </docs> + </option> </group> <group name='Index' docs='Configuration options related to the alphabetical class index'> <option type='bool' id='ALPHABETICAL_INDEX' defval='1'> diff --git a/src/portable.cpp b/src/portable.cpp index 1983fe7..4ad88a4 100644 --- a/src/portable.cpp +++ b/src/portable.cpp @@ -180,6 +180,7 @@ int portable_system(const char *command,const char *args,bool commandHasConsole) } } #endif + return 1; // we should never get here } |