mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
cmake: enable threading in samples
- moved code into separate file due issue with handling of CMake policies
This commit is contained in:
parent
b998c06d08
commit
3201ea89d6
@ -1,32 +1,3 @@
|
|||||||
# Utility function: adds sample executable target with name "example_<group>_<file_name>"
|
|
||||||
# Usage:
|
|
||||||
# ocv_define_sample(<output target> <relative filename> <group>)
|
|
||||||
function(ocv_define_sample out_target source sub)
|
|
||||||
get_filename_component(name "${source}" NAME_WE)
|
|
||||||
set(the_target "example_${sub}_${name}")
|
|
||||||
add_executable(${the_target} "${source}")
|
|
||||||
set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}")
|
|
||||||
if(ENABLE_SOLUTION_FOLDERS)
|
|
||||||
set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sub}")
|
|
||||||
endif()
|
|
||||||
if(WIN32 AND MSVC AND NOT BUILD_SHARED_LIBS)
|
|
||||||
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
|
|
||||||
endif()
|
|
||||||
if(WIN32)
|
|
||||||
install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${sub}" COMPONENT samples)
|
|
||||||
endif()
|
|
||||||
# Add single target to build all samples in the group: 'make opencv_samples_cpp'
|
|
||||||
set(parent_target opencv_samples_${sub})
|
|
||||||
if(NOT TARGET ${parent_target})
|
|
||||||
add_custom_target(${parent_target})
|
|
||||||
if(TARGET opencv_samples)
|
|
||||||
add_dependencies(opencv_samples ${parent_target})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
add_dependencies(${parent_target} ${the_target})
|
|
||||||
set(${out_target} ${the_target} PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR)
|
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR)
|
||||||
#===================================================================================================
|
#===================================================================================================
|
||||||
#
|
#
|
||||||
@ -34,6 +5,8 @@ if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_LIST_DIR)
|
|||||||
#
|
#
|
||||||
#===================================================================================================
|
#===================================================================================================
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/samples_utils.cmake")
|
||||||
|
|
||||||
function(ocv_install_example_src relpath)
|
function(ocv_install_example_src relpath)
|
||||||
if(INSTALL_C_EXAMPLES)
|
if(INSTALL_C_EXAMPLES)
|
||||||
file(GLOB files ${ARGN})
|
file(GLOB files ${ARGN})
|
||||||
@ -43,6 +16,10 @@ function(ocv_install_example_src relpath)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
if((TARGET Threads::Threads OR HAVE_PTHREAD OR MSVC OR APPLE) AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
|
||||||
|
add_definitions(-DHAVE_THREADS=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_subdirectory(cpp)
|
add_subdirectory(cpp)
|
||||||
add_subdirectory(java/tutorial_code)
|
add_subdirectory(java/tutorial_code)
|
||||||
add_subdirectory(dnn)
|
add_subdirectory(dnn)
|
||||||
@ -94,6 +71,8 @@ option(BUILD_EXAMPLES "Build samples" ON)
|
|||||||
# │ ├── cpp/
|
# │ ├── cpp/
|
||||||
find_package(OpenCV REQUIRED PATHS "..")
|
find_package(OpenCV REQUIRED PATHS "..")
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/samples_utils.cmake")
|
||||||
|
|
||||||
function(ocv_install_example_src)
|
function(ocv_install_example_src)
|
||||||
# not used in this branch
|
# not used in this branch
|
||||||
endfunction()
|
endfunction()
|
||||||
@ -125,6 +104,17 @@ endif()
|
|||||||
|
|
||||||
add_definitions(-DDISABLE_OPENCV_24_COMPATIBILITY=1) # Avoid C-like legacy API
|
add_definitions(-DDISABLE_OPENCV_24_COMPATIBILITY=1) # Avoid C-like legacy API
|
||||||
|
|
||||||
|
if(OPENCV_EXAMPLES_DISABLE_THREADS)
|
||||||
|
# nothing
|
||||||
|
elseif(MSVC OR APPLE)
|
||||||
|
set(HAVE_THREADS 1)
|
||||||
|
else()
|
||||||
|
find_package(Threads)
|
||||||
|
endif()
|
||||||
|
if((TARGET Threads::Threads OR HAVE_THREADS) AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
|
||||||
|
add_definitions(-DHAVE_THREADS=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_subdirectory(cpp)
|
add_subdirectory(cpp)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
add_subdirectory(directx)
|
add_subdirectory(directx)
|
||||||
|
31
samples/samples_utils.cmake
Normal file
31
samples/samples_utils.cmake
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Utility function: adds sample executable target with name "example_<group>_<file_name>"
|
||||||
|
# Usage:
|
||||||
|
# ocv_define_sample(<output target> <relative filename> <group>)
|
||||||
|
function(ocv_define_sample out_target source sub)
|
||||||
|
get_filename_component(name "${source}" NAME_WE)
|
||||||
|
set(the_target "example_${sub}_${name}")
|
||||||
|
add_executable(${the_target} "${source}")
|
||||||
|
if(TARGET Threads::Threads AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
|
||||||
|
target_link_libraries(${the_target} LINK_PRIVATE Threads::Threads)
|
||||||
|
endif()
|
||||||
|
set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}")
|
||||||
|
if(ENABLE_SOLUTION_FOLDERS)
|
||||||
|
set_target_properties(${the_target} PROPERTIES FOLDER "samples/${sub}")
|
||||||
|
endif()
|
||||||
|
if(WIN32 AND MSVC AND NOT BUILD_SHARED_LIBS)
|
||||||
|
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
|
||||||
|
endif()
|
||||||
|
if(WIN32)
|
||||||
|
install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${sub}" COMPONENT samples)
|
||||||
|
endif()
|
||||||
|
# Add single target to build all samples in the group: 'make opencv_samples_cpp'
|
||||||
|
set(parent_target opencv_samples_${sub})
|
||||||
|
if(NOT TARGET ${parent_target})
|
||||||
|
add_custom_target(${parent_target})
|
||||||
|
if(TARGET opencv_samples)
|
||||||
|
add_dependencies(opencv_samples ${parent_target})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
add_dependencies(${parent_target} ${the_target})
|
||||||
|
set(${out_target} ${the_target} PARENT_SCOPE)
|
||||||
|
endfunction()
|
Loading…
Reference in New Issue
Block a user