|
|
|
@ -1,16 +1,18 @@ |
|
|
|
|
set(MODULE_NAME "objc") |
|
|
|
|
set(MODULE_NAME "objc_bindings_generator") |
|
|
|
|
set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE) |
|
|
|
|
ocv_add_module(${MODULE_NAME} INTERNAL opencv_core opencv_imgproc) |
|
|
|
|
|
|
|
|
|
set(OPENCV_OBJC_SIGNATURES_FILE "${CMAKE_CURRENT_BINARY_DIR}/opencv_objc_signatures.json" CACHE INTERNAL "") |
|
|
|
|
#set(OPENCV_OBJC_SIGNATURES_FILE "${CMAKE_CURRENT_BINARY_DIR}/opencv_objc_signatures.json" CACHE INTERNAL "") |
|
|
|
|
set(OPENCV_OBJC_BINDINGS_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "") |
|
|
|
|
|
|
|
|
|
file(REMOVE_RECURSE "${OPENCV_OBJC_BINDINGS_DIR}/gen") |
|
|
|
|
file(REMOVE "${OPENCV_DEPHELPER}/gen_opencv_objc_source") # force re-run after CMake |
|
|
|
|
file(REMOVE_RECURSE "${OPENCV_OBJC_BINDINGS_DIR}/osx") |
|
|
|
|
file(REMOVE "${OPENCV_DEPHELPER}/gen_opencv_objc_source_osx") # force re-run after CMake |
|
|
|
|
file(REMOVE_RECURSE "${OPENCV_OBJC_BINDINGS_DIR}/ios") |
|
|
|
|
file(REMOVE "${OPENCV_DEPHELPER}/gen_opencv_objc_source_ios") # force re-run after CMake |
|
|
|
|
|
|
|
|
|
# This file is included from a subdirectory |
|
|
|
|
set(OBJC_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..") |
|
|
|
|
include(${OBJC_SOURCE_DIR}/common.cmake) |
|
|
|
|
include(${OBJC_SOURCE_DIR}/common.cmake) # fill OPENCV_OBJC_MODULES |
|
|
|
|
|
|
|
|
|
# common files |
|
|
|
|
file(GLOB_RECURSE deps "${CMAKE_CURRENT_SOURCE_DIR}/templates/*") |
|
|
|
@ -30,15 +32,21 @@ foreach(m ${OPENCV_OBJC_MODULES}) |
|
|
|
|
set(__modules_config "${__modules_config} { \"name\": \"${m_}\", \"location\": \"${rel_path}\" }") |
|
|
|
|
endforeach(m) |
|
|
|
|
|
|
|
|
|
if(HAVE_opencv_objc) |
|
|
|
|
set(__objc_build_dir "\"objc_build_dir\": \"${CMAKE_CURRENT_BINARY_DIR}/../objc\",") |
|
|
|
|
endif() |
|
|
|
|
|
|
|
|
|
set(CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/gen_objc.json") |
|
|
|
|
set(__config_str |
|
|
|
|
"{ |
|
|
|
|
\"rootdir\": \"${OpenCV_SOURCE_DIR}\", |
|
|
|
|
${__objc_build_dir} |
|
|
|
|
\"modules\": [ |
|
|
|
|
${__modules_config} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
") |
|
|
|
|
#TODO: ocv_update_file("${CONFIG_FILE}" "${__config_str}" ON_CHANGE_REMOVE "${OPENCV_DEPHELPER}/gen_opencv_objc_source") |
|
|
|
|
if(EXISTS "${CONFIG_FILE}") |
|
|
|
|
file(READ "${CONFIG_FILE}" __content) |
|
|
|
|
else() |
|
|
|
@ -52,33 +60,66 @@ unset(__config_str) |
|
|
|
|
|
|
|
|
|
set(objc_generated_files |
|
|
|
|
# "${OPENCV_OBJC_SIGNATURES_FILE}" |
|
|
|
|
"${OPENCV_DEPHELPER}/gen_opencv_objc_source" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
string(REPLACE "opencv_" "" MODULES "${OPENCV_OBJC_MODULES}") |
|
|
|
|
|
|
|
|
|
if(IOS) |
|
|
|
|
set(TARGET "ios") |
|
|
|
|
else() |
|
|
|
|
set(TARGET "osx") |
|
|
|
|
if(NOT DEFINED OPENCV_OBJC_TARGET AND APPLE_FRAMEWORK) |
|
|
|
|
if(IOS) |
|
|
|
|
set(OPENCV_OBJC_TARGET "ios") |
|
|
|
|
else() |
|
|
|
|
set(OPENCV_OBJC_TARGET "osx") |
|
|
|
|
endif() |
|
|
|
|
endif() |
|
|
|
|
|
|
|
|
|
add_custom_command( |
|
|
|
|
OUTPUT ${objc_generated_files} |
|
|
|
|
COMMAND ${PYTHON_DEFAULT_EXECUTABLE} "${OBJC_SOURCE_DIR}/generator/gen_objc.py" -p "${OBJC_SOURCE_DIR}/../python/src2/gen2.py" -c "${CONFIG_FILE}" -t "${TARGET}" -f "${FRAMEWORK_NAME}" |
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch "${OPENCV_DEPHELPER}/gen_opencv_objc_source" |
|
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
|
|
|
|
DEPENDS "${OBJC_SOURCE_DIR}/generator/gen_objc.py" |
|
|
|
|
"${OBJC_SOURCE_DIR}/../python/src2/gen2.py" |
|
|
|
|
"${OBJC_SOURCE_DIR}/../python/src2/hdr_parser.py" |
|
|
|
|
# don't, result of file(WRITE): "${CMAKE_CURRENT_BINARY_DIR}/gen_objc.json" |
|
|
|
|
${deps} |
|
|
|
|
# not allowed (file(WRITE) result): "${CONFIG_FILE}" |
|
|
|
|
COMMENT "Generate files for Objective-C bindings" |
|
|
|
|
) |
|
|
|
|
if(NOT DEFINED OPENCV_OBJC_FRAMEWORK_NAME) |
|
|
|
|
if(DEFINED FRAMEWORK_NAME) |
|
|
|
|
set(OPENCV_OBJC_FRAMEWORK_NAME "${FRAMEWORK_NAME}") |
|
|
|
|
else() |
|
|
|
|
set(OPENCV_OBJC_FRAMEWORK_NAME "opencv2") |
|
|
|
|
endif() |
|
|
|
|
endif() |
|
|
|
|
|
|
|
|
|
set(objc_generated_targets "") |
|
|
|
|
|
|
|
|
|
macro(ocv_add_objc_generated_target TARGET) |
|
|
|
|
set(objc_${TARGET}_generated_output_dependecy "${OPENCV_DEPHELPER}/gen_opencv_objc_source_${TARGET}") |
|
|
|
|
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}") |
|
|
|
|
add_custom_command( |
|
|
|
|
OUTPUT ${objc_generated_files} "${objc_${TARGET}_generated_output_dependecy}" |
|
|
|
|
COMMAND ${PYTHON_DEFAULT_EXECUTABLE} "${OBJC_SOURCE_DIR}/generator/gen_objc.py" |
|
|
|
|
-p "${OBJC_SOURCE_DIR}/../python/src2/gen2.py" |
|
|
|
|
-c "${CONFIG_FILE}" |
|
|
|
|
-t "${TARGET}" |
|
|
|
|
-f "${OPENCV_OBJC_FRAMEWORK_NAME}" |
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch "${objc_${TARGET}_generated_output_dependecy}" |
|
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}" |
|
|
|
|
DEPENDS "${OpenCV_SOURCE_DIR}/modules/objc/generator/gen_objc.py" |
|
|
|
|
"${OpenCV_SOURCE_DIR}/modules/python/src2/gen2.py" |
|
|
|
|
"${OpenCV_SOURCE_DIR}/modules/python/src2/hdr_parser.py" |
|
|
|
|
# don't, result of file(WRITE): "${CMAKE_CURRENT_BINARY_DIR}/gen_objc.json" |
|
|
|
|
${deps} |
|
|
|
|
# not allowed (file(WRITE) result): "${CONFIG_FILE}" |
|
|
|
|
COMMENT "Generate files for Objective-C bindings (${TARGET})" |
|
|
|
|
) |
|
|
|
|
add_custom_target(gen_opencv_objc_source_${TARGET} |
|
|
|
|
# excluded from all: ALL |
|
|
|
|
DEPENDS ${objc_generated_files} ${objc_${TARGET}_generated_output_dependecy} |
|
|
|
|
SOURCES "${OBJC_SOURCE_DIR}/generator/gen_objc.py" |
|
|
|
|
"${OBJC_SOURCE_DIR}/generator/templates/cmakelists.template" |
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/gen_objc.json" |
|
|
|
|
) |
|
|
|
|
list(APPEND objc_generated_targets gen_opencv_objc_source_${TARGET}) |
|
|
|
|
endmacro() |
|
|
|
|
|
|
|
|
|
if(OPENCV_OBJC_TARGET) |
|
|
|
|
ocv_add_objc_generated_target(${OPENCV_OBJC_TARGET}) |
|
|
|
|
else() |
|
|
|
|
ocv_add_objc_generated_target(osx) |
|
|
|
|
ocv_add_objc_generated_target(ios) |
|
|
|
|
endif() |
|
|
|
|
|
|
|
|
|
add_custom_target(gen_opencv_objc_source ALL DEPENDS ${objc_generated_files} |
|
|
|
|
SOURCES "${OBJC_SOURCE_DIR}/generator/gen_objc.py" |
|
|
|
|
"${OBJC_SOURCE_DIR}/generator/templates/cmakelists.template" |
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/gen_objc.json" |
|
|
|
|
add_custom_target(gen_opencv_objc_source |
|
|
|
|
# excluded from all: ALL |
|
|
|
|
DEPENDS ${objc_generated_targets} |
|
|
|
|
) |
|
|
|
|