Skip to content

Commit

Permalink
Only add include directories for LLVM, clang & rapidjson if they are …
Browse files Browse the repository at this point in the history
…not in CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES

/usr/include/c++/9 comes before /usr/include in `{clang,gcc} -v -fsyntax-only -xc++ /dev/null`.

    target_include_directories(ccls SYSTEM PRIVATE ${RapidJSON_INCLUDE_DIRS})

If ${RapidJSON_INCLUDE_DIRS} resolves to /usr/include, /usr/include will
be shuffled before /usr/include/c++/9 and will cause `#include_next <stdlib.h>`
issues (see MaskRay#417).

Check if the include directories are already in CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES.
  • Loading branch information
dcermak authored and MaskRay committed Jun 27, 2019
1 parent aa7bb00 commit eb9d564
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,25 @@ set_property(SOURCE src/utils.cc APPEND PROPERTY COMPILE_DEFINITIONS

### Includes

target_include_directories(ccls PRIVATE src)
target_include_directories(ccls SYSTEM PRIVATE
third_party ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS})

if(USE_SYSTEM_RAPIDJSON)
find_package(RapidJSON QUIET)
endif()
if(NOT RapidJSON_FOUND)
set(RapidJSON_INCLUDE_DIRS third_party/rapidjson/include)
endif()
target_include_directories(ccls SYSTEM PRIVATE ${RapidJSON_INCLUDE_DIRS})

target_include_directories(ccls PRIVATE src)

foreach(include_dir third_party
${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS} ${RapidJSON_INCLUDE_DIRS})
get_filename_component(include_dir_realpath ${include_dir} REALPATH)
# Don't add as SYSTEM if they are in CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES.
# It would reorder the system search paths and cause issues with libstdc++'s
# use of #include_next. See https://github.com/MaskRay/ccls/pull/417
if(NOT "${include_dir_realpath}" IN_LIST CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES)
target_include_directories(ccls SYSTEM PRIVATE ${include_dir})
endif()
endforeach()

### Install

Expand Down

0 comments on commit eb9d564

Please sign in to comment.