From f3dde79ed6f5e17f16f4e2ad9669841e0dd6887c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sun, 7 Jan 2018 18:16:38 +0000 Subject: [PATCH] cmake: allow BUILD_FAT_JAVA_LIB for non-Android targets too --- CMakeLists.txt | 4 ++-- cmake/OpenCVModule.cmake | 5 ++++- cmake/OpenCVUtils.cmake | 3 +++ modules/java/CMakeLists.txt | 7 +++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4464441b76..e90f7db03c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,7 +279,7 @@ OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" OCV_OPTION(BUILD_WITH_DEBUG_INFO "Include debug info into debug libs (not MSCV only)" ON ) OCV_OPTION(BUILD_WITH_STATIC_CRT "Enables use of statically linked CRT for statically linked OpenCV" ON IF MSVC ) OCV_OPTION(BUILD_WITH_DYNAMIC_IPP "Enables dynamic linking of IPP (only for standalone IPP)" OFF ) -OCV_OPTION(BUILD_FAT_JAVA_LIB "Create fat java wrapper containing the whole OpenCV library" ON IF NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX ) +OCV_OPTION(BUILD_FAT_JAVA_LIB "Create Java wrapper exporting all functions of OpenCV library (requires static build of OpenCV modules)" ANDROID IF NOT BUILD_SHARED_LIBS) OCV_OPTION(BUILD_ANDROID_SERVICE "Build OpenCV Manager for Google Play" OFF IF ANDROID ) OCV_OPTION(BUILD_CUDA_STUBS "Build CUDA modules stubs when no CUDA SDK" OFF IF (NOT APPLE_FRAMEWORK) ) OCV_OPTION(BUILD_JAVA "Enable Java support" (ANDROID OR NOT CMAKE_CROSSCOMPILING) IF (ANDROID OR (NOT APPLE_FRAMEWORK AND NOT WINRT)) ) @@ -1401,7 +1401,7 @@ endif() # ========================== java ========================== if(BUILD_JAVA OR BUILD_opencv_java) status("") - status(" Java:") + status(" Java:" BUILD_FAT_JAVA_LIB THEN "export all functions" ELSE "") status(" ant:" ANT_EXECUTABLE THEN "${ANT_EXECUTABLE} (ver ${ANT_VERSION})" ELSE NO) if(NOT ANDROID) status(" JNI:" JNI_INCLUDE_DIRS THEN "${JNI_INCLUDE_DIRS}" ELSE NO) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index a84bbff453..f89e4cfd84 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -886,7 +886,10 @@ macro(_ocv_create_module) DEFINE_SYMBOL CVAPI_EXPORTS ) - if(ANDROID AND BUILD_FAT_JAVA_LIB) + if(BUILD_FAT_JAVA_LIB) # force exports from static modules too + if(BUILD_SHARED_LIBS) + message(FATAL_ERROR "Assertion failed: BUILD_SHARED_LIBS=OFF must be off if BUILD_FAT_JAVA_LIB=ON") + endif() target_compile_definitions(${the_module} PRIVATE CVAPI_EXPORTS) endif() diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 47e37a3b48..60662536f6 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -452,6 +452,9 @@ macro(OCV_OPTION variable description value) option(${variable} "${description}" ${__value}) endif() else() + if(DEFINED ${variable}) + # TODO: message(WARNING "Option will be ignored: ${variable} (=${${variable}})") + endif() unset(${variable} CACHE) endif() unset(__condition) diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index d44b195238..76bfe6235a 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -442,8 +442,10 @@ if(BUILD_FAT_JAVA_LIB) foreach(_dep ${__deps}) ocv_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-force_load "${_dep}") endforeach() - else() + elseif(((CMAKE_COMPILER_IS_GNUCXX OR UNIX) OR (OPENCV_FORCE_FAT_JAVA_LIB_LD_RULES)) AND (NOT OPENCV_SKIP_FAT_JAVA_LIB_LD_RULES)) ocv_target_link_libraries(${the_module} LINK_PRIVATE -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive) + else() + ocv_target_link_libraries(${the_module} LINK_PRIVATE ${__deps}) endif() ocv_target_link_libraries(${the_module} LINK_PRIVATE ${__extradeps} ${OPENCV_LINKER_LIBS}) else() @@ -480,8 +482,9 @@ if(ENABLE_SOLUTION_FOLDERS) set_target_properties(${the_module} PROPERTIES FOLDER "bindings") endif() -if(ANDROID) +if(BUILD_FAT_JAVA_LIB) ocv_install_target(${the_module} OPTIONAL EXPORT OpenCVModules + RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT java LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT java ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT java) else()