This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/main by this push:
     new 286992e1f ORC-1301: [C++] Enforce C++17
286992e1f is described below

commit 286992e1fc3075f5a73315e74cbe81719e9a5cff
Author: Gang Wu <[email protected]>
AuthorDate: Sat Oct 29 01:00:34 2022 -0700

    ORC-1301: [C++] Enforce C++17
    
    ### What changes were proposed in this pull request?
    Enforce the C++ library to use C++17 to compile.
    
    ### Why are the changes needed?
    To keep up the pace of modern C++ standard and improve development 
efficiency.
    
    ### How was this patch tested?
    Manual test on laptop. It requires all GitHub action checks to pass.
    
    Closes #1295 from wgtmac/ORC-1301.
    
    Authored-by: Gang Wu <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 CMakeLists.txt                          | 34 +++++++++++++++++++++++++--------
 c++/src/CMakeLists.txt                  |  2 +-
 c++/test/CMakeLists.txt                 |  2 +-
 c++/test/MemoryOutputStream.hh          |  2 +-
 cmake_modules/CheckSourceCompiles.cmake |  2 +-
 tools/src/CMakeLists.txt                |  2 +-
 tools/test/CMakeLists.txt               |  2 +-
 7 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6b15d5f3f..9d140d428 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -90,6 +90,14 @@ endif ()
 #
 # Compiler specific flags
 #
+# This ensures that things like c++17 get passed correctly
+if(NOT DEFINED CMAKE_CXX_STANDARD)
+  set(CMAKE_CXX_STANDARD 17)
+elseif(${CMAKE_CXX_STANDARD} VERSION_LESS 17)
+  message(FATAL_ERROR "Cannot set a CMAKE_CXX_STANDARD smaller than 17")
+endif()
+# We require a C++17 compliant compiler
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
 if (NOT MSVC)
   set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fno-omit-frame-pointer")
   set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG -fno-omit-frame-pointer")
@@ -97,7 +105,12 @@ if (NOT MSVC)
 endif ()
 message(STATUS "compiler ${CMAKE_CXX_COMPILER_ID} version 
${CMAKE_CXX_COMPILER_VERSION}")
 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-  set (CXX11_FLAGS "-std=c++11")
+  if (CMAKE_CXX_COMPILER_VERSION STREQUAL "" OR
+      CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0")
+    message(FATAL_ERROR "A c++17-compliant compiler is required, please use at 
least Clang 5")
+  else ()
+    set (CXX17_FLAGS "-std=c++17")
+  endif ()
   set (WARN_FLAGS "-Weverything -Wno-c++98-compat -Wno-missing-prototypes")
   set (WARN_FLAGS "${WARN_FLAGS} -Wno-c++98-compat-pedantic -Wno-padded")
   set (WARN_FLAGS "${WARN_FLAGS} -Wno-covered-switch-default")
@@ -116,22 +129,27 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
     set (WARN_FLAGS "${WARN_FLAGS} -Werror")
   endif ()
 elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+  if (CMAKE_CXX_COMPILER_VERSION STREQUAL "" OR
+      CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0")
+    message(FATAL_ERROR "A c++17-compliant compiler is required, please use at 
least GCC 5")
+  else ()
+    set (CXX17_FLAGS "-std=c++17")
+  endif ()
   set (WARN_FLAGS "-Wall -Wno-unknown-pragmas -Wconversion")
   if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "12.0")
     set (WARN_FLAGS "${WARN_FLAGS} -Wno-array-bounds -Wno-stringop-overread") 
# To compile protobuf in Fedora37
-  elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9")
-    set (WARN_FLAGS "${WARN_FLAGS} -Wno-unused-function")
   endif ()
   if (STOP_BUILD_ON_WARNING)
     set (WARN_FLAGS "${WARN_FLAGS} -Werror")
   endif ()
-  if (CMAKE_CXX_COMPILER_VERSION STREQUAL "" OR
-      CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
-    set (CXX11_FLAGS "-std=c++0x")
+elseif (MSVC)
+  include(CheckCXXCompilerFlag)
+  CHECK_CXX_COMPILER_FLAG("/std:c++17" CPP17_FLAG_SUPPORTED)
+  if (CPP17_FLAG_SUPPORTED)
+    add_compile_options("/std:c++17")
   else ()
-    set (CXX11_FLAGS "-std=c++11")
+    message(FATAL_ERROR "A c++17-compliant compiler is required")
   endif ()
-elseif (MSVC)
   add_definitions (-D_SCL_SECURE_NO_WARNINGS)
   add_definitions (-D_CRT_SECURE_NO_WARNINGS)
   add_definitions (-D_CRT_NONSTDC_NO_DEPRECATE) # The POSIX name for this item 
is deprecated
diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt
index 5608fbad0..673c156d3 100644
--- a/c++/src/CMakeLists.txt
+++ b/c++/src/CMakeLists.txt
@@ -10,7 +10,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS} ${WARN_FLAGS}")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX17_FLAGS} ${WARN_FLAGS}")
 
 INCLUDE(CheckCXXSourceCompiles)
 
diff --git a/c++/test/CMakeLists.txt b/c++/test/CMakeLists.txt
index d25f0a347..ed2715bf5 100644
--- a/c++/test/CMakeLists.txt
+++ b/c++/test/CMakeLists.txt
@@ -16,7 +16,7 @@ include_directories(
   ${PROJECT_BINARY_DIR}/c++/src
 )
 
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS} ${WARN_FLAGS}")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX17_FLAGS} ${WARN_FLAGS}")
 
 add_executable (orc-test
   MemoryInputStream.cc
diff --git a/c++/test/MemoryOutputStream.hh b/c++/test/MemoryOutputStream.hh
index c05c6239a..a2b727b67 100644
--- a/c++/test/MemoryOutputStream.hh
+++ b/c++/test/MemoryOutputStream.hh
@@ -28,7 +28,7 @@ namespace orc {
 
   class MemoryOutputStream : public OutputStream {
   public:
-    MemoryOutputStream(ssize_t capacity) : name("MemoryOutputStream") {
+    MemoryOutputStream(size_t capacity) : name("MemoryOutputStream") {
       data = new char[capacity];
       length = 0;
       naturalWriteSize = 2048;
diff --git a/cmake_modules/CheckSourceCompiles.cmake 
b/cmake_modules/CheckSourceCompiles.cmake
index 7f337fc70..3168560df 100644
--- a/cmake_modules/CheckSourceCompiles.cmake
+++ b/cmake_modules/CheckSourceCompiles.cmake
@@ -10,7 +10,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS} ${WARN_FLAGS}")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX17_FLAGS} ${WARN_FLAGS}")
 
 INCLUDE(CheckCXXSourceCompiles)
 
diff --git a/tools/src/CMakeLists.txt b/tools/src/CMakeLists.txt
index 4b89aced9..886e84d41 100644
--- a/tools/src/CMakeLists.txt
+++ b/tools/src/CMakeLists.txt
@@ -24,7 +24,7 @@ include_directories (
   ${PROJECT_BINARY_DIR}/c++/src
   )
 
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ${CXX11_FLAGS} ${WARN_FLAGS}")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ${CXX17_FLAGS} ${WARN_FLAGS}")
 
 add_executable (orc-contents
   FileContents.cc
diff --git a/tools/test/CMakeLists.txt b/tools/test/CMakeLists.txt
index e71a51d73..ce48d429f 100644
--- a/tools/test/CMakeLists.txt
+++ b/tools/test/CMakeLists.txt
@@ -18,7 +18,7 @@ include_directories(
   ${PROJECT_BINARY_DIR}/c++/src
 )
 
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_FLAGS} ${WARN_FLAGS}")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX17_FLAGS} ${WARN_FLAGS}")
 
 add_executable (tool-test
   gzip.cc

Reply via email to