diff --git a/CMakeLists.txt b/CMakeLists.txt index f4195ae6346..cc8dd0133c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 409a5d61e65..57e8955ccd9 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -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) diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 0d39a07c522..5b9d554341a 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -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 still manages to respect NDEBUG properly. + CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG + #include + #define NDEBUG + #include + 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)