From b08824bd0ede65832c8d3edfaa8c3a7c04fc0e7b Mon Sep 17 00:00:00 2001
From: Vassil Vassilev <vvasilev@cern.ch>
Date: Thu, 30 Mar 2017 15:25:18 +0200
Subject: [PATCH] [modules] Do not with -fmodules-local-submodule-visibility on
 OSX.

This allows us to use the system modulemaps (with special treatment for OpenGL).
---
 CMakeLists.txt | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a82ad5542bb..0acbb6a6b4a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -150,8 +150,19 @@ if(cxxmodules)
 
   # FIXME: We should remove this once libc++ supports -fmodules-local-submodule-visibility.
   if (APPLE)
-    set(ROOT_CXXMODULES_COMMONFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -fno-implicit-module-maps -fmodule-map-file=${CMAKE_BINARY_DIR}/include/module.modulemap")
-  endif(APPLE)
+    # FIXME: TGLIncludes and alike depend on glew.h doing special preprocessor
+    # trickery to override the contents of system's OpenGL.
+    # On OSX #include TGLIncludes.h will trigger the creation of the system
+    # OpenGL.pcm. Once it is built, glew cannot use preprocessor trickery to 'fix'
+    # the translation units which it needs to 'rewrite'. The translation units
+    # which need glew support are in graf3d. However, depending on the modulemap
+    # organization we could request it implicitly (eg. one big module for ROOT).
+    # In these cases we need to 'prepend' this include path to the compiler in order
+    # for glew.h to it its trick.
+    set(ROOT_CXXMODULES_COMMONFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -isystem ${CMAKE_SOURCE_DIR}/graf3d/glew/isystem")
+  else()
+    set(ROOT_CXXMODULES_COMMONFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -Xclang -fmodules-local-submodule-visibility")
+  endif()
 
   configure_file("${CMAKE_SOURCE_DIR}/build/unix/module.modulemap" "${CMAKE_BINARY_DIR}/include/module.modulemap" COPYONLY)
 
@@ -186,7 +197,7 @@ if(cxxmodules)
   endif()
 
   # These vars are useful when we want to compile things without cxxmodules.
-  set(ROOT_CXXMODULES_CXXFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -fcxx-modules -Xclang -fmodules-local-submodule-visibility" CACHE STRING "Useful to filter out the modules-related cxxflags.")
+  set(ROOT_CXXMODULES_CXXFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -fcxx-modules" CACHE STRING "Useful to filter out the modules-related cxxflags.")
   set(ROOT_CXXMODULES_CFLAGS "${ROOT_CXXMODULES_COMMONFLAGS}" CACHE STRING "Useful to filter out the modules-related cflags.")
 
 
-- 
GitLab