Install: added prebuilt samples installation
authorMaksim Shabunin <maksim.shabunin@gmail.com>
Tue, 8 Sep 2020 17:22:26 +0000 (20:22 +0300)
committerMaksim Shabunin <maksim.shabunin@gmail.com>
Tue, 8 Sep 2020 17:22:26 +0000 (20:22 +0300)
CMakeLists.txt
cmake/OpenCVModule.cmake
samples/samples_utils.cmake

index 2620bbe..d143a7a 100644 (file)
@@ -463,6 +463,7 @@ OCV_OPTION(BUILD_JAVA               "Enable Java support"
 # OpenCV installation options
 # ===================================================
 OCV_OPTION(INSTALL_CREATE_DISTRIB   "Change install rules to build the distribution package" OFF )
+OCV_OPTION(INSTALL_BIN_EXAMPLES     "Install prebuilt examples" WIN32 IF BUILD_EXAMPLES)
 OCV_OPTION(INSTALL_C_EXAMPLES       "Install C examples"        OFF )
 OCV_OPTION(INSTALL_PYTHON_EXAMPLES  "Install Python examples"   OFF )
 OCV_OPTION(INSTALL_ANDROID_EXAMPLES "Install Android examples"  OFF IF ANDROID )
index 634b5b2..10ee406 100644 (file)
@@ -1337,8 +1337,8 @@ function(ocv_add_samples)
         endif()
         add_dependencies(${parent_target} ${the_target})
 
-        if(WIN32)
-          install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT samples)
+        if(INSTALL_BIN_EXAMPLES)
+          install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${module_id}" COMPONENT samples)
         endif()
       endforeach()
     endif()
index 845b458..9459099 100644 (file)
@@ -15,8 +15,12 @@ function(ocv_define_sample out_target source sub)
   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)
+  # Should be usable in stand-alone build scenario
+  if((NOT DEFINED INSTALL_BIN_EXAMPLES AND WIN32) OR INSTALL_BIN_EXAMPLES)
+    if(NOT DEFINED OPENCV_SAMPLES_BIN_INSTALL_PATH)
+      set(OPENCV_SAMPLES_BIN_INSTALL_PATH "samples")
+    endif()
+    install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sub}" COMPONENT samples)
   endif()
   # Add single target to build all samples in the group: 'make opencv_samples_cpp'
   set(parent_target opencv_samples_${sub})