2014-06-30 04:45:24 +08:00
|
|
|
# This file is included from a subdirectory
|
|
|
|
set(PYTHON_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../")
|
|
|
|
|
2017-12-10 02:54:52 +08:00
|
|
|
ocv_add_module(${MODULE_NAME} BINDINGS PRIVATE_REQUIRED opencv_python_bindings_generator)
|
2014-07-31 13:11:30 +08:00
|
|
|
|
2018-02-09 22:10:02 +08:00
|
|
|
include_directories(SYSTEM
|
2016-07-07 00:53:32 +08:00
|
|
|
"${${PYTHON}_INCLUDE_PATH}"
|
|
|
|
${${PYTHON}_NUMPY_INCLUDE_DIRS}
|
2018-02-09 22:10:02 +08:00
|
|
|
)
|
|
|
|
ocv_module_include_directories(
|
2014-06-30 04:45:24 +08:00
|
|
|
"${PYTHON_SOURCE_DIR}/src2"
|
2017-12-10 02:54:52 +08:00
|
|
|
"${OPENCV_PYTHON_BINDINGS_DIR}"
|
2017-09-05 23:28:26 +08:00
|
|
|
)
|
|
|
|
|
2017-12-10 02:54:52 +08:00
|
|
|
# try to use dynamic symbols linking with libpython.so
|
|
|
|
set(OPENCV_FORCE_PYTHON_LIBS OFF CACHE BOOL "")
|
|
|
|
string(REPLACE "-Wl,--no-undefined" "" CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
|
|
|
|
if(NOT WIN32 AND NOT APPLE AND NOT OPENCV_PYTHON_SKIP_LINKER_EXCLUDE_LIBS)
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--exclude-libs=ALL")
|
|
|
|
endif()
|
2016-08-07 00:46:17 +08:00
|
|
|
|
|
|
|
ocv_add_library(${the_module} MODULE ${PYTHON_SOURCE_DIR}/src2/cv2.cpp ${cv2_generated_hdrs} ${opencv_userdef_hdrs} ${cv2_custom_hdr})
|
2017-12-10 02:54:52 +08:00
|
|
|
add_dependencies(${the_module} gen_opencv_python_source)
|
2014-06-30 04:45:24 +08:00
|
|
|
|
2016-07-07 00:53:32 +08:00
|
|
|
if(APPLE)
|
|
|
|
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
|
|
|
|
elseif(WIN32 OR OPENCV_FORCE_PYTHON_LIBS)
|
|
|
|
if(${PYTHON}_DEBUG_LIBRARIES AND NOT ${PYTHON}_LIBRARIES MATCHES "optimized.*debug")
|
2017-08-17 05:23:06 +08:00
|
|
|
ocv_target_link_libraries(${the_module} LINK_PRIVATE debug ${${PYTHON}_DEBUG_LIBRARIES} optimized ${${PYTHON}_LIBRARIES})
|
2015-03-24 14:36:46 +08:00
|
|
|
else()
|
2017-08-17 05:23:06 +08:00
|
|
|
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${${PYTHON}_LIBRARIES})
|
2015-03-24 14:36:46 +08:00
|
|
|
endif()
|
2014-06-30 04:45:24 +08:00
|
|
|
endif()
|
2017-12-10 02:54:52 +08:00
|
|
|
|
|
|
|
set(deps ${OPENCV_MODULE_${the_module}_DEPS})
|
|
|
|
list(REMOVE_ITEM deps opencv_python_bindings_generator) # don't add dummy module to target_link_libraries list
|
|
|
|
ocv_target_link_libraries(${the_module} LINK_PRIVATE ${deps})
|
2014-06-30 04:45:24 +08:00
|
|
|
|
2016-07-07 00:53:32 +08:00
|
|
|
if(DEFINED ${PYTHON}_CVPY_SUFFIX)
|
|
|
|
set(CVPY_SUFFIX "${${PYTHON}_CVPY_SUFFIX}")
|
|
|
|
else()
|
|
|
|
execute_process(COMMAND ${${PYTHON}_EXECUTABLE} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('SO'))"
|
|
|
|
RESULT_VARIABLE PYTHON_CVPY_PROCESS
|
|
|
|
OUTPUT_VARIABLE CVPY_SUFFIX
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
if(NOT PYTHON_CVPY_PROCESS EQUAL 0)
|
|
|
|
set(CVPY_SUFFIX ".so")
|
|
|
|
endif()
|
|
|
|
endif()
|
2014-06-30 04:45:24 +08:00
|
|
|
|
|
|
|
set_target_properties(${the_module} PROPERTIES
|
2014-08-07 12:21:42 +08:00
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}/${MODULE_INSTALL_SUBDIR}"
|
2016-02-26 22:08:07 +08:00
|
|
|
ARCHIVE_OUTPUT_NAME ${the_module} # prevent name conflict for python2/3 outputs
|
2017-01-25 19:20:57 +08:00
|
|
|
DEFINE_SYMBOL CVAPI_EXPORTS
|
2014-06-30 04:45:24 +08:00
|
|
|
PREFIX ""
|
|
|
|
OUTPUT_NAME cv2
|
|
|
|
SUFFIX ${CVPY_SUFFIX})
|
|
|
|
|
|
|
|
if(ENABLE_SOLUTION_FOLDERS)
|
|
|
|
set_target_properties(${the_module} PROPERTIES FOLDER "bindings")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MSVC)
|
2014-08-07 13:01:11 +08:00
|
|
|
add_definitions(-DCVAPI_EXPORTS)
|
2014-06-30 04:45:24 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MSVC AND NOT ENABLE_NOISY_WARNINGS)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100") #unreferenced formal parameter
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4127") #conditional expression is constant
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4505") #unreferenced local function has been removed
|
|
|
|
string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
endif()
|
|
|
|
|
2016-10-07 23:49:52 +08:00
|
|
|
ocv_warnings_disable(CMAKE_CXX_FLAGS -Woverloaded-virtual -Wunused-private-field)
|
2017-08-22 16:56:55 +08:00
|
|
|
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef) # accurate guard via #pragma doesn't work (C++ preprocessor doesn't handle #pragma)
|
2016-10-07 23:49:52 +08:00
|
|
|
|
2014-06-30 04:45:24 +08:00
|
|
|
if(MSVC AND NOT BUILD_SHARED_LIBS)
|
|
|
|
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
|
|
|
|
endif()
|
|
|
|
|
2016-07-07 00:53:32 +08:00
|
|
|
if(MSVC AND NOT ${PYTHON}_DEBUG_LIBRARIES)
|
2014-06-30 04:45:24 +08:00
|
|
|
set(PYTHON_INSTALL_CONFIGURATIONS CONFIGURATIONS Release)
|
|
|
|
else()
|
|
|
|
set(PYTHON_INSTALL_CONFIGURATIONS "")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
set(PYTHON_INSTALL_ARCHIVE "")
|
|
|
|
else()
|
2016-07-07 00:53:32 +08:00
|
|
|
set(PYTHON_INSTALL_ARCHIVE ARCHIVE DESTINATION ${${PYTHON}_PACKAGES_PATH} COMPONENT python)
|
2014-06-30 04:45:24 +08:00
|
|
|
endif()
|
|
|
|
|
2016-07-07 00:53:32 +08:00
|
|
|
if(NOT INSTALL_CREATE_DISTRIB AND DEFINED ${PYTHON}_PACKAGES_PATH)
|
|
|
|
set(__dst "${${PYTHON}_PACKAGES_PATH}")
|
2016-10-30 04:03:41 +08:00
|
|
|
endif()
|
|
|
|
if(NOT __dst)
|
2016-07-07 00:53:32 +08:00
|
|
|
if(DEFINED ${PYTHON}_VERSION_MAJOR)
|
|
|
|
set(__ver "${${PYTHON}_VERSION_MAJOR}.${${PYTHON}_VERSION_MINOR}")
|
|
|
|
elseif(DEFINED ${PYTHON}_VERSION_STRING)
|
|
|
|
set(__ver "${${PYTHON}_VERSION_STRING}")
|
2014-06-30 04:45:24 +08:00
|
|
|
else()
|
|
|
|
set(__ver "unknown")
|
|
|
|
endif()
|
2016-10-30 04:03:41 +08:00
|
|
|
if(INSTALL_CREATE_DISTRIB)
|
|
|
|
set(__dst "python/${__ver}/${OpenCV_ARCH}")
|
|
|
|
else()
|
|
|
|
set(__dst "python/${__ver}")
|
|
|
|
endif()
|
2014-06-30 04:45:24 +08:00
|
|
|
endif()
|
|
|
|
|
2016-10-30 04:03:41 +08:00
|
|
|
install(TARGETS ${the_module}
|
|
|
|
${PYTHON_INSTALL_CONFIGURATIONS}
|
|
|
|
RUNTIME DESTINATION "${__dst}" COMPONENT python
|
|
|
|
LIBRARY DESTINATION "${__dst}" COMPONENT python
|
|
|
|
${PYTHON_INSTALL_ARCHIVE}
|
|
|
|
)
|
|
|
|
|
2014-06-30 04:45:24 +08:00
|
|
|
unset(PYTHON_SRC_DIR)
|
|
|
|
unset(PYTHON_CVPY_PROCESS)
|
|
|
|
unset(CVPY_SUFFIX)
|
|
|
|
unset(PYTHON_INSTALL_CONFIGURATIONS)
|
|
|
|
unset(PYTHON_INSTALL_ARCHIVE)
|