1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

cmake: refactored scripts with samples building:

- allow installing samples sources on all platforms
  even if BUILD_EXAMPLES is disabled,  fixed minor
  issues in sources installation process
- use 'example_<group>_<name>' scheme for target and binary file naming
- use single function for sample executable creation
This commit is contained in:
Maksim Shabunin
2018-02-09 13:30:04 +03:00
parent 633b0e56a5
commit 2200e13c71
15 changed files with 346 additions and 576 deletions
+16 -13
View File
@@ -1221,9 +1221,13 @@ function(ocv_add_samples)
ocv_debug_message("ocv_add_samples(" ${ARGN} ")")
set(samples_path "${CMAKE_CURRENT_SOURCE_DIR}/samples")
if(NOT EXISTS "${samples_path}")
return()
endif()
string(REGEX REPLACE "^opencv_" "" module_id ${the_module})
if(BUILD_EXAMPLES AND EXISTS "${samples_path}")
if(BUILD_EXAMPLES)
set(samples_deps ${the_module} ${OPENCV_MODULE_${the_module}_DEPS} opencv_imgcodecs opencv_videoio opencv_highgui ${ARGN})
ocv_check_dependencies(${samples_deps})
@@ -1237,15 +1241,14 @@ function(ocv_add_samples)
ocv_add_executable(${the_target} "${source}")
ocv_target_include_modules(${the_target} ${samples_deps})
ocv_target_link_libraries(${the_target} LINK_PRIVATE ${samples_deps})
set_target_properties(${the_target} PROPERTIES PROJECT_LABEL "(sample) ${name}")
set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample")
set_source_files_properties("${source}"
PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample")
set_target_properties(${the_target} PROPERTIES
PROJECT_LABEL "(sample) ${name}"
LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample")
set_source_files_properties("${source}" PROPERTIES
LABELS "${OPENCV_MODULE_${the_module}_LABEL};Sample")
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES
OUTPUT_NAME "${module_id}-example-${name}"
FOLDER "samples/${module_id}")
endif()
@@ -1256,8 +1259,8 @@ function(ocv_add_samples)
endif()
endif()
if(INSTALL_C_EXAMPLES AND NOT WIN32 AND EXISTS "${samples_path}")
file(GLOB DEPLOY_FILES_AND_DIRS "${samples_path}/*")
if(INSTALL_C_EXAMPLES)
file(GLOB DEPLOY_FILES_AND_DIRS "${samples_path}/*")
foreach(ITEM ${DEPLOY_FILES_AND_DIRS})
IF( IS_DIRECTORY "${ITEM}" )
LIST( APPEND sample_dirs "${ITEM}" )
@@ -1266,10 +1269,10 @@ function(ocv_add_samples)
ENDIF()
endforeach()
install(FILES ${sample_files}
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id}
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)
DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id}"
COMPONENT samples)
install(DIRECTORY ${sample_dirs}
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id}
USE_SOURCE_PERMISSIONS COMPONENT samples)
DESTINATION "${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id}"
COMPONENT samples)
endif()
endfunction()