1 # ----------------------------------------------------------------------------
2 # CMake file for C samples. See root CMakeLists.txt
4 # ----------------------------------------------------------------------------
6 SET(OPENCV_CPP_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
7 opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching)
9 ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
12 if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
15 include_directories("${OpenCV_SOURCE_DIR}/include")#for opencv.hpp
16 ocv_include_modules(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
19 include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include")
22 if(CMAKE_COMPILER_IS_GNUCXX)
23 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
26 # ---------------------------------------------
27 # Define executable targets
28 # ---------------------------------------------
29 MACRO(OPENCV_DEFINE_CPP_EXAMPLE name srcs)
30 set(the_target "example_${name}")
31 add_executable(${the_target} ${srcs})
32 target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
35 target_link_libraries(${the_target} opencv_gpu)
38 set_target_properties(${the_target} PROPERTIES
40 PROJECT_LABEL "(EXAMPLE) ${name}")
42 if(ENABLE_SOLUTION_FOLDERS)
43 set_target_properties(${the_target} PROPERTIES FOLDER "samples//cpp")
47 if (MSVC AND NOT BUILD_SHARED_LIBS)
48 set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
50 install(TARGETS ${the_target}
51 RUNTIME DESTINATION "samples/cpp" COMPONENT main)
55 file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
57 foreach(sample_filename ${cpp_samples})
58 get_filename_component(sample ${sample_filename} NAME_WE)
59 OPENCV_DEFINE_CPP_EXAMPLE(${sample} ${sample_filename})
63 if (INSTALL_C_EXAMPLES AND NOT WIN32)
64 file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
65 install(FILES ${C_SAMPLES}
66 DESTINATION share/opencv/samples/cpp
67 PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)