95de6f2f664d11d1161181c058db4a2dd96e94c7
[profile/ivi/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_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
7                                      opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching)
8
9 ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
10
11
12 if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
13   project(cpp_samples)
14
15   include_directories("${OpenCV_SOURCE_DIR}/include")#for opencv.hpp
16   ocv_include_modules(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
17
18   if (HAVE_opencv_gpu)
19     include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include")
20   endif()
21
22   if(CMAKE_COMPILER_IS_GNUCXX)
23     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
24   endif()
25     
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})
33
34     if (HAVE_opencv_gpu)
35       target_link_libraries(${the_target} opencv_gpu)
36     endif()
37
38     set_target_properties(${the_target} PROPERTIES
39       OUTPUT_NAME "${name}"
40       PROJECT_LABEL "(EXAMPLE) ${name}")
41             
42     if(ENABLE_SOLUTION_FOLDERS)
43       set_target_properties(${the_target} PROPERTIES FOLDER "samples//cpp")
44     endif()
45
46     if(WIN32)
47       if (MSVC AND NOT BUILD_SHARED_LIBS)
48         set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
49       endif()
50       install(TARGETS ${the_target}
51               RUNTIME DESTINATION "samples/cpp" COMPONENT main)
52     endif()
53   ENDMACRO()
54     
55   file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
56     
57   foreach(sample_filename ${cpp_samples})
58     get_filename_component(sample ${sample_filename} NAME_WE)
59     OPENCV_DEFINE_CPP_EXAMPLE(${sample}  ${sample_filename})
60   endforeach()
61 endif()
62
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)
68 endif()
69