From 0ca7d350cff64eb0b1cbc66332eb6a851fdc52b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Thu, 27 Jun 2019 12:19:11 +0200 Subject: [PATCH] Only add include directories for LLVM, clang & rapidjson if they are 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 ` issues (see https://github.com/MaskRay/ccls/pull/417). Check if the include directories are already in CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES. --- CMakeLists.txt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efca2ba9..baaa6a39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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