diff --git a/cmake/templates/OpenCVConfig.cmake.in b/cmake/templates/OpenCVConfig.cmake.in index ef299a4515..2e9022a355 100644 --- a/cmake/templates/OpenCVConfig.cmake.in +++ b/cmake/templates/OpenCVConfig.cmake.in @@ -273,6 +273,32 @@ endif() # ============================================================== set(OpenCV_LIBRARIES ${OpenCV_LIBS}) +# Require C++11 features for OpenCV modules +if(CMAKE_VERSION VERSION_LESS "3.1") + if(NOT OpenCV_FIND_QUIETLY AND NOT OPENCV_HIDE_WARNING_COMPILE_FEATURES) + message(STATUS "OpenCV: CMake version is low (${CMAKE_VERSION}, required 3.1+). Can't enable C++11 features: https://github.com/opencv/opencv/issues/13000") + endif() +else() + set(__target opencv_core) + if(TARGET opencv_world) + set(__target opencv_world) + endif() + set(__compile_features cxx_std_11) # CMake 3.8+ + if(DEFINED OPENCV_COMPILE_FEATURES) + set(__compile_features ${OPENCV_COMPILE_FEATURES}) # custom override + elseif(CMAKE_VERSION VERSION_LESS "3.8") + set(__compile_features cxx_auto_type cxx_rvalue_references cxx_lambdas) + endif() + if(__compile_features) + # Simulate exported result of target_compile_features(opencv_core PUBLIC ...) + set_target_properties(${__target} PROPERTIES + INTERFACE_COMPILE_FEATURES "${__compile_features}" + ) + endif() + unset(__target) + unset(__compile_features) +endif() + # # Some macros for samples # diff --git a/samples/CMakeLists.example.in b/samples/CMakeLists.example.in index 9a00ac2991..7cf20d5e44 100644 --- a/samples/CMakeLists.example.in +++ b/samples/CMakeLists.example.in @@ -12,11 +12,6 @@ file(TO_CMAKE_PATH "${EXAMPLE_FILE}" EXAMPLE_FILE) message(STATUS "Project: ${EXAMPLE_NAME}") message(STATUS "File : ${EXAMPLE_FILE}") -# Enable C++11 -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - - # Define project name project(${EXAMPLE_NAME}) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 6e739a178e..1bbd3fc328 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -58,10 +58,6 @@ else() #=================================================================================================== cmake_minimum_required(VERSION 3.1) -# Enable C++11 -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - project(samples C CXX) option(BUILD_EXAMPLES "Build samples" ON) diff --git a/samples/android/face-detection/jni/CMakeLists.txt b/samples/android/face-detection/jni/CMakeLists.txt index d395999ce0..15f8f4db38 100644 --- a/samples/android/face-detection/jni/CMakeLists.txt +++ b/samples/android/face-detection/jni/CMakeLists.txt @@ -1,9 +1,5 @@ cmake_minimum_required(VERSION 3.6) -# Enable C++11 -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - set(target detection_based_tracker) project(${target} CXX) diff --git a/samples/android/tutorial-2-mixedprocessing/jni/CMakeLists.txt b/samples/android/tutorial-2-mixedprocessing/jni/CMakeLists.txt index 2219121fde..5b34f8b948 100644 --- a/samples/android/tutorial-2-mixedprocessing/jni/CMakeLists.txt +++ b/samples/android/tutorial-2-mixedprocessing/jni/CMakeLists.txt @@ -1,9 +1,5 @@ cmake_minimum_required(VERSION 3.6) -# Enable C++11 -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - set(target mixed_sample) project(${target} CXX) diff --git a/samples/android/tutorial-4-opencl/jni/CMakeLists.txt b/samples/android/tutorial-4-opencl/jni/CMakeLists.txt index 6b3f3a0940..4fdea1356e 100644 --- a/samples/android/tutorial-4-opencl/jni/CMakeLists.txt +++ b/samples/android/tutorial-4-opencl/jni/CMakeLists.txt @@ -1,9 +1,5 @@ cmake_minimum_required(VERSION 3.6) -# Enable C++11 -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - set(target mixed_sample) project(${target} CXX) diff --git a/samples/cpp/example_cmake/CMakeLists.txt b/samples/cpp/example_cmake/CMakeLists.txt index d3d86eed9d..8d5cd98af2 100644 --- a/samples/cpp/example_cmake/CMakeLists.txt +++ b/samples/cpp/example_cmake/CMakeLists.txt @@ -1,10 +1,6 @@ # cmake needs this line cmake_minimum_required(VERSION 3.1) -# Enable C++11 -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) - # Define project name project(opencv_example_project)