Skip to content

Commit 01c1b34

Browse files
committed
cmake: enable C++11 implicitly
1 parent bf2f7b0 commit 01c1b34

File tree

7 files changed

+26
-25
lines changed

7 files changed

+26
-25
lines changed

cmake/templates/OpenCVConfig.cmake.in

+26
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,32 @@ endif()
273273
# ==============================================================
274274
set(OpenCV_LIBRARIES ${OpenCV_LIBS})
275275

276+
# Require C++11 features for OpenCV modules
277+
if(CMAKE_VERSION VERSION_LESS "3.1")
278+
if(NOT OpenCV_FIND_QUIETLY AND NOT OPENCV_HIDE_WARNING_COMPILE_FEATURES)
279+
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")
280+
endif()
281+
else()
282+
set(__target opencv_core)
283+
if(TARGET opencv_world)
284+
set(__target opencv_world)
285+
endif()
286+
set(__compile_features cxx_std_11) # CMake 3.8+
287+
if(DEFINED OPENCV_COMPILE_FEATURES)
288+
set(__compile_features ${OPENCV_COMPILE_FEATURES}) # custom override
289+
elseif(CMAKE_VERSION VERSION_LESS "3.8")
290+
set(__compile_features cxx_auto_type cxx_rvalue_references cxx_lambdas)
291+
endif()
292+
if(__compile_features)
293+
# Simulate exported result of target_compile_features(opencv_core PUBLIC ...)
294+
set_target_properties(${__target} PROPERTIES
295+
INTERFACE_COMPILE_FEATURES "${__compile_features}"
296+
)
297+
endif()
298+
unset(__target)
299+
unset(__compile_features)
300+
endif()
301+
276302
#
277303
# Some macros for samples
278304
#

samples/CMakeLists.example.in

-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ file(TO_CMAKE_PATH "${EXAMPLE_FILE}" EXAMPLE_FILE)
1212
message(STATUS "Project: ${EXAMPLE_NAME}")
1313
message(STATUS "File : ${EXAMPLE_FILE}")
1414

15-
# Enable C++11
16-
set(CMAKE_CXX_STANDARD 11)
17-
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
18-
19-
2015
# Define project name
2116
project(${EXAMPLE_NAME})
2217

samples/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ else()
5858
#===================================================================================================
5959
cmake_minimum_required(VERSION 3.1)
6060

61-
# Enable C++11
62-
set(CMAKE_CXX_STANDARD 11)
63-
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
64-
6561
project(samples C CXX)
6662
option(BUILD_EXAMPLES "Build samples" ON)
6763

samples/android/face-detection/jni/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
cmake_minimum_required(VERSION 3.6)
22

3-
# Enable C++11
4-
set(CMAKE_CXX_STANDARD 11)
5-
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
6-
73
set(target detection_based_tracker)
84
project(${target} CXX)
95

samples/android/tutorial-2-mixedprocessing/jni/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
cmake_minimum_required(VERSION 3.6)
22

3-
# Enable C++11
4-
set(CMAKE_CXX_STANDARD 11)
5-
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
6-
73
set(target mixed_sample)
84
project(${target} CXX)
95

samples/android/tutorial-4-opencl/jni/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
cmake_minimum_required(VERSION 3.6)
22

3-
# Enable C++11
4-
set(CMAKE_CXX_STANDARD 11)
5-
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
6-
73
set(target mixed_sample)
84
project(${target} CXX)
95

samples/cpp/example_cmake/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# cmake needs this line
22
cmake_minimum_required(VERSION 3.1)
33

4-
# Enable C++11
5-
set(CMAKE_CXX_STANDARD 11)
6-
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
7-
84
# Define project name
95
project(opencv_example_project)
106

0 commit comments

Comments
 (0)