OpenCVGenSetupVars.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. if(WIN32)
  2. ocv_update(OPENCV_SETUPVARS_INSTALL_PATH ".")
  3. ocv_update(OPENCV_SCRIPT_EXTENSION ".cmd")
  4. ocv_update(OPENCV_SETUPVARS_TEMPLATE "setup_vars_win32.cmd.in")
  5. else()
  6. ocv_update(OPENCV_SETUPVARS_INSTALL_PATH "bin")
  7. ocv_update(OPENCV_SCRIPT_EXTENSION ".sh")
  8. if(APPLE)
  9. ocv_update(OPENCV_SETUPVARS_TEMPLATE "setup_vars_macosx.sh.in")
  10. else()
  11. ocv_update(OPENCV_SETUPVARS_TEMPLATE "setup_vars_linux.sh.in")
  12. endif()
  13. endif()
  14. if(INSTALL_TO_MANGLED_PATHS)
  15. ocv_update(OPENCV_SETUPVARS_FILENAME "setup_vars_opencv-${OPENCV_VERSION}${OPENCV_SCRIPT_EXTENSION}")
  16. else()
  17. ocv_update(OPENCV_SETUPVARS_FILENAME setup_vars_opencv4${OPENCV_SCRIPT_EXTENSION})
  18. endif()
  19. ##### build directory
  20. if(WIN32)
  21. set(__build_type "${CMAKE_BUILD_TYPE}")
  22. if(NOT __build_type)
  23. set(__build_type "Release") # default
  24. endif()
  25. file(RELATIVE_PATH OPENCV_LIB_RUNTIME_DIR_RELATIVE_CMAKECONFIG "${OpenCV_BINARY_DIR}/" "${EXECUTABLE_OUTPUT_PATH}/${__build_type}/")
  26. else()
  27. file(RELATIVE_PATH OPENCV_LIB_RUNTIME_DIR_RELATIVE_CMAKECONFIG "${OpenCV_BINARY_DIR}/" "${LIBRARY_OUTPUT_PATH}/")
  28. endif()
  29. set(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "python_loader") # https://github.com/opencv/opencv/pull/12977
  30. configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/${OPENCV_SETUPVARS_TEMPLATE}" "${CMAKE_BINARY_DIR}/tmp/setup_vars${OPENCV_SCRIPT_EXTENSION}" @ONLY)
  31. file(COPY "${CMAKE_BINARY_DIR}/tmp/setup_vars${OPENCV_SCRIPT_EXTENSION}" DESTINATION "${CMAKE_BINARY_DIR}"
  32. FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  33. ##### install directory
  34. if(WIN32)
  35. file(RELATIVE_PATH OPENCV_LIB_RUNTIME_DIR_RELATIVE_CMAKECONFIG
  36. "${CMAKE_INSTALL_PREFIX}/${OPENCV_SETUPVARS_INSTALL_PATH}/" "${CMAKE_INSTALL_PREFIX}/${OPENCV_BIN_INSTALL_PATH}/")
  37. else()
  38. file(RELATIVE_PATH OPENCV_LIB_RUNTIME_DIR_RELATIVE_CMAKECONFIG
  39. "${CMAKE_INSTALL_PREFIX}/${OPENCV_SETUPVARS_INSTALL_PATH}/" "${CMAKE_INSTALL_PREFIX}/${OPENCV_LIB_INSTALL_PATH}/")
  40. endif()
  41. file(RELATIVE_PATH OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG
  42. "${CMAKE_INSTALL_PREFIX}/${OPENCV_SETUPVARS_INSTALL_PATH}/" "${CMAKE_INSTALL_PREFIX}/")
  43. if(DEFINED OPENCV_PYTHON_INSTALL_PATH)
  44. set(__python_path "${OPENCV_PYTHON_INSTALL_PATH}")
  45. elseif(DEFINED OPENCV_PYTHON_INSTALL_PATH_SETUPVARS)
  46. set(__python_path "${OPENCV_PYTHON_INSTALL_PATH_SETUPVARS}")
  47. endif()
  48. if(DEFINED __python_path)
  49. if(IS_ABSOLUTE "${__python_path}")
  50. set(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "${__python_path}")
  51. message(WARNING "CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install directory")
  52. else()
  53. ocv_path_join(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "${OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG}" "${__python_path}")
  54. endif()
  55. else()
  56. if(DEFINED OPENCV_PYTHON3_INSTALL_PATH)
  57. ocv_path_join(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "${OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG}" "${OPENCV_PYTHON3_INSTALL_PATH}")
  58. else()
  59. set(OPENCV_PYTHON_DIR_RELATIVE_CMAKECONFIG "python_loader_is_not_installed")
  60. endif()
  61. endif()
  62. configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/${OPENCV_SETUPVARS_TEMPLATE}" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/install/${OPENCV_SETUPVARS_FILENAME}" @ONLY)
  63. install(FILES "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/install/${OPENCV_SETUPVARS_FILENAME}"
  64. DESTINATION "${OPENCV_SETUPVARS_INSTALL_PATH}"
  65. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
  66. COMPONENT scripts)