CMakeLists.txt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. if(NOT HAVE_JULIA)
  2. message(STATUS "Julia not found. Not compiling Julia Bindings. ${HAVE_JULIA}")
  3. ocv_module_disable(julia)
  4. elseif(NOT PYTHON_DEFAULT_EXECUTABLE)
  5. message(WARNING "Python required for Julia bindings...disabling")
  6. ocv_module_disable(julia)
  7. endif()
  8. # WARN_MIXED_PRECISION
  9. macro(WARN_MIXED_PRECISION COMPILER_BITNESS JULIA_BITNESS)
  10. set(MSG "Your compiler is ${COMPILER_BITNESS}-bit")
  11. set(MSG "${MSG} but your version of Julia is ${JULIA_BITNESS}-bit.")
  12. set(MSG "${MSG} To build Julia bindings, please switch to a ${JULIA_BITNESS}-bit compiler.")
  13. message(WARNING ${MSG})
  14. endmacro()
  15. math(EXPR ARCH "${CMAKE_SIZEOF_VOID_P} * 8")
  16. if (${ARCH} EQUAL 32 AND ${Julia_WORD_SIZE} MATCHES "64")
  17. warn_mixed_precision("32" "64")
  18. ocv_module_disable(julia)
  19. return()
  20. elseif (${ARCH} EQUAL 64 AND NOT ${Julia_WORD_SIZE} MATCHES "64")
  21. warn_mixed_precision("64" "32")
  22. ocv_module_disable(julia)
  23. return()
  24. endif()
  25. if(NOT JlCxx_DIR)
  26. execute_process(
  27. COMMAND "${Julia_EXECUTABLE}" --startup-file=no -e "using CxxWrap; print(CxxWrap.CxxWrapCore.prefix_path())"
  28. OUTPUT_VARIABLE JlCxx_DIR
  29. )
  30. endif()
  31. if(JlCxx_DIR)
  32. if(EXISTS ${JlCxx_DIR}/JlCxxConfig.cmake)
  33. else()
  34. message(STATUS "JlCxx found but not source build - disabling Julia module")
  35. ocv_module_disable(julia)
  36. endif()
  37. endif()
  38. find_package(JlCxx QUIET)
  39. if(NOT JlCxx_FOUND)
  40. message(STATUS "JlCxx not found")
  41. ocv_module_disable(julia)
  42. return()
  43. else()
  44. message(STATUS "JlCxx_DIR: ${JlCxx_DIR}")
  45. endif()
  46. set(JlCxx_DIR "${JlCxx_DIR}" CACHE STRING ADVANCED)
  47. set(HAVE_JULIA "YES" CACHE STRING ADVANCED)
  48. set(the_description "The Julia bindings")
  49. ocv_add_module(
  50. julia
  51. BINDINGS
  52. OPTIONAL
  53. opencv_core
  54. opencv_imgproc
  55. opencv_imgcodecs
  56. opencv_highgui
  57. opencv_videoio
  58. opencv_dnn
  59. opencv_features2d
  60. opencv_objdetect
  61. opencv_calib3d
  62. )
  63. set(HDR_PARSER_PATH ${CMAKE_SOURCE_DIR}/modules/python/src2/hdr_parser.py)
  64. set(opencv_hdrs "")
  65. foreach(m ${OPENCV_MODULES_BUILD})
  66. list(APPEND opencv_hdrs ${OPENCV_MODULE_${m}_HEADERS})
  67. endforeach(m)
  68. file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/gen/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/gen)
  69. file(COPY ${HDR_PARSER_PATH} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/gen)
  70. message(STATUS "Generating Julia Binding Files")
  71. execute_process(
  72. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gen"
  73. COMMAND ${PYTHON_DEFAULT_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/gen/gen_all.py" ${CMAKE_SOURCE_DIR}/modules ${OPENCV_MODULES_BUILD}
  74. )
  75. file(COPY ${CMAKE_CURRENT_BINARY_DIR}/gen/cpp_files/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/gen/autogen_cpp)
  76. file(COPY ${CMAKE_CURRENT_BINARY_DIR}/gen/jl_cxx_files/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/gen/autogen_jl)
  77. ocv_glob_module_sources()
  78. ocv_module_include_directories()
  79. ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-prototypes -Wmissing-declarations)
  80. ocv_add_library(${the_module} SHARED ${OPENCV_MODULE_${the_module}_HEADERS}
  81. ${OPENCV_MODULE_${the_module}_SOURCES}
  82. "${CMAKE_CURRENT_BINARY_DIR}/gen/autogen_cpp/cv_core.cpp")
  83. if(NOT JULIA_PKG_INSTALL_PATH)
  84. set(JULIA_PKG_INSTALL_PATH ${CMAKE_BINARY_DIR})
  85. endif()
  86. set(JULIA_PKG_INSTALL_PATH_HOOK ${JULIA_PKG_INSTALL_PATH} CACHE STRING "" FORCE)
  87. mark_as_advanced(JULIA_PKG_INSTALL_PATH_HOOK)
  88. message(STATUS "Installing ${the_module} bindings at ${JULIA_PKG_INSTALL_PATH}")
  89. install(DIRECTORY package/ DESTINATION ${JULIA_PKG_INSTALL_PATH})
  90. install(TARGETS ${the_module} LIBRARY DESTINATION ${JULIA_PKG_INSTALL_PATH}/OpenCV/src/lib)
  91. if(JULIA_PKG_INSTALL_ENV)
  92. set(JULIA_PKG_EXECS "Pkg.activate(${JULIA_PKG_INSTALL_ENV});${JULIA_PKG_EXECS}")
  93. endif()
  94. set(JULIA_COMMAND "\"${Julia_EXECUTABLE}\" -e \"using Pkg; ${JULIA_PKG_EXECS}\"")
  95. # message(STATUS "Installing Julia bindings using ${JULIA_COMMAND}")
  96. if(NOT INSTALL_CREATE_DISTRIB)
  97. install(CODE "
  98. set(JULIA_PKG_PATH \"${JULIA_PKG_INSTALL_PATH}/OpenCV\")
  99. execute_process(COMMAND \"${Julia_EXECUTABLE}\" ${CMAKE_CURRENT_LIST_DIR}/package/install_package.jl \${JULIA_PKG_PATH} OUTPUT_VARIABLE JULIA_INSTALL_OUT)
  100. message(STATUS \"Install output: \${JULIA_INSTALL_OUT}\")
  101. ")
  102. endif()
  103. # ocv_create_module()
  104. # ocv_add_accuracy_tests()
  105. # ocv_add_perf_tests()
  106. ocv_add_samples()
  107. message(STATUS ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK})
  108. ocv_target_link_libraries(${the_module} PUBLIC ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK}
  109. INTERFACE ${OPENCV_MODULE_${the_module}_DEPS_TO_LINK}
  110. )
  111. ocv_target_link_libraries(${the_module} PUBLIC ${OPENCV_MODULE_${the_module}_DEPS_EXT}
  112. INTERFACE ${OPENCV_MODULE_${the_module}_DEPS_EXT}
  113. )
  114. ocv_target_link_libraries(${the_module} PRIVATE ${OPENCV_LINKER_LIBS} ${OPENCV_HAL_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
  115. ocv_target_link_libraries(${the_module} JlCxx::cxxwrap_julia)
  116. ocv_target_link_libraries(${the_module} JlCxx::cxxwrap_julia_stl)
  117. # targets# opencv_julia_sources --> opencv_julia
  118. add_custom_command(TARGET ${the_module}
  119. POST_BUILD
  120. COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/package/OpenCV ${CMAKE_BINARY_DIR}/OpenCV
  121. COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/gen/autogen_jl/ ${CMAKE_BINARY_DIR}/OpenCV/src
  122. COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${the_module}> ${CMAKE_BINARY_DIR}/OpenCV/src/lib/libopencv_julia
  123. COMMENT "Copying over julia package"
  124. )
  125. if (BUILD_TESTS)
  126. add_subdirectory(test)
  127. endif()