61 lines
3.0 KiB
Diff
61 lines
3.0 KiB
Diff
From bfd1b325eb93083ce4478c28aa61101ac553b458 Mon Sep 17 00:00:00 2001
|
|
From: xuxuepeng <xuxuepeng1@huawei.com>
|
|
Date: Wed, 13 Sep 2023 02:16:12 +0000
|
|
Subject: [PATCH 33/33] !2188 Support both C++11 and C++17 * Support both C++11
|
|
and C++17
|
|
|
|
---
|
|
cmake/set_build_flags.cmake | 11 ++++++++++-
|
|
test/fuzz/CMakeLists.txt | 13 ++++++++++++-
|
|
2 files changed, 22 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/cmake/set_build_flags.cmake b/cmake/set_build_flags.cmake
|
|
index 09c85c65..38069791 100644
|
|
--- a/cmake/set_build_flags.cmake
|
|
+++ b/cmake/set_build_flags.cmake
|
|
@@ -3,7 +3,16 @@ set(CMAKE_C_FLAGS "-fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2 -Wall -fP
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
|
|
|
|
if (GRPC_CONNECTOR)
|
|
- set(CMAKE_CXX_FLAGS "-fPIC -std=c++17 -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2 -Wall -Wno-error=deprecated-declarations")
|
|
+ include(CheckCXXCompilerFlag)
|
|
+ CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
|
|
+ if (COMPILER_SUPPORTS_CXX17)
|
|
+ message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has C++17 support.")
|
|
+ set(CMAKE_CXX_VERSION "-std=c++17")
|
|
+ else()
|
|
+ message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Use C++11.")
|
|
+ set(CMAKE_CXX_VERSION "-std=c++11")
|
|
+ endif()
|
|
+ set(CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_VERSION} -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2 -Wall -Wno-error=deprecated-declarations")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
|
|
endif()
|
|
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -shared -pthread")
|
|
diff --git a/test/fuzz/CMakeLists.txt b/test/fuzz/CMakeLists.txt
|
|
index 617a168f..0682ffa3 100644
|
|
--- a/test/fuzz/CMakeLists.txt
|
|
+++ b/test/fuzz/CMakeLists.txt
|
|
@@ -34,7 +34,18 @@ MESSAGE(STATUS "GCLANG_PP_BINARY is set to ${GCLANG_PP_BINARY}")
|
|
SET(CMAKE_C_COMPILER "${GCLANG_BINARY}")
|
|
SET(CMAKE_CXX_COMPILER "${GCLANG_PP_BINARY}")
|
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage -fsanitize=fuzzer,address -fsanitize-coverage=indirect-calls,trace-cmp,trace-div,trace-gep")
|
|
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage -std=c++17 -fsanitize=fuzzer,address -fsanitize-coverage=indirect-calls,trace-cmp,trace-div,trace-gep")
|
|
+
|
|
+include(CheckCXXCompilerFlag)
|
|
+CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
|
|
+if (COMPILER_SUPPORTS_CXX17)
|
|
+ message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has C++17 support.")
|
|
+ set(CMAKE_CXX_VERSION "-std=c++17")
|
|
+else()
|
|
+ message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Use C++11.")
|
|
+ set(CMAKE_CXX_VERSION "-std=c++11")
|
|
+endif()
|
|
+
|
|
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage ${CMAKE_CXX_VERSION} -fsanitize=fuzzer,address -fsanitize-coverage=indirect-calls,trace-cmp,trace-div,trace-gep")
|
|
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
SET(EXE0 test_volume_mount_spec_fuzz)
|
|
--
|
|
2.40.1
|
|
|