mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 20:50:25 +08:00
cmake: update CXX11 compiler flag
This commit is contained in:
parent
108188e42f
commit
3f02f569af
@ -110,14 +110,12 @@ if(POLICY CMP0056)
|
||||
cmake_policy(SET CMP0056 NEW)
|
||||
endif()
|
||||
|
||||
include(cmake/OpenCVUtils.cmake)
|
||||
|
||||
if(OPENCV_CXX11)
|
||||
#cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
if(POLICY CMP0067)
|
||||
cmake_policy(SET CMP0067 NEW)
|
||||
endif()
|
||||
|
||||
include(cmake/OpenCVUtils.cmake)
|
||||
|
||||
# must go before the project command
|
||||
ocv_update(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
|
||||
if(DEFINED CMAKE_BUILD_TYPE)
|
||||
@ -149,6 +147,7 @@ endif()
|
||||
# ----------------------------------------------------------------------------
|
||||
# Detect compiler and target platform architecture
|
||||
# ----------------------------------------------------------------------------
|
||||
OCV_OPTION(ENABLE_CXX11 "Enable C++11 compilation mode" "${OPENCV_CXX11}")
|
||||
include(cmake/OpenCVDetectCXXCompiler.cmake)
|
||||
|
||||
# Add these standard paths to the search paths for FIND_LIBRARY
|
||||
@ -305,7 +304,6 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar
|
||||
|
||||
# OpenCV build options
|
||||
# ===================================================
|
||||
OCV_OPTION(OPENCV_CXX11 "Enable C++11 compilation mode" OFF )
|
||||
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND NOT IOS AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja")) )
|
||||
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" ON IF (NOT IOS AND NOT CMAKE_CROSSCOMPILING) )
|
||||
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
|
||||
@ -963,8 +961,8 @@ string(STRIP "${OPENCV_COMPILER_STR}" OPENCV_COMPILER_STR)
|
||||
status("")
|
||||
status(" C/C++:")
|
||||
status(" Built as dynamic libs?:" BUILD_SHARED_LIBS THEN YES ELSE NO)
|
||||
if(OPENCV_CXX11)
|
||||
status(" C++11:" "YES")
|
||||
if(ENABLE_CXX11 OR HAVE_CXX11)
|
||||
status(" C++11:" HAVE_CXX11 THEN YES ELSE NO)
|
||||
endif()
|
||||
status(" C++ Compiler:" ${OPENCV_COMPILER_STR})
|
||||
status(" C++ flags (Release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
|
||||
|
@ -182,3 +182,23 @@ if(CMAKE_VERSION VERSION_LESS "3.1")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(ENABLE_CXX11)
|
||||
#cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF) # use -std=c++11 instead of -std=gnu++11
|
||||
if(XCMAKE_CXX11_COMPILE_FEATURES)
|
||||
set(HAVE_CXX11 ON)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT HAVE_CXX11)
|
||||
ocv_check_compiler_flag(CXX "" HAVE_CXX11 "${OpenCV_SOURCE_DIR}/cmake/checks/cxx11.cpp")
|
||||
if(NOT HAVE_CXX11 AND ENABLE_CXX11)
|
||||
ocv_check_compiler_flag(CXX "-std=c++11" HAVE_STD_CXX11 "${OpenCV_SOURCE_DIR}/cmake/checks/cxx11.cpp")
|
||||
if(HAVE_STD_CXX11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(HAVE_CXX11 ON)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
13
cmake/checks/cxx11.cpp
Normal file
13
cmake/checks/cxx11.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)
|
||||
// OK
|
||||
#else
|
||||
#error "C++11 is not supported"
|
||||
#endif
|
||||
|
||||
static int test() { return 0; }
|
||||
|
||||
int main()
|
||||
{
|
||||
auto res = test();
|
||||
return res;
|
||||
}
|
Loading…
Reference in New Issue
Block a user