This repository was archived by the owner on Mar 1, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ if (POLICY CMP0003)
2+ cmake_policy (SET CMP0003 NEW )
3+ endif ()
4+
15# Utility function: adds sample executable target with name "example_<group>_<file_name>"
26# Usage:
37# ocv_define_sample(<output target> <relative filename> <group>)
48function (ocv_define_sample out_target source sub )
59 get_filename_component (name "${source} " NAME_WE )
610 set (the_target "example_${sub} _${name} " )
711 add_executable (${the_target} "${source} " )
12+ if (TARGET Threads::Threads AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
13+ target_link_libraries (${the_target} Threads::Threads )
14+ endif ()
815 set_target_properties (${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name} " )
916 if (ENABLE_SOLUTION_FOLDERS)
1017 set_target_properties (${the_target} PROPERTIES FOLDER "samples/${sub} " )
@@ -43,6 +50,10 @@ function(ocv_install_example_src relpath)
4350 endif ()
4451endfunction ()
4552
53+ if ((TARGET Threads::Threads OR HAVE_PTHREAD OR MSVC OR APPLE ) AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
54+ add_definitions (-DHAVE_THREADS=1 )
55+ endif ()
56+
4657add_subdirectory (cpp )
4758add_subdirectory (java/tutorial_code )
4859add_subdirectory (dnn )
@@ -127,6 +138,17 @@ if(MSVC)
127138 endif ()
128139endif ()
129140
141+ if (OPENCV_EXAMPLES_DISABLE_THREADS)
142+ # nothing
143+ elseif (MSVC OR APPLE )
144+ set (HAVE_THREADS 1)
145+ else ()
146+ find_package (Threads )
147+ endif ()
148+ if ((TARGET Threads::Threads OR HAVE_THREADS) AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
149+ add_definitions (-DHAVE_THREADS=1 )
150+ endif ()
151+
130152add_definitions (-DDISABLE_OPENCV_24_COMPATIBILITY=1 ) # Avoid C-like legacy API
131153
132154add_subdirectory (cpp )
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+
3+ #if defined(_MSC_VER) || defined(__APPLE__) || defined HAVE_THREADS
4+
15#include < fstream>
26#include < sstream>
37#include < thread>
@@ -379,3 +383,11 @@ void callback(int pos, void*)
379383{
380384 confThreshold = pos * 0 .01f ;
381385}
386+
387+ #else
388+ int main (int argc, char ** argv)
389+ {
390+ std::cerr << " ERROR: This sample has been compiled without threads support" << std::endl;
391+ return 1 ;
392+ }
393+ #endif
You can’t perform that action at this time.
0 commit comments