Add LLVM_ENABLE_MODULES flag to CMake to enable building with C++ modules.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 26 Sep 2014 22:40:15 +0000 (22:40 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 26 Sep 2014 22:40:15 +0000 (22:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218551 91177308-0d34-0410-b5e6-96231b3b80d8

CMakeLists.txt
cmake/modules/AddLLVM.cmake
cmake/modules/HandleLLVMOptions.cmake

index f4195ae6346985e8fae082cef1d2b66d42a1beb3..cc8dd0133c09de90d30cbf5c7a02b0f5353ca277 100644 (file)
@@ -208,6 +208,7 @@ else()
   option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
 endif()
 
+option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
 option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
index 409a5d61e65be6e8b6514d1f07a2834af5e61206..57e8955ccd9ba6ea5176a95c150310686788c4a6 100644 (file)
@@ -310,6 +310,12 @@ function(llvm_add_library name)
   endif()
 
   if(ARG_MODULE OR ARG_SHARED)
+    # Do not add -Dname_EXPORTS to the command-line when building files in this
+    # target. Doing so is actively harmful for the modules build because it
+    # creates extra module variants, and not useful because we don't use these
+    # macros.
+    set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
+
     if (LLVM_EXPORTED_SYMBOL_FILE)
       add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
     endif()
@@ -435,6 +441,12 @@ macro(add_llvm_executable name)
   llvm_update_compile_flags(${name})
   add_dead_strip( ${name} )
 
+  # Do not add -Dname_EXPORTS to the command-line when building files in this
+  # target. Doing so is actively harmful for the modules build because it
+  # creates extra module variants, and not useful because we don't use these
+  # macros.
+  set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
+
   if (LLVM_EXPORTED_SYMBOL_FILE)
     add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
   endif(LLVM_EXPORTED_SYMBOL_FILE)
index 0d39a07c52291db85a2195a89a318616fc78797e..5b9d554341a93e0496a10d33a6af17061ced44f7 100644 (file)
@@ -332,6 +332,25 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
       message(FATAL_ERROR "LLVM requires C++11 support but the '-std=c++11' flag isn't supported.")
     endif()
   endif()
+  if (LLVM_ENABLE_MODULES)
+    set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fmodules -fcxx-modules")
+    # Check that we can build code with modules enabled, and that repeatedly
+    # including <cassert> still manages to respect NDEBUG properly.
+    CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG
+                               #include <cassert>
+                               #define NDEBUG
+                               #include <cassert>
+                               int main() { assert(this code is not compiled); }"
+                               CXX_SUPPORTS_MODULES)
+    set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
+    if (CXX_SUPPORTS_MODULES)
+      append_if(CXX_SUPPORTS_MODULES "-fmodules" CMAKE_C_FLAGS)
+      append_if(CXX_SUPPORTS_MODULES "-fmodules -fcxx-modules" CMAKE_CXX_FLAGS)
+    else()
+      message(FATAL_ERROR "LLVM_ENABLE_MODULES is not supported by this compiler")
+    endif()
+  endif(LLVM_ENABLE_MODULES)
 endif( MSVC )
 
 macro(append_common_sanitizer_flags)