[PATCH] D60399: [CMake] Replace LLVM_ENABLE_CXX1Y and friends with LLVM_CXX_STD
Justin Bogner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 01:38:15 PDT 2019
bogner created this revision.
bogner added reviewers: jfb, mehdi_amini.
Herald added subscribers: llvm-commits, mstorsjo, dexonsmith, mgorny, mcrosier.
Herald added a project: LLVM.
Simplify building with particular C++ standards by replacing the
specific "enable standard X" flags with a flag that allows specifying
the standard you want directly.
We preserve compatibility with the existing flags so that anyone with
those flags in existing caches won't break mysteriously.
Repository:
rL LLVM
https://reviews.llvm.org/D60399
Files:
CMakeLists.txt
cmake/modules/HandleLLVMOptions.cmake
docs/CMake.rst
Index: docs/CMake.rst
===================================================================
--- docs/CMake.rst
+++ docs/CMake.rst
@@ -266,8 +266,8 @@
**LLVM_ENABLE_THREADS**:BOOL
Build with threads support, if available. Defaults to ON.
-**LLVM_ENABLE_CXX1Y**:BOOL
- Build in C++1y mode, if available. Defaults to OFF.
+**LLVM_CXX_STD**:STRING
+ Build with the specified C++ standard. Defaults to "c++11".
**LLVM_ENABLE_ASSERTIONS**:BOOL
Enables code assertions. Defaults to ON if and only if ``CMAKE_BUILD_TYPE``
Index: cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -437,25 +437,18 @@
append_if(LLVM_ENABLE_WERROR "-Wno-error" CMAKE_REQUIRED_FLAGS)
add_flag_if_supported("-Werror=date-time" WERROR_DATE_TIME)
add_flag_if_supported("-Werror=unguarded-availability-new" WERROR_UNGUARDED_AVAILABILITY_NEW)
- if (LLVM_ENABLE_CXX1Y)
- check_cxx_compiler_flag("-std=c++1y" CXX_SUPPORTS_CXX1Y)
- append_if(CXX_SUPPORTS_CXX1Y "-std=c++1y" CMAKE_CXX_FLAGS)
- elseif(LLVM_ENABLE_CXX1Z)
- check_cxx_compiler_flag("-std=c++1z" CXX_SUPPORTS_CXX1Z)
- append_if(CXX_SUPPORTS_CXX1Z "-std=c++1z" CMAKE_CXX_FLAGS)
- else()
- check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11)
- if (CXX_SUPPORTS_CXX11)
- if (CYGWIN OR MINGW)
- # MinGW and Cygwin are a bit stricter and lack things like
- # 'strdup', 'stricmp', etc in c++11 mode.
- append("-std=gnu++11" CMAKE_CXX_FLAGS)
- else()
- append("-std=c++11" CMAKE_CXX_FLAGS)
- endif()
+ check_cxx_compiler_flag("-std=${LLVM_CXX_STD}" CXX_SUPPORTS_CXX_STD)
+ if (CXX_SUPPORTS_CXX_STD)
+ if (CYGWIN OR MINGW)
+ # MinGW and Cygwin are a bit stricter and lack things like
+ # 'strdup', 'stricmp', etc in c++11 mode.
+ string(REPLACE "c++" "gnu++" "${LLVM_CXX_STD}" gnu_LLVM_CXX_STD)
+ append("-std=${gnu_LLVM_CXX_STD}" CMAKE_CXX_FLAGS)
else()
- message(FATAL_ERROR "LLVM requires C++11 support but the '-std=c++11' flag isn't supported.")
+ append("-std=${LLVM_CXX_STD}" CMAKE_CXX_FLAGS)
endif()
+ else()
+ message(FATAL_ERROR "The host compiler does not support '-std=${LLVM_CXX_STD}'.")
endif()
if (LLVM_ENABLE_MODULES)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -421,13 +421,21 @@
option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." OFF)
option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
endif()
-option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
-option(LLVM_ENABLE_CXX1Z "Compile with C++1z enabled." OFF)
option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
+set(LLVM_CXX_STD_default "c++11")
+# Preserve behaviour of legacy cache variables
+if (LLVM_ENABLE_CXX1Y)
+ set(LLVM_CXX_STD_default "c++1y")
+elseif (LLVM_ENABLE_CXX1Z)
+ set(LLVM_CXX_STD_default "c++1z")
+endif()
+set(LLVM_CXX_STD ${LLVM_CXX_STD_default}
+ CACHE STRING "C++ standard to use for compilation.")
+
option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60399.194102.patch
Type: text/x-patch
Size: 3580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190408/1d366de1/attachment.bin>
More information about the llvm-commits
mailing list