1 # ----------------------------------------------------------------------------
2 # CMake file for C samples. See root CMakeLists.txt
4 # ----------------------------------------------------------------------------
6 SET(OPENCV_CPP_SAMPLES_REQUIRED_DEPS opencv_core opencv_imgproc opencv_flann
7 opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_photo opencv_nonfree
8 opencv_features2d opencv_calib3d opencv_stitching opencv_videostab opencv_shape)
10 ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
13 if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
16 ocv_include_directories("${OpenCV_SOURCE_DIR}/include")#for opencv.hpp
17 ocv_include_modules(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
19 if(HAVE_opencv_cudaoptflow)
20 ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaoptflow/include")
22 if(HAVE_opencv_cudaimgproc)
23 ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaimgproc/include")
25 if(HAVE_opencv_cudaarithm)
26 ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaarithm/include")
28 if(HAVE_opencv_cudafilters)
29 ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudafilters/include")
33 ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/ocl/include")
36 if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
37 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
40 # ---------------------------------------------
41 # Define executable targets
42 # ---------------------------------------------
43 MACRO(OPENCV_DEFINE_CPP_EXAMPLE name srcs)
45 if("${srcs}" MATCHES "tutorial_code")
46 set(sample_kind tutorial)
47 set(sample_KIND TUTORIAL)
48 set(sample_subfolder "tutorials")
50 set(sample_kind example)
51 set(sample_KIND EXAMPLE)
52 set(sample_subfolder "cpp")
55 set(the_target "${sample_kind}_${name}")
56 add_executable(${the_target} ${srcs})
57 target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
59 if("${srcs}" MATCHES "gpu/")
60 target_link_libraries(${the_target} opencv_cudaarithm opencv_cudafilters)
64 target_link_libraries(${the_target} opencv_ocl)
67 set_target_properties(${the_target} PROPERTIES
68 OUTPUT_NAME "cpp-${sample_kind}-${name}"
69 PROJECT_LABEL "(${sample_KIND}) ${name}")
71 if(ENABLE_SOLUTION_FOLDERS)
72 set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sample_subfolder}")
76 if (MSVC AND NOT BUILD_SHARED_LIBS)
77 set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
79 install(TARGETS ${the_target}
80 RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT samples)
84 file(GLOB_RECURSE cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
87 ocv_list_filterout(cpp_samples Qt_sample)
90 if(NOT HAVE_opencv_cudaarithm OR NOT HAVE_opencv_cudafilters)
91 ocv_list_filterout(cpp_samples "/gpu/")
94 ocv_list_filterout(cpp_samples "viz")
97 ocv_list_filterout(cpp_samples "/ippasync/")
100 foreach(sample_filename ${cpp_samples})
101 get_filename_component(sample ${sample_filename} NAME_WE)
102 OPENCV_DEFINE_CPP_EXAMPLE(${sample} ${sample_filename})
106 if(INSTALL_C_EXAMPLES AND NOT WIN32)
107 file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
108 install(FILES ${C_SAMPLES}
109 DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/cpp
110 PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)