cmake: CMP0026 NEW

pull/9415/head
Alexander Alekhin 7 years ago
parent e63d3dd25f
commit 87a98e4562
  1. 5
      CMakeLists.txt
  2. 3
      cmake/OpenCVDetectAndroidSDK.cmake
  3. 12
      cmake/OpenCVGenABI.cmake
  4. 25
      cmake/OpenCVGenAndroidMK.cmake
  5. 95
      cmake/OpenCVGenPkgconfig.cmake
  6. 70
      cmake/OpenCVUtils.cmake
  7. 2
      cmake/templates/opencv_abi.xml.in
  8. 3
      modules/java/CMakeLists.txt
  9. 5
      modules/java/android_test/CMakeLists.txt

@ -78,8 +78,7 @@ if(WINRT)
endif()
if(POLICY CMP0026)
# silence cmake 3.0+ warnings about reading LOCATION attribute
cmake_policy(SET CMP0026 OLD)
cmake_policy(SET CMP0026 NEW)
endif()
if(POLICY CMP0042)
@ -1368,7 +1367,7 @@ if(HAVE_OPENCL)
set(__libs "")
foreach(l ${OPENCL_LIBRARIES})
if(TARGET ${l})
get_target_property(p ${l} LOCATION)
get_target_property(p ${l} IMPORTED_LOCATION)
if(p MATCHES NOTFOUND)
list(APPEND __libs "${l}")
else()

@ -297,9 +297,8 @@ macro(add_android_project target path)
LIBRARY_OUTPUT_DIRECTORY "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}"
)
get_target_property(android_proj_jni_location "${JNI_LIB_NAME}" LOCATION)
if (NOT (CMAKE_BUILD_TYPE MATCHES "debug"))
add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${android_proj_jni_location}")
add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$<TARGET_FILE:${JNI_LIB_NAME}>")
endif()
endif()
endif()

@ -26,7 +26,9 @@ set(OPENCV_ABI_SKIP_HEADERS "")
set(OPENCV_ABI_SKIP_LIBRARIES "")
foreach(mod ${OPENCV_MODULES_BUILD})
string(REGEX REPLACE "^opencv_" "" mod "${mod}")
if(NOT "${OPENCV_MODULE_opencv_${mod}_LOCATION}" STREQUAL "${OpenCV_SOURCE_DIR}/modules/${mod}")
if(NOT OPENCV_MODULE_opencv_${mod}_CLASS STREQUAL "PUBLIC"
OR NOT "${OPENCV_MODULE_opencv_${mod}_LOCATION}" STREQUAL "${OpenCV_SOURCE_DIR}/modules/${mod}" # opencv_contrib
)
# headers
foreach(h ${OPENCV_MODULE_opencv_${mod}_HEADERS})
file(RELATIVE_PATH h "${OPENCV_MODULE_opencv_${mod}_LOCATION}/include" "${h}")
@ -34,10 +36,7 @@ foreach(mod ${OPENCV_MODULES_BUILD})
endforeach()
# libraries
if(TARGET opencv_${mod}) # opencv_world
set(lib_name "")
get_target_property(lib_name opencv_${mod} LOCATION)
get_filename_component(lib_name "${lib_name}" NAME)
list(APPEND OPENCV_ABI_SKIP_LIBRARIES "${lib_name}")
list(APPEND OPENCV_ABI_SKIP_LIBRARIES "\$<TARGET_FILE_NAME:opencv_${mod}>")
endif()
endif()
endforeach()
@ -48,4 +47,5 @@ string(REPLACE ";" "\n " OPENCV_ABI_SKIP_LIBRARIES "${OPENCV_ABI_SKIP_LIBRARI
set(OPENCV_ABI_GCC_OPTIONS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -DOPENCV_ABI_CHECK=1")
string(REGEX REPLACE "([^ ]) +([^ ])" "\\1\\n \\2" OPENCV_ABI_GCC_OPTIONS "${OPENCV_ABI_GCC_OPTIONS}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_abi.xml.in" "${path1}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_abi.xml.in" "${path1}.base")
file(GENERATE OUTPUT "${path1}" INPUT "${path1}.base")

@ -20,12 +20,29 @@ if(ANDROID)
endif()
# build the list of opencv libs and dependencies for all modules
ocv_get_all_libs(OPENCV_MODULES_CONFIGMAKE OPENCV_EXTRA_COMPONENTS_CONFIGMAKE OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE)
ocv_get_all_libs(OPENCV_MODULES OPENCV_EXTRA_COMPONENTS OPENCV_3RDPARTY_COMPONENTS)
# list -> string
string(REPLACE ";" " " OPENCV_MODULES_CONFIGMAKE "${OPENCV_MODULES_CONFIGMAKE}")
string(REPLACE ";" " " OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "${OPENCV_EXTRA_COMPONENTS_CONFIGMAKE}")
string(REPLACE ";" " " OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE "${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}")
foreach(_var OPENCV_MODULES OPENCV_EXTRA_COMPONENTS OPENCV_3RDPARTY_COMPONENTS)
set(var "${_var}_CONFIGMAKE")
set(${var} "")
foreach(lib ${${_var}})
set(lib_name "${lib}")
if(TARGET ${lib})
get_target_property(_output ${lib} IMPORTED_LOCATION)
if(NOT _output)
get_target_property(output_name ${lib} OUTPUT_NAME)
if(output_name)
set(lib_name "${output_name}")
endif()
else()
ocv_get_libname(lib_name "${_output}")
endif()
endif()
set(${var} "${${var}} ${lib_name}")
endforeach()
string(STRIP "${${var}}" ${var})
endforeach()
# replace 'opencv_<module>' -> '<module>''
string(REPLACE "opencv_" "" OPENCV_MODULES_CONFIGMAKE "${OPENCV_MODULES_CONFIGMAKE}")

@ -1,3 +1,7 @@
if(MSVC OR IOS)
return()
endif()
# --------------------------------------------------------------------------------------------
# according to man pkg-config
# The package name specified on the pkg-config command line is defined to
@ -12,11 +16,11 @@
macro(fix_prefix lst isown)
set(_lst)
foreach(item ${${lst}})
if(TARGET ${item})
get_target_property(item "${item}" LOCATION_${CMAKE_BUILD_TYPE})
if("${isown}")
get_filename_component(item "${item}" NAME_WE)
string(REGEX REPLACE "^lib(.*)" "\\1" item "${item}")
if(DEFINED TARGET_LOCATION_${item})
set(item "${TARGET_LOCATION_${item}}")
if(${isown})
get_filename_component(item "${item}" NAME)
ocv_get_libname(item "${item}")
endif()
endif()
if(item MATCHES "^-l")
@ -25,8 +29,8 @@ macro(fix_prefix lst isown)
list(APPEND _lst "${item}")
elseif(item MATCHES "[\\/]")
get_filename_component(libdir "${item}" PATH)
get_filename_component(libname "${item}" NAME_WE)
string(REGEX REPLACE "^lib(.*)" "\\1" libname "${libname}")
get_filename_component(_libname "${item}" NAME)
ocv_get_libname(libname "${_libname}")
list(APPEND _lst "-L${libdir}" "-l${libname}")
else()
list(APPEND _lst "-l${item}")
@ -36,6 +40,14 @@ macro(fix_prefix lst isown)
unset(_lst)
endmacro()
if(NOT DEFINED CMAKE_HELPER_SCRIPT)
if(INSTALL_TO_MANGLED_PATHS)
set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc")
else()
set(OPENCV_PC_FILE_NAME opencv.pc)
endif()
# build the list of opencv libs and dependencies for all modules
ocv_get_all_libs(_modules _extra _3rdparty)
@ -56,9 +68,61 @@ if(_modules MATCHES "opencv_contrib_world")
list(INSERT _modules 0 "opencv_contrib_world")
endif()
fix_prefix(_modules TRUE)
fix_prefix(_extra FALSE)
fix_prefix(_3rdparty TRUE)
set(HELPER_SCRIPT "")
ocv_cmake_script_append_var(HELPER_SCRIPT
BUILD_SHARED_LIBS
CMAKE_BINARY_DIR
CMAKE_INSTALL_PREFIX
OpenCV_SOURCE_DIR
OPENCV_PC_FILE_NAME
OPENCV_VERSION_PLAIN
OPENCV_LIB_INSTALL_PATH
OPENCV_INCLUDE_INSTALL_PATH
OPENCV_3P_LIB_INSTALL_PATH
_modules
_extra
_3rdparty
)
foreach(item ${_modules} ${_extra} ${_3rdparty})
if(TARGET ${item})
set(HELPER_SCRIPT "${HELPER_SCRIPT}
set(TARGET_LOCATION_${item} \"$<TARGET_FILE:${item}>\")
")
endif()
endforeach()
set(CMAKE_HELPER_SCRIPT "${CMAKE_BINARY_DIR}/OpenCVGenPkgConfig.info.cmake")
file(GENERATE OUTPUT "${CMAKE_HELPER_SCRIPT}" CONTENT "${HELPER_SCRIPT}")
add_custom_target(developer_scripts)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}"
COMMAND ${CMAKE_COMMAND} "-DCMAKE_HELPER_SCRIPT=${CMAKE_HELPER_SCRIPT}" -P "${OpenCV_SOURCE_DIR}/cmake/OpenCVGenPkgconfig.cmake"
DEPENDS "${CMAKE_BINARY_DIR}/OpenCVGenPkgConfig.info.cmake"
"${OpenCV_SOURCE_DIR}/cmake/OpenCVGenPkgconfig.cmake"
COMMENT "Generate ${OPENCV_PC_FILE_NAME}"
)
add_custom_target(gen-pkgconfig ALL SOURCES "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}")
add_dependencies(developer_scripts gen-pkgconfig)
if(UNIX AND NOT ANDROID)
install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev)
endif()
# =============================================================================
else() # DEFINED CMAKE_HELPER_SCRIPT
cmake_minimum_required(VERSION 2.8.12.2)
cmake_policy(SET CMP0012 NEW)
include("${CMAKE_HELPER_SCRIPT}")
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVUtils.cmake")
fix_prefix(_modules 1)
fix_prefix(_extra 0)
fix_prefix(_3rdparty 1)
ocv_list_unique(_modules)
ocv_list_unique(_extra)
@ -68,7 +132,7 @@ set(OPENCV_PC_LIBS
"-L\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}"
"${_modules}"
)
if (BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
set(OPENCV_PC_LIBS_PRIVATE "${_extra}")
else()
set(OPENCV_PC_LIBS_PRIVATE
@ -86,15 +150,8 @@ set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}")
set(includedir "\${prefix}/${OPENCV_INCLUDE_INSTALL_PATH}")
if(INSTALL_TO_MANGLED_PATHS)
set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc")
else()
set(OPENCV_PC_FILE_NAME opencv.pc)
endif()
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.in"
"${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}"
@ONLY)
if(UNIX AND NOT ANDROID)
install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev)
endif()
endif() # DEFINED CMAKE_HELPER_SCRIPT

@ -517,6 +517,7 @@ macro(CHECK_MODULE module_name define cv_module)
endif()
endmacro()
if(NOT DEFINED CMAKE_ARGC) # Guard CMake standalone invocations
set(OPENCV_BUILD_INFO_FILE "${CMAKE_BINARY_DIR}/version_string.tmp")
file(REMOVE "${OPENCV_BUILD_INFO_FILE}")
@ -597,6 +598,7 @@ function(status text)
endif()
endfunction()
endif() # NOT DEFINED CMAKE_ARGC
# remove all matching elements from the list
macro(ocv_list_filterout lst regex)
@ -689,8 +691,8 @@ endmacro()
function(ocv_convert_to_lib_name var)
set(tmp "")
foreach(path ${ARGN})
get_filename_component(tmp_name "${path}" NAME_WE)
string(REGEX REPLACE "^lib" "" tmp_name "${tmp_name}")
get_filename_component(tmp_name "${path}" NAME)
ocv_get_libname(tmp_name "${tmp_name}")
list(APPEND tmp "${tmp_name}")
endforeach()
set(${var} ${tmp} PARENT_SCOPE)
@ -899,32 +901,42 @@ function(ocv_source_group group)
endif()
endfunction()
macro(__ocv_push_target_link_libraries)
if(NOT TARGET ${target})
if(NOT DEFINED OPENCV_MODULE_${target}_LOCATION)
message(FATAL_ERROR "ocv_target_link_libraries: invalid target: '${target}'")
endif()
set(OPENCV_MODULE_${target}_LINK_DEPS ${OPENCV_MODULE_${target}_LINK_DEPS} ${ARGN} CACHE INTERNAL "" FORCE)
else()
target_link_libraries(${target} ${ARGN})
endif()
endmacro()
function(ocv_target_link_libraries target)
_ocv_fix_target(target)
set(LINK_DEPS ${ARGN})
# process world
_ocv_fix_target(target)
set(LINK_MODE "LINK_PRIVATE")
set(LINK_PENDING "")
foreach(dep ${LINK_DEPS})
if(" ${dep}" STREQUAL " ${target}")
# prevent "link to itself" warning (world problem)
elseif(" ${dep}" STREQUAL " LINK_PRIVATE" OR " ${dep}" STREQUAL "LINK_PUBLIC")
if(NOT LINK_PENDING STREQUAL "")
__ocv_push_target_link_libraries(${LINK_MODE} ${LINK_PENDING})
set(LINK_PENDING "")
set(LINK_MODE "${dep}")
endif()
else()
if(BUILD_opencv_world)
foreach(m ${OPENCV_MODULES_BUILD})
if(OPENCV_MODULE_${m}_IS_PART_OF_WORLD)
if(";${LINK_DEPS};" MATCHES ";${m};")
list(REMOVE_ITEM LINK_DEPS ${m})
if(NOT (";${LINK_DEPS};" MATCHES ";opencv_world;"))
list(APPEND LINK_DEPS opencv_world)
if(OPENCV_MODULE_${dep}_IS_PART_OF_WORLD)
set(dep opencv_world)
endif()
endif()
list(APPEND LINK_PENDING "${dep}")
endif()
endforeach()
endif()
if(";${LINK_DEPS};" MATCHES ";${target};")
list(REMOVE_ITEM LINK_DEPS "${target}") # prevent "link to itself" warning (world problem)
endif()
if(NOT TARGET ${target})
if(NOT DEFINED OPENCV_MODULE_${target}_LOCATION)
message(FATAL_ERROR "ocv_target_link_libraries: invalid target: '${target}'")
endif()
set(OPENCV_MODULE_${target}_LINK_DEPS ${OPENCV_MODULE_${target}_LINK_DEPS} ${LINK_DEPS} CACHE INTERNAL "" FORCE)
else()
target_link_libraries(${target} ${LINK_DEPS})
if(NOT LINK_PENDING STREQUAL "")
__ocv_push_target_link_libraries(${LINK_MODE} ${LINK_PENDING})
endif()
endfunction()
@ -1037,6 +1049,12 @@ macro(ocv_get_all_libs _modules _extra _3rdparty)
endforeach()
foreach (dep ${deps} ${OPENCV_LINKER_LIBS})
if (NOT DEFINED OPENCV_MODULE_${dep}_LOCATION)
if(dep MATCHES "^\\$<LINK_ONLY:([^>]+)>$")
set(dep "${CMAKE_MATCH_1}")
endif()
if(dep MATCHES "^\\$<")
message(WARNING "Unexpected CMake generator expression: ${dep}")
endif()
if (TARGET ${dep})
get_target_property(_type ${dep} TYPE)
if(_type STREQUAL "STATIC_LIBRARY" AND BUILD_SHARED_LIBS)
@ -1055,7 +1073,7 @@ macro(ocv_get_all_libs _modules _extra _3rdparty)
string(FIND "${_output}" "${CMAKE_BINARY_DIR}" _POS)
if (_POS EQUAL 0)
ocv_get_libname(_libname "${_output_name}")
list(INSERT ${_3rdparty} 0 ${_libname})
list(INSERT ${_3rdparty} 0 ${dep})
else()
if(_output)
list(INSERT ${_extra} 0 ${_output})
@ -1175,3 +1193,11 @@ macro(ocv_generate_vs_version_file DESTINATION)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/vs_version.rc.in" "${DESTINATION}" @ONLY)
endmacro()
macro(ocv_cmake_script_append_var content_var)
foreach(var_name ${ARGN})
set(${content_var} "${${content_var}}
set(${var_name} \"${${var_name}}\")
")
endforeach()
endmacro()

@ -29,8 +29,6 @@
opencv2/flann/hdf5.h
opencv2/imgcodecs/ios.h
opencv2/videoio/cap_ios.h
opencv2/ts.hpp
opencv2/ts/*
opencv2/xobjdetect/private.hpp
@OPENCV_ABI_SKIP_HEADERS@
</skip_headers>

@ -460,10 +460,9 @@ if(ANDROID)
# force strip library after the build command
# because samples and tests will make a copy of the library before install
get_target_property(__opencv_java_location ${the_module} LOCATION)
# Turn off stripping in debug build
if ( NOT (CMAKE_BUILD_TYPE MATCHES "Debug"))
add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${__opencv_java_location}")
add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$<TARGET_FILE:${the_module}>")
endif()
endif()

@ -43,13 +43,10 @@ add_custom_command(
list(APPEND opencv_test_java_file_deps ${android_proj_target_files})
get_target_property(java_location opencv_java LOCATION)
get_filename_component(java_name "${java_location}" NAME)
# build java part
add_custom_command(
OUTPUT "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${java_location}" "${opencv_test_java_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${java_name}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:opencv_java>" "${opencv_test_java_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/$<TARGET_FILE_NAME:opencv_java>"
COMMAND ${ANT_EXECUTABLE} -q -noinput -k debug -Djava.target=1.6 -Djava.source=1.6
COMMAND ${CMAKE_COMMAND} -E touch "${opencv_test_java_bin_dir}/bin/OpenCVTest-debug.apk" # needed because ant does not update the timestamp of updated apk
WORKING_DIRECTORY "${opencv_test_java_bin_dir}"

Loading…
Cancel
Save