removed contrib, legacy and softcsscade modules; removed latentsvm and datamatrix...
[platform/upstream/opencv.git] / samples / cpp / CMakeLists.txt
1 # ----------------------------------------------------------------------------
2 #  CMake file for C samples. See root CMakeLists.txt
3 #
4 # ----------------------------------------------------------------------------
5
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)
9
10 ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
11
12
13 if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
14   project(cpp_samples)
15
16   ocv_include_directories("${OpenCV_SOURCE_DIR}/include")#for opencv.hpp
17   ocv_include_modules(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
18
19   if(HAVE_opencv_cudaoptflow)
20     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaoptflow/include")
21   endif()
22   if(HAVE_opencv_cudaimgproc)
23     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaimgproc/include")
24   endif()
25   if(HAVE_opencv_cudaarithm)
26     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaarithm/include")
27   endif()
28   if(HAVE_opencv_cudafilters)
29     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudafilters/include")
30   endif()
31
32   if(HAVE_opencv_ocl)
33     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/ocl/include")
34   endif()
35
36   if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
37     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
38   endif()
39
40   # ---------------------------------------------
41   #      Define executable targets
42   # ---------------------------------------------
43   MACRO(OPENCV_DEFINE_CPP_EXAMPLE name srcs)
44
45     if("${srcs}" MATCHES "tutorial_code")
46       set(sample_kind tutorial)
47       set(sample_KIND TUTORIAL)
48       set(sample_subfolder "tutorials")
49     else()
50       set(sample_kind example)
51       set(sample_KIND EXAMPLE)
52       set(sample_subfolder "cpp")
53     endif()
54
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})
58
59     if("${srcs}" MATCHES "gpu/")
60       target_link_libraries(${the_target} opencv_cudaarithm opencv_cudafilters)
61     endif()
62
63     if(HAVE_opencv_ocl)
64       target_link_libraries(${the_target} opencv_ocl)
65     endif()
66
67     set_target_properties(${the_target} PROPERTIES
68       OUTPUT_NAME "cpp-${sample_kind}-${name}"
69       PROJECT_LABEL "(${sample_KIND}) ${name}")
70
71     if(ENABLE_SOLUTION_FOLDERS)
72       set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sample_subfolder}")
73     endif()
74
75     if(WIN32)
76       if (MSVC AND NOT BUILD_SHARED_LIBS)
77         set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
78       endif()
79       install(TARGETS ${the_target}
80               RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT samples)
81     endif()
82   ENDMACRO()
83
84   file(GLOB_RECURSE cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
85
86   if(NOT HAVE_OPENGL)
87     ocv_list_filterout(cpp_samples Qt_sample)
88   endif()
89
90   if(NOT HAVE_opencv_cudaarithm OR NOT HAVE_opencv_cudafilters)
91     ocv_list_filterout(cpp_samples "/gpu/")
92   endif()
93
94   ocv_list_filterout(cpp_samples "viz")
95
96   if(NOT HAVE_IPP_A)
97     ocv_list_filterout(cpp_samples "/ippasync/")
98   endif()
99
100   foreach(sample_filename ${cpp_samples})
101     get_filename_component(sample ${sample_filename} NAME_WE)
102     OPENCV_DEFINE_CPP_EXAMPLE(${sample}  ${sample_filename})
103   endforeach()
104 endif()
105
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)
111 endif()