mirror of
https://github.com/opencv/opencv.git
synced 2025-01-09 21:27:59 +08:00
Merge pull request #26585 from FantasqueX:clean-up-cmake-1
Clean up cmake after upgrading cmake_minimum_required to 3.13
This commit is contained in:
commit
76c2d01938
@ -1091,12 +1091,6 @@ endfunction()
|
||||
##############################################################################
|
||||
|
||||
macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||
|
||||
# If CMake doesn't support separable compilation, complain
|
||||
if(CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS "2.8.10.1")
|
||||
message(SEND_ERROR "CUDA_SEPARABLE_COMPILATION isn't supported for CMake versions less than 2.8.10.1")
|
||||
endif()
|
||||
|
||||
# Set up all the command line flags here, so that they can be overridden on a per target basis.
|
||||
|
||||
set(nvcc_flags "")
|
||||
|
@ -379,7 +379,7 @@ endif()
|
||||
|
||||
# Apply "-Wl,--as-needed" linker flags: https://github.com/opencv/opencv/issues/7001
|
||||
if(NOT OPENCV_SKIP_LINK_AS_NEEDED)
|
||||
if(UNIX AND (NOT APPLE OR NOT CMAKE_VERSION VERSION_LESS "3.2"))
|
||||
if(UNIX)
|
||||
set(_option "-Wl,--as-needed")
|
||||
set(_saved_CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_option}") # requires CMake 3.2+ and CMP0056
|
||||
@ -395,7 +395,7 @@ endif()
|
||||
|
||||
# Apply "-Wl,--no-undefined" linker flags: https://github.com/opencv/opencv/pull/21347
|
||||
if(NOT OPENCV_SKIP_LINK_NO_UNDEFINED)
|
||||
if(UNIX AND ((NOT APPLE OR NOT CMAKE_VERSION VERSION_LESS "3.2") AND NOT CMAKE_SYSTEM_NAME MATCHES "OpenBSD"))
|
||||
if(UNIX AND (NOT CMAKE_SYSTEM_NAME MATCHES "OpenBSD"))
|
||||
set(_option "-Wl,--no-undefined")
|
||||
set(_saved_CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_option}") # requires CMake 3.2+ and CMP0056
|
||||
|
@ -14,9 +14,7 @@ if(CUDA_TOOLKIT_ROOT_DIR)
|
||||
set(CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR})
|
||||
endif()
|
||||
|
||||
if(((NOT CMAKE_VERSION VERSION_LESS "3.9.0") # requires https://gitlab.kitware.com/cmake/cmake/merge_requests/663
|
||||
OR OPENCV_CUDA_FORCE_EXTERNAL_CMAKE_MODULE)
|
||||
AND NOT OPENCV_CUDA_FORCE_BUILTIN_CMAKE_MODULE)
|
||||
if(NOT OPENCV_CUDA_FORCE_BUILTIN_CMAKE_MODULE)
|
||||
ocv_update(CUDA_LINK_LIBRARIES_KEYWORD "PRIVATE")
|
||||
find_host_package(CUDA "${MIN_VER_CUDA}" QUIET)
|
||||
else()
|
||||
|
@ -113,9 +113,7 @@ macro(ocv_initialize_nvidia_device_generations)
|
||||
list(APPEND _generations "Auto")
|
||||
endif()
|
||||
set(CUDA_GENERATION "" CACHE STRING "Build CUDA device code only for specific GPU architecture. Leave empty to build for all architectures (see https://docs.opencv.org/5.x/d2/dbc/cuda_intro.html).")
|
||||
if( CMAKE_VERSION VERSION_GREATER "2.8" )
|
||||
set_property( CACHE CUDA_GENERATION PROPERTY STRINGS "" ${_generations} )
|
||||
endif()
|
||||
set_property( CACHE CUDA_GENERATION PROPERTY STRINGS "" ${_generations} )
|
||||
|
||||
if(CUDA_GENERATION)
|
||||
if(NOT ";${_generations};" MATCHES ";${CUDA_GENERATION};")
|
||||
|
@ -84,15 +84,11 @@ if(NOT ${found})
|
||||
"Consider providing the '${executable}' variable via CMake command line or environment variables\n")
|
||||
endif()
|
||||
ocv_clear_vars(PYTHONINTERP_FOUND PYTHON_EXECUTABLE PYTHON_VERSION_STRING PYTHON_VERSION_MAJOR PYTHON_VERSION_MINOR PYTHON_VERSION_PATCH)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS "3.12")
|
||||
set(__PYTHON_PREFIX Python3)
|
||||
find_host_package(${__PYTHON_PREFIX} "${preferred_version}" COMPONENTS Interpreter)
|
||||
if(${__PYTHON_PREFIX}_EXECUTABLE)
|
||||
set(PYTHON_EXECUTABLE "${${__PYTHON_PREFIX}_EXECUTABLE}")
|
||||
find_host_package(PythonInterp "${preferred_version}") # Populate other variables
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Consider using CMake 3.12+ for better Python support")
|
||||
set(__PYTHON_PREFIX Python3)
|
||||
find_host_package(${__PYTHON_PREFIX} "${preferred_version}" COMPONENTS Interpreter)
|
||||
if(${__PYTHON_PREFIX}_EXECUTABLE)
|
||||
set(PYTHON_EXECUTABLE "${${__PYTHON_PREFIX}_EXECUTABLE}")
|
||||
find_host_package(PythonInterp "${preferred_version}") # Populate other variables
|
||||
endif()
|
||||
endif()
|
||||
if(PYTHONINTERP_FOUND AND "${_python_version_major}" STREQUAL "${PYTHON_VERSION_MAJOR}")
|
||||
|
@ -168,11 +168,7 @@ macro(ipp_detect_version)
|
||||
)
|
||||
AND NOT OPENCV_SKIP_IPP_EXCLUDE_LIBS_CORE
|
||||
)
|
||||
if(CMAKE_VERSION VERSION_LESS "3.13.0")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--exclude-libs,${_filename} ${CMAKE_SHARED_LINKER_FLAGS}")
|
||||
else()
|
||||
target_link_options(ipp${name} INTERFACE "LINKER:--exclude-libs,${_filename}")
|
||||
endif()
|
||||
target_link_options(ipp${name} INTERFACE "LINKER:--exclude-libs,${_filename}")
|
||||
endif()
|
||||
endif()
|
||||
list(APPEND IPP_LIBRARIES ipp${name})
|
||||
|
@ -55,10 +55,7 @@ endif(WITH_CUDA)
|
||||
|
||||
# --- Eigen ---
|
||||
if(WITH_EIGEN AND NOT HAVE_EIGEN)
|
||||
if((OPENCV_FORCE_EIGEN_FIND_PACKAGE_CONFIG
|
||||
OR NOT (CMAKE_VERSION VERSION_LESS "3.0.0") # Eigen3Targets.cmake required CMake 3.0.0+
|
||||
) AND NOT OPENCV_SKIP_EIGEN_FIND_PACKAGE_CONFIG
|
||||
)
|
||||
if(NOT OPENCV_SKIP_EIGEN_FIND_PACKAGE_CONFIG)
|
||||
find_package(Eigen3 CONFIG QUIET) # Ceres 2.0.0 CMake scripts doesn't work with CMake's FindEigen3.cmake module (due to missing EIGEN3_VERSION_STRING)
|
||||
endif()
|
||||
if(NOT Eigen3_FOUND)
|
||||
|
@ -373,7 +373,7 @@ function(ocv_target_include_directories target)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
if(HAVE_CUDA OR CMAKE_VERSION VERSION_LESS 2.8.11)
|
||||
if(HAVE_CUDA)
|
||||
include_directories(${__params})
|
||||
include_directories(SYSTEM ${__system_params})
|
||||
else()
|
||||
@ -915,15 +915,9 @@ if(DEFINED ENV{BUILD_USE_SYMLINKS})
|
||||
endif()
|
||||
OCV_OPTION(BUILD_USE_SYMLINKS "Use symlinks instead of files copying during build (and !!INSTALL!!)" (${__symlink_default}) IF (UNIX OR DEFINED __symlink_default))
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS "3.2")
|
||||
macro(ocv_cmake_byproducts var_name)
|
||||
set(${var_name}) # nothing
|
||||
endmacro()
|
||||
else()
|
||||
macro(ocv_cmake_byproducts var_name)
|
||||
set(${var_name} BYPRODUCTS ${ARGN})
|
||||
endmacro()
|
||||
endif()
|
||||
macro(ocv_cmake_byproducts var_name)
|
||||
set(${var_name} BYPRODUCTS ${ARGN})
|
||||
endmacro()
|
||||
|
||||
set(OPENCV_DEPHELPER "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dephelper" CACHE INTERNAL "")
|
||||
file(MAKE_DIRECTORY ${OPENCV_DEPHELPER})
|
||||
@ -1267,13 +1261,8 @@ function(ocv_install_target)
|
||||
|
||||
# don't move this into global scope of this file: compiler settings (like MSVC variable) are not available during processing
|
||||
if(BUILD_SHARED_LIBS) # no defaults for static libs (modern CMake is required)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.6.0)
|
||||
option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default" ON)
|
||||
option(INSTALL_PDB "Add install PDB rules" ON)
|
||||
elseif(NOT CMAKE_VERSION VERSION_LESS 3.1.0)
|
||||
option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default (not supported)" OFF)
|
||||
option(INSTALL_PDB "Add install PDB rules" OFF)
|
||||
endif()
|
||||
option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default" ON)
|
||||
option(INSTALL_PDB "Add install PDB rules" ON)
|
||||
endif()
|
||||
|
||||
if(INSTALL_PDB AND NOT INSTALL_IGNORE_PDB
|
||||
@ -1305,36 +1294,28 @@ function(ocv_install_target)
|
||||
|
||||
# message(STATUS "Process ${__target} dst=${__dst}...")
|
||||
if(DEFINED __dst)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.1.0)
|
||||
set(__pdb_install_component "pdb")
|
||||
if(DEFINED INSTALL_PDB_COMPONENT AND INSTALL_PDB_COMPONENT)
|
||||
set(__pdb_install_component "${INSTALL_PDB_COMPONENT}")
|
||||
endif()
|
||||
set(__pdb_exclude_from_all "")
|
||||
if(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.6.0)
|
||||
set(__pdb_exclude_from_all EXCLUDE_FROM_ALL)
|
||||
else()
|
||||
message(WARNING "INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL requires CMake 3.6+")
|
||||
endif()
|
||||
endif()
|
||||
set(__pdb_install_component "pdb")
|
||||
if(DEFINED INSTALL_PDB_COMPONENT AND INSTALL_PDB_COMPONENT)
|
||||
set(__pdb_install_component "${INSTALL_PDB_COMPONENT}")
|
||||
endif()
|
||||
set(__pdb_exclude_from_all "")
|
||||
if(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL)
|
||||
set(__pdb_exclude_from_all EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
# message(STATUS "Adding PDB file installation rule: target=${__target} dst=${__dst} component=${__pdb_install_component}")
|
||||
if("${__target_type}" STREQUAL "SHARED_LIBRARY" OR "${__target_type}" STREQUAL "MODULE_LIBRARY")
|
||||
install(FILES "$<TARGET_PDB_FILE:${__target}>" DESTINATION "${__dst}"
|
||||
COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all})
|
||||
else()
|
||||
# There is no generator expression similar to TARGET_PDB_FILE and TARGET_PDB_FILE can't be used: https://gitlab.kitware.com/cmake/cmake/issues/16932
|
||||
# However we still want .pdb files like: 'lib/Debug/opencv_core341d.pdb' or '3rdparty/lib/zlibd.pdb'
|
||||
install(FILES "$<TARGET_PROPERTY:${__target},ARCHIVE_OUTPUT_DIRECTORY>/$<CONFIG>/$<IF:$<BOOL:$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_DEBUG>>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_DEBUG>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME>>.pdb"
|
||||
DESTINATION "${__dst}" CONFIGURATIONS Debug
|
||||
COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all})
|
||||
install(FILES "$<TARGET_PROPERTY:${__target},ARCHIVE_OUTPUT_DIRECTORY>/$<CONFIG>/$<IF:$<BOOL:$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_RELEASE>>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_RELEASE>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME>>.pdb"
|
||||
DESTINATION "${__dst}" CONFIGURATIONS Release
|
||||
COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all})
|
||||
endif()
|
||||
if("${__target_type}" STREQUAL "SHARED_LIBRARY" OR "${__target_type}" STREQUAL "MODULE_LIBRARY")
|
||||
install(FILES "$<TARGET_PDB_FILE:${__target}>" DESTINATION "${__dst}"
|
||||
COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all})
|
||||
else()
|
||||
message(WARNING "PDB files installation is not supported (need CMake >= 3.1.0)")
|
||||
# There is no generator expression similar to TARGET_PDB_FILE and TARGET_PDB_FILE can't be used: https://gitlab.kitware.com/cmake/cmake/issues/16932
|
||||
# However we still want .pdb files like: 'lib/Debug/opencv_core341d.pdb' or '3rdparty/lib/zlibd.pdb'
|
||||
install(FILES "$<TARGET_PROPERTY:${__target},ARCHIVE_OUTPUT_DIRECTORY>/$<CONFIG>/$<IF:$<BOOL:$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_DEBUG>>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_DEBUG>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME>>.pdb"
|
||||
DESTINATION "${__dst}" CONFIGURATIONS Debug
|
||||
COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all})
|
||||
install(FILES "$<TARGET_PROPERTY:${__target},ARCHIVE_OUTPUT_DIRECTORY>/$<CONFIG>/$<IF:$<BOOL:$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_RELEASE>>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_RELEASE>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME>>.pdb"
|
||||
DESTINATION "${__dst}" CONFIGURATIONS Release
|
||||
COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@ -1628,45 +1609,19 @@ function(ocv_add_external_target name inc link def)
|
||||
endif()
|
||||
add_library(ocv.3rdparty.${name} INTERFACE ${imp})
|
||||
if(def)
|
||||
if(NOT (CMAKE_VERSION VERSION_LESS "3.11.0")) # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1264 : eliminates "Cannot specify compile definitions for imported target" error message
|
||||
target_compile_definitions(ocv.3rdparty.${name} INTERFACE "${def}")
|
||||
else()
|
||||
set_target_properties(ocv.3rdparty.${name} PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${def}")
|
||||
endif()
|
||||
target_compile_definitions(ocv.3rdparty.${name} INTERFACE "${def}")
|
||||
endif()
|
||||
if(inc)
|
||||
if(NOT (CMAKE_VERSION VERSION_LESS "3.11.0")) # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1264 : eliminates "Cannot specify compile definitions for imported target" error message
|
||||
target_include_directories(ocv.3rdparty.${name} SYSTEM INTERFACE "$<BUILD_INTERFACE:${inc}>")
|
||||
else()
|
||||
set_target_properties(ocv.3rdparty.${name} PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${inc}>"
|
||||
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${inc}>"
|
||||
)
|
||||
endif()
|
||||
target_include_directories(ocv.3rdparty.${name} SYSTEM INTERFACE "$<BUILD_INTERFACE:${inc}>")
|
||||
endif()
|
||||
if(link)
|
||||
# When cmake version is greater than or equal to 3.11, INTERFACE_LINK_LIBRARIES no longer applies to interface library
|
||||
# See https://github.com/opencv/opencv/pull/18658
|
||||
if(CMAKE_VERSION VERSION_LESS 3.11)
|
||||
set_target_properties(ocv.3rdparty.${name} PROPERTIES
|
||||
INTERFACE_LINK_LIBRARIES "${link}")
|
||||
else()
|
||||
target_link_libraries(ocv.3rdparty.${name} INTERFACE ${link})
|
||||
endif()
|
||||
endif()
|
||||
# to install used target only upgrade CMake
|
||||
if(NOT BUILD_SHARED_LIBS
|
||||
AND CMAKE_VERSION VERSION_LESS "3.13.0" # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2152
|
||||
)
|
||||
install(TARGETS ocv.3rdparty.${name} EXPORT OpenCVModules)
|
||||
target_link_libraries(ocv.3rdparty.${name} INTERFACE ${link})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
set(__OPENCV_EXPORTED_EXTERNAL_TARGETS "" CACHE INTERNAL "")
|
||||
function(ocv_install_used_external_targets)
|
||||
if(NOT BUILD_SHARED_LIBS
|
||||
AND NOT (CMAKE_VERSION VERSION_LESS "3.13.0") # upgrade CMake: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2152
|
||||
)
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
foreach(tgt in ${ARGN})
|
||||
if(tgt MATCHES "^ocv\.3rdparty\.")
|
||||
list(FIND __OPENCV_EXPORTED_EXTERNAL_TARGETS "${tgt}" _found)
|
||||
@ -1784,7 +1739,7 @@ endmacro()
|
||||
|
||||
|
||||
function(ocv_add_test_from_target test_name test_kind the_target)
|
||||
if(CMAKE_VERSION VERSION_GREATER "2.8" AND NOT CMAKE_CROSSCOMPILING)
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
if(NOT "${test_kind}" MATCHES "^(Accuracy|Performance|Sanity)$")
|
||||
message(FATAL_ERROR "Unknown test kind : ${test_kind}")
|
||||
endif()
|
||||
@ -1979,12 +1934,7 @@ macro(ocv_get_smart_file_name output_var fpath)
|
||||
endmacro()
|
||||
|
||||
# Needed by install(DIRECTORY ...)
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
|
||||
set(compatible_MESSAGE_NEVER MESSAGE_NEVER)
|
||||
else()
|
||||
set(compatible_MESSAGE_NEVER "")
|
||||
endif()
|
||||
|
||||
set(compatible_MESSAGE_NEVER MESSAGE_NEVER)
|
||||
|
||||
macro(ocv_git_describe var_name path)
|
||||
if(GIT_FOUND)
|
||||
|
@ -1,7 +1,3 @@
|
||||
if(CMAKE_VERSION VERSION_LESS "3.9")
|
||||
message(STATUS "OpenMP detection requires CMake 3.9+") # OpenMP::OpenMP_CXX target
|
||||
endif()
|
||||
|
||||
find_package(OpenMP)
|
||||
if(OpenMP_FOUND)
|
||||
if(TARGET OpenMP::OpenMP_CXX)
|
||||
|
@ -71,11 +71,9 @@ endforeach()
|
||||
include("tutorial_code/calib3d/real_time_pose_estimation/CMakeLists.txt" OPTIONAL)
|
||||
|
||||
# Standalone samples only
|
||||
if(OpenCV_FOUND AND NOT CMAKE_VERSION VERSION_LESS "3.1")
|
||||
if(OpenCV_FOUND)
|
||||
add_subdirectory("example_cmake")
|
||||
endif()
|
||||
if(OpenCV_FOUND AND NOT CMAKE_VERSION VERSION_LESS "3.9"
|
||||
AND NOT OPENCV_EXAMPLES_SKIP_PARALLEL_BACKEND
|
||||
)
|
||||
if(OpenCV_FOUND AND NOT OPENCV_EXAMPLES_SKIP_PARALLEL_BACKEND)
|
||||
add_subdirectory("tutorial_code/core/parallel_backend")
|
||||
endif()
|
||||
|
@ -1,11 +1,5 @@
|
||||
ocv_install_example_src(opencl *.cpp *.hpp CMakeLists.txt)
|
||||
|
||||
# cmake 3.1 needed for find_package(OpenCL)
|
||||
if(CMAKE_VERSION VERSION_LESS "3.1")
|
||||
message(STATUS "OpenCL samples require CMakes 3.1+")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(OPENCV_OPENCL_SAMPLES_REQUIRED_DEPS
|
||||
opencv_core
|
||||
opencv_imgproc
|
||||
|
@ -16,13 +16,6 @@ if(NOT BUILD_EXAMPLES OR NOT OCV_DEPENDENCIES_FOUND OR OPENCV_SKIP_SAMPLES_BUILD
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS "3.5")
|
||||
message(STATUS "SYCL samples require CMake 3.5+")
|
||||
return()
|
||||
endif()
|
||||
|
||||
cmake_policy(VERSION 3.5)
|
||||
|
||||
find_package(SYCL QUIET) # will oneAPI support this straightforward way?
|
||||
|
||||
if(NOT SYCL_FOUND AND NOT OPENCV_SKIP_SAMPLES_SYCL_ONEDNN)
|
||||
|
Loading…
Reference in New Issue
Block a user