[llvm] r218551 - Add LLVM_ENABLE_MODULES flag to CMake to enable building with C++ modules.
Richard Smith
richard-llvm at metafoo.co.uk
Fri Sep 26 15:40:15 PDT 2014
Author: rsmith
Date: Fri Sep 26 17:40:15 2014
New Revision: 218551
URL: http://llvm.org/viewvc/llvm-project?rev=218551&view=rev
Log:
Add LLVM_ENABLE_MODULES flag to CMake to enable building with C++ modules.
Modified:
llvm/trunk/CMakeLists.txt
llvm/trunk/cmake/modules/AddLLVM.cmake
llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
Modified: llvm/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=218551&r1=218550&r2=218551&view=diff
==============================================================================
--- llvm/trunk/CMakeLists.txt (original)
+++ llvm/trunk/CMakeLists.txt Fri Sep 26 17:40:15 2014
@@ -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)
Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=218551&r1=218550&r2=218551&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Fri Sep 26 17:40:15 2014
@@ -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)
Modified: llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/HandleLLVMOptions.cmake?rev=218551&r1=218550&r2=218551&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/HandleLLVMOptions.cmake (original)
+++ llvm/trunk/cmake/modules/HandleLLVMOptions.cmake Fri Sep 26 17:40:15 2014
@@ -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)
More information about the llvm-commits
mailing list