Home | History | Annotate | Download | only in cpp
      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_imgcodecs opencv_videoio opencv_highgui opencv_ml opencv_video
      8     opencv_objdetect opencv_photo opencv_features2d opencv_calib3d
      9     opencv_stitching opencv_videostab opencv_shape)
     10 
     11 ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
     12 
     13 
     14 if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
     15   project(cpp_samples)
     16 
     17   ocv_include_directories("${OpenCV_SOURCE_DIR}/include")#for opencv.hpp
     18   ocv_include_modules_recurse(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
     19 
     20   if(HAVE_opencv_cudaoptflow)
     21     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaoptflow/include")
     22   endif()
     23   if(HAVE_opencv_cudaimgproc)
     24     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaimgproc/include")
     25   endif()
     26   if(HAVE_opencv_cudaarithm)
     27     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudaarithm/include")
     28   endif()
     29   if(HAVE_opencv_cudafilters)
     30     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/cudafilters/include")
     31   endif()
     32 
     33   if (HAVE_opencv_xfeatures2d)
     34     ocv_include_directories("${OPENCV_MODULE_opencv_xfeatures2d_LOCATION}/include")
     35   endif()
     36 
     37   if(HAVE_opencv_ocl)
     38     ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/ocl/include")
     39   endif()
     40 
     41   if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
     42     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
     43   endif()
     44 
     45   # ---------------------------------------------
     46   #      Define executable targets
     47   # ---------------------------------------------
     48   MACRO(OPENCV_DEFINE_CPP_EXAMPLE name srcs)
     49 
     50     if("${srcs}" MATCHES "tutorial_code")
     51       set(sample_kind tutorial)
     52       set(sample_KIND TUTORIAL)
     53       set(sample_subfolder "tutorials")
     54     else()
     55       set(sample_kind example)
     56       set(sample_KIND EXAMPLE)
     57       set(sample_subfolder "cpp")
     58     endif()
     59 
     60     set(the_target "${sample_kind}_${name}")
     61     add_executable(${the_target} ${srcs})
     62     ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
     63 
     64     if("${srcs}" MATCHES "gpu/")
     65       ocv_target_link_libraries(${the_target} opencv_cudaarithm opencv_cudafilters)
     66     endif()
     67 
     68     if(HAVE_opencv_ocl)
     69       ocv_target_link_libraries(${the_target} opencv_ocl)
     70     endif()
     71 
     72     set_target_properties(${the_target} PROPERTIES
     73       OUTPUT_NAME "cpp-${sample_kind}-${name}"
     74       PROJECT_LABEL "(${sample_KIND}) ${name}")
     75 
     76     if(ENABLE_SOLUTION_FOLDERS)
     77       set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sample_subfolder}")
     78     endif()
     79 
     80     if(WIN32)
     81       if (MSVC AND NOT BUILD_SHARED_LIBS)
     82         set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
     83       endif()
     84       install(TARGETS ${the_target}
     85               RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT samples)
     86     endif()
     87   ENDMACRO()
     88 
     89   file(GLOB_RECURSE cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
     90 
     91   if(NOT HAVE_OPENGL)
     92     ocv_list_filterout(cpp_samples Qt_sample)
     93   endif()
     94 
     95   if(NOT HAVE_opencv_cudaarithm OR NOT HAVE_opencv_cudafilters)
     96     ocv_list_filterout(cpp_samples "/gpu/")
     97   endif()
     98 
     99   ocv_list_filterout(cpp_samples "viz")
    100 
    101   if(NOT HAVE_IPP_A)
    102     ocv_list_filterout(cpp_samples "/ippasync/")
    103   endif()
    104 
    105   foreach(sample_filename ${cpp_samples})
    106     if(NOT "${sample_filename}" MATCHES "real_time_pose_estimation/")
    107         get_filename_component(sample ${sample_filename} NAME_WE)
    108         OPENCV_DEFINE_CPP_EXAMPLE(${sample}  ${sample_filename})
    109     endif()
    110   endforeach()
    111 
    112   include("tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt")
    113 endif()
    114 
    115 if(INSTALL_C_EXAMPLES AND NOT WIN32)
    116   file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
    117   install(FILES ${C_SAMPLES}
    118           DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/cpp
    119           PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)
    120 endif()
    121