Merge branch 'upstream/4.5.3' into tizen
[platform/upstream/opencv.git] / samples / samples_utils.cmake
1 # Utility function: adds sample executable target with name "example_<group>_<file_name>"
2 # Usage:
3 #   ocv_define_sample(<output target> <relative filename> <group>)
4 function(ocv_define_sample out_target source sub)
5   get_filename_component(name "${source}" NAME_WE)
6   set(the_target "example_${sub}_${name}")
7   if(OPENCV_DUMP_EXAMPLE_TARGET)
8     message(STATUS "Example: ${the_target}    (${source})")
9   endif()
10   add_executable(${the_target} "${source}")
11   if(TARGET Threads::Threads AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
12     target_link_libraries(${the_target} PRIVATE Threads::Threads)
13   endif()
14   set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}")
15   if(ENABLE_SOLUTION_FOLDERS)
16     set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sub}")
17   endif()
18   if(WIN32 AND MSVC AND NOT BUILD_SHARED_LIBS)
19     set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
20   endif()
21   # Should be usable in stand-alone build scenario
22   if((NOT DEFINED INSTALL_BIN_EXAMPLES AND WIN32) OR INSTALL_BIN_EXAMPLES)
23     if(NOT DEFINED OPENCV_SAMPLES_BIN_INSTALL_PATH)
24       set(OPENCV_SAMPLES_BIN_INSTALL_PATH "samples")
25     endif()
26     install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sub}" COMPONENT samples)
27   endif()
28   # Add single target to build all samples in the group: 'make opencv_samples_cpp'
29   set(parent_target opencv_samples_${sub})
30   if(NOT TARGET ${parent_target})
31     add_custom_target(${parent_target})
32     if(TARGET opencv_samples)
33       add_dependencies(opencv_samples ${parent_target})
34     endif()
35   endif()
36   add_dependencies(${parent_target} ${the_target})
37   set(${out_target} ${the_target} PARENT_SCOPE)
38 endfunction()