From 9d0a93f0ec7b529cdbfaa2a553ffee1a4f7088ff Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic@gmail.com>
Date: Mon, 31 Jul 2017 11:45:20 +0000
Subject: [PATCH] [CMake][Modules] libclang: Ignore _CINDEX_LIB_ and
 CLANG_TOOL_EXTRA_BUILD for -fmodules.

CLANG_TOOL_EXTRA_BUILD doesn't affect headers.

_CINDEX_LIB_ is defined when the target is SHARED.
On Win32, it affects clang-c/Platform.h and it shouldn't be ignored.

This is part of https://reviews.llvm.org/D35559

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309557 91177308-0d34-0410-b5e6-96231b3b80d8
---
 tools/libclang/CMakeLists.txt | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt
index 2dd67030763..a28499c2c46 100644
--- a/tools/libclang/CMakeLists.txt
+++ b/tools/libclang/CMakeLists.txt
@@ -51,6 +51,9 @@ if (TARGET clangTidyPlugin)
   add_definitions(-DCLANG_TOOL_EXTRA_BUILD)
   list(APPEND LIBS clangTidyPlugin)
   list(APPEND LIBS clangIncludeFixerPlugin)
+  if(LLVM_ENABLE_MODULES)
+    list(APPEND LLVM_COMPILE_FLAGS "-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
+  endif()
 endif ()
 
 find_library(DL_LIBRARY_PATH dl)
@@ -115,6 +118,12 @@ if(ENABLE_SHARED)
       PROPERTIES
       VERSION ${LIBCLANG_LIBRARY_VERSION}
       DEFINE_SYMBOL _CINDEX_LIB_)
+    # FIXME: _CINDEX_LIB_ affects dllexport/dllimport on Win32.
+    if(LLVM_ENABLE_MODULES AND NOT WIN32)
+      target_compile_options(libclang PRIVATE
+        "-fmodules-ignore-macro=_CINDEX_LIB_"
+        )
+    endif()
   endif()
 endif()
 
-- 
GitLab