[PATCH] Enable C++11
Alp Toker
alp at nuanti.com
Mon Jan 6 09:34:55 PST 2014
The attached patch enables C++11 by default in the CMake and Makefile
build systems.
The old LLVM_ENABLE_CXX11 flag is retrofitted as LLVM_ENABLE_CXX1Y for
those looking to try the latest experimental standard.
The CMake changes include an additional fallback to -std=c++0x. This
fallback can hopefully be removed shortly when the remaining legacy
build servers are upgraded.
No changes made to the MSVC configuration in this patch. I'm guessing
Takumi will want to take care of that personally :-)
Alp.
--
http://www.nuanti.com
the browser experts
-------------- next part --------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56e8328..dea0aab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -181,7 +181,7 @@ else( MSVC )
option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
endif()
-option(LLVM_ENABLE_CXX11 "Compile with C++11 enabled." OFF)
+option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
diff --git a/Makefile.config.in b/Makefile.config.in
index dcca45f..70169fe 100644
--- a/Makefile.config.in
+++ b/Makefile.config.in
@@ -232,8 +232,8 @@ RDYNAMIC := @RDYNAMIC@
#ENABLE_LIBCPP = 0
ENABLE_LIBCPP = @ENABLE_LIBCPP@
-# When ENABLE_CXX11 is enabled, LLVM uses c++11 mode by default to build.
-ENABLE_CXX11 = @ENABLE_CXX11@
+# When ENABLE_CXX1Y is enabled, LLVM uses c++1y mode by default to build.
+ENABLE_CXX1Y = @ENABLE_CXX1Y@
# When ENABLE_SPLIT_DWARF is enabled, LLVM uses -gfission to build in debug mode.
ENABLE_SPLIT_DWARF = @ENABLE_SPLIT_DWARF@
diff --git a/Makefile.rules b/Makefile.rules
index 6c7ec02..ac77e70 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -311,7 +311,9 @@ ifeq ($(ENABLE_LIBCPP),1)
LD.Flags += -stdlib=libc++
endif
-ifeq ($(ENABLE_CXX11),1)
+ifeq ($(ENABLE_CXX1Y),1)
+ CXX.Flags += -std=c++1y
+else
CXX.Flags += -std=c++11
endif
diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index 3d0a2b3..912820f 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -503,16 +503,16 @@ case "$enableval" in
*) AC_MSG_ERROR([Invalid setting for --enable-libcpp. Use "yes" or "no"]) ;;
esac
-dnl --enable-cxx11 : check whether or not to use -std=c++11 on the command line
-AC_ARG_ENABLE(cxx11,
- AS_HELP_STRING([--enable-cxx11],
- [Use c++11 if available (default is NO)]),,
+dnl --enable-cxx1y : check whether or not to use -std=c++1y on the command line
+AC_ARG_ENABLE(cxx1y,
+ AS_HELP_STRING([--enable-cxx1y],
+ [Use c++1y if available (default is NO)]),,
enableval=default)
case "$enableval" in
- yes) AC_SUBST(ENABLE_CXX11,[1]) ;;
- no) AC_SUBST(ENABLE_CXX11,[0]) ;;
- default) AC_SUBST(ENABLE_CXX11,[0]);;
- *) AC_MSG_ERROR([Invalid setting for --enable-cxx11. Use "yes" or "no"]) ;;
+ yes) AC_SUBST(ENABLE_CXX1Y,[1]) ;;
+ no) AC_SUBST(ENABLE_CXX1Y,[0]) ;;
+ default) AC_SUBST(ENABLE_CXX1Y,[0]);;
+ *) AC_MSG_ERROR([Invalid setting for --enable-cxx1y. Use "yes" or "no"]) ;;
esac
dnl --enable-fission : check whether or not to use -gsplit-dwarf on the command
diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
index 38dacb7..b77e88a 100644
--- a/cmake/modules/HandleLLVMOptions.cmake
+++ b/cmake/modules/HandleLLVMOptions.cmake
@@ -249,10 +249,25 @@ elseif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
if (LLVM_ENABLE_WERROR)
add_llvm_definitions( -Werror )
endif (LLVM_ENABLE_WERROR)
- if (LLVM_ENABLE_CXX11)
+
+ 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)
+ if (NOT CXX_SUPPORTS_CXX1Y)
+ MESSAGE(FATAL_ERROR "Failed to enable C++1y")
+ endif ()
+ else ()
check_cxx_compiler_flag("-std=c++11" CXX_SUPPORTS_CXX11)
append_if(CXX_SUPPORTS_CXX11 "-std=c++11" CMAKE_CXX_FLAGS)
- endif (LLVM_ENABLE_CXX11)
+ if (NOT CXX_SUPPORTS_CXX11)
+ check_cxx_compiler_flag("-std=c++0x" CXX_SUPPORTS_CXX0X)
+ append_if(CXX_SUPPORTS_CXX0X "-std=c++0x" CMAKE_CXX_FLAGS)
+ endif ()
+ if (NOT CXX_SUPPORTS_CXX11 AND NOT CXX_SUPPORTS_CXX0X)
+ MESSAGE(FATAL_ERROR "Failed to enable C++11")
+ endif ()
+ endif ()
+
endif( MSVC )
macro(append_common_sanitizer_flags)
diff --git a/docs/CMake.rst b/docs/CMake.rst
index 9fb4f48..8ec3864 100644
--- a/docs/CMake.rst
+++ b/docs/CMake.rst
@@ -211,8 +211,8 @@ LLVM-specific variables
**LLVM_ENABLE_THREADS**:BOOL
Build with threads support, if available. Defaults to ON.
-**LLVM_ENABLE_CXX11**:BOOL
- Build in C++11 mode, if available. Defaults to OFF.
+**LLVM_ENABLE_CXX1Y**:BOOL
+ Build in C++1y mode, if available. Defaults to OFF.
**LLVM_ENABLE_ASSERTIONS**:BOOL
Enables code assertions. Defaults to OFF if and only if ``CMAKE_BUILD_TYPE``
diff --git a/projects/sample/Makefile.llvm.config.in b/projects/sample/Makefile.llvm.config.in
index c7df998..38a0736 100644
--- a/projects/sample/Makefile.llvm.config.in
+++ b/projects/sample/Makefile.llvm.config.in
@@ -184,8 +184,8 @@ RDYNAMIC := @RDYNAMIC@
#ENABLE_LIBCPP = 0
ENABLE_LIBCPP = @ENABLE_LIBCPP@
-# When ENABLE_CXX11 is enabled, LLVM uses c++11 mode by default to build.
-ENABLE_CXX11 = @ENABLE_CXX11@
+# When ENABLE_CXX1Y is enabled, LLVM uses c++11 mode by default to build.
+ENABLE_CXX1Y = @ENABLE_CXX1Y@
# When ENABLE_WERROR is enabled, we'll pass -Werror on the command line
ENABLE_WERROR = @ENABLE_WERROR@
diff --git a/projects/sample/Makefile.llvm.rules b/projects/sample/Makefile.llvm.rules
index 545e629..9832336 100644
--- a/projects/sample/Makefile.llvm.rules
+++ b/projects/sample/Makefile.llvm.rules
@@ -252,7 +252,7 @@ ifeq ($(ENABLE_LIBCPP),1)
LD.Flags += -stdlib=libc++
endif
-ifeq ($(ENABLE_CXX11),1)
+ifeq ($(ENABLE_CXX1Y),1)
CXX.Flags += -std=c++11
endif
diff --git a/projects/sample/autoconf/configure.ac b/projects/sample/autoconf/configure.ac
index 03cd214..20fc7d3 100644
--- a/projects/sample/autoconf/configure.ac
+++ b/projects/sample/autoconf/configure.ac
@@ -387,9 +387,9 @@ AC_ARG_ENABLE(cxx11,
[Use c++11 if available (default is NO)]),,
enableval=default)
case "$enableval" in
- yes) AC_SUBST(ENABLE_CXX11,[1]) ;;
- no) AC_SUBST(ENABLE_CXX11,[0]) ;;
- default) AC_SUBST(ENABLE_CXX11,[0]);;
+ yes) AC_SUBST(ENABLE_CXX1Y,[1]) ;;
+ no) AC_SUBST(ENABLE_CXX1Y,[0]) ;;
+ default) AC_SUBST(ENABLE_CXX1Y,[0]);;
*) AC_MSG_ERROR([Invalid setting for --enable-cxx11. Use "yes" or "no"]) ;;
esac
diff --git a/projects/sample/configure b/projects/sample/configure
index bc04c96..84891f6 100755
--- a/projects/sample/configure
+++ b/projects/sample/configure
@@ -683,7 +683,7 @@ BUILD_EXEEXT
BUILD_CXX
CVSBUILD
ENABLE_LIBCPP
-ENABLE_CXX11
+ENABLE_CXX1Y
ENABLE_OPTIMIZED
ENABLE_PROFILING
DISABLE_ASSERTIONS
@@ -4961,11 +4961,11 @@ else
fi
case "$enableval" in
- yes) ENABLE_CXX11=1
+ yes) ENABLE_CXX1Y=1
;;
- no) ENABLE_CXX11=0
+ no) ENABLE_CXX1Y=0
;;
- default) ENABLE_CXX11=0
+ default) ENABLE_CXX1Y=0
;;
*) { { echo "$as_me:$LINENO: error: Invalid setting for --enable-cxx11. Use \"yes\" or \"no\"" >&5
echo "$as_me: error: Invalid setting for --enable-cxx11. Use \"yes\" or \"no\"" >&2;}
@@ -22263,7 +22263,7 @@ BUILD_EXEEXT!$BUILD_EXEEXT$ac_delim
BUILD_CXX!$BUILD_CXX$ac_delim
CVSBUILD!$CVSBUILD$ac_delim
ENABLE_LIBCPP!$ENABLE_LIBCPP$ac_delim
-ENABLE_CXX11!$ENABLE_CXX11$ac_delim
+ENABLE_CXX1Y!$ENABLE_CXX1Y$ac_delim
ENABLE_OPTIMIZED!$ENABLE_OPTIMIZED$ac_delim
ENABLE_PROFILING!$ENABLE_PROFILING$ac_delim
DISABLE_ASSERTIONS!$DISABLE_ASSERTIONS$ac_delim
More information about the llvm-commits
mailing list