build: minor changes for cmake 3.30 and some cleanup

pull/26105/head
Maksim Shabunin 3 months ago
parent 88f99edc65
commit 32d3d6fa97
  1. 87
      CMakeLists.txt
  2. 8
      cmake/OpenCVDetectCXXCompiler.cmake
  3. 5
      cmake/OpenCVDownload.cmake

@ -121,14 +121,20 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_PIC})
ocv_cmake_hook(PRE_CMAKE_BOOTSTRAP) ocv_cmake_hook(PRE_CMAKE_BOOTSTRAP)
# Bootstrap CMake system: setup CMAKE_SYSTEM_NAME and other vars # Bootstrap CMake system: setup CMAKE_SYSTEM_NAME and other vars
# workaround: https://gitlab.kitware.com/cmake/cmake/-/issues/20989
if(OPENCV_WORKAROUND_CMAKE_20989) if(OPENCV_WORKAROUND_CMAKE_20989)
set(CMAKE_SYSTEM_PROCESSOR_BACKUP ${CMAKE_SYSTEM_PROCESSOR}) set(CMAKE_SYSTEM_PROCESSOR_BACKUP ${CMAKE_SYSTEM_PROCESSOR})
endif() endif()
enable_language(CXX C)
project(OpenCV CXX C)
if(OPENCV_WORKAROUND_CMAKE_20989) if(OPENCV_WORKAROUND_CMAKE_20989)
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR_BACKUP}) set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR_BACKUP})
endif() endif()
enable_testing()
ocv_cmake_hook(POST_CMAKE_BOOTSTRAP) ocv_cmake_hook(POST_CMAKE_BOOTSTRAP)
if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE) if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE)
@ -151,10 +157,6 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # https://cmake.org/cmake/help/
endif() endif()
endif() endif()
enable_testing()
project(OpenCV CXX C)
if(MSVC) if(MSVC)
set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE) set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE)
endif() endif()
@ -163,70 +165,30 @@ ocv_cmake_eval(DEBUG_PRE ONCE)
ocv_clear_vars(OpenCVModules_TARGETS) ocv_clear_vars(OpenCVModules_TARGETS)
include(cmake/OpenCVDownload.cmake)
set(BUILD_LIST "" CACHE STRING "Build only listed modules (comma-separated, e.g. 'videoio,dnn,ts')")
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Break in case of popular CMake configuration mistakes # Autodetect if we are in a GIT repository
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
if(NOT CMAKE_SIZEOF_VOID_P GREATER 0) find_host_package(Git QUIET)
message(FATAL_ERROR "CMake fails to determine the bitness of the target platform.
Please check your CMake and compiler installation. If you are cross-compiling then ensure that your CMake toolchain file correctly sets the compiler details.") if(NOT DEFINED OPENCV_VCSVERSION AND GIT_FOUND)
ocv_git_describe(OPENCV_VCSVERSION "${OpenCV_SOURCE_DIR}")
elseif(NOT DEFINED OPENCV_VCSVERSION)
# We don't have git:
set(OPENCV_VCSVERSION "unknown")
endif() endif()
include(cmake/OpenCVDownload.cmake)
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Detect compiler and target platform architecture # Detect compiler and target platform architecture
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
include(cmake/OpenCVDetectCXXCompiler.cmake) include(cmake/OpenCVDetectCXXCompiler.cmake)
ocv_cmake_hook(POST_DETECT_COMPILER) ocv_cmake_hook(POST_DETECT_COMPILER)
# Add these standard paths to the search paths for FIND_LIBRARY
# to find libraries from these locations first
if(UNIX AND NOT ANDROID)
if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8)
if(EXISTS /lib64)
list(APPEND CMAKE_LIBRARY_PATH /lib64)
else()
list(APPEND CMAKE_LIBRARY_PATH /lib)
endif()
if(EXISTS /usr/lib64)
list(APPEND CMAKE_LIBRARY_PATH /usr/lib64)
else()
list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
endif()
elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4)
if(EXISTS /lib32)
list(APPEND CMAKE_LIBRARY_PATH /lib32)
else()
list(APPEND CMAKE_LIBRARY_PATH /lib)
endif()
if(EXISTS /usr/lib32)
list(APPEND CMAKE_LIBRARY_PATH /usr/lib32)
else()
list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
endif()
endif()
endif()
# Add these standard paths to the search paths for FIND_PATH
# to find include files from these locations first
if(MINGW)
if(EXISTS /mingw)
list(APPEND CMAKE_INCLUDE_PATH /mingw)
endif()
if(EXISTS /mingw32)
list(APPEND CMAKE_INCLUDE_PATH /mingw32)
endif()
if(EXISTS /mingw64)
list(APPEND CMAKE_INCLUDE_PATH /mingw64)
endif()
endif()
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# OpenCV cmake options # OpenCV cmake options
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
set(BUILD_LIST "" CACHE STRING "Build only listed modules (comma-separated, e.g. 'videoio,dnn,ts')")
OCV_OPTION(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" OFF) OCV_OPTION(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" OFF)
# 3rd party libs # 3rd party libs
@ -660,19 +622,6 @@ ocv_include_directories(${OPENCV_CONFIG_FILE_INCLUDE_DIR})
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
set(OPENCV_EXTRA_MODULES_PATH "" CACHE PATH "Where to look for additional OpenCV modules (can be ;-separated list of paths)") set(OPENCV_EXTRA_MODULES_PATH "" CACHE PATH "Where to look for additional OpenCV modules (can be ;-separated list of paths)")
# ----------------------------------------------------------------------------
# Autodetect if we are in a GIT repository
# ----------------------------------------------------------------------------
find_host_package(Git QUIET)
if(NOT DEFINED OPENCV_VCSVERSION AND GIT_FOUND)
ocv_git_describe(OPENCV_VCSVERSION "${OpenCV_SOURCE_DIR}")
elseif(NOT DEFINED OPENCV_VCSVERSION)
# We don't have git:
set(OPENCV_VCSVERSION "unknown")
endif()
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# OpenCV compiler and linker options # OpenCV compiler and linker options
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------

@ -83,6 +83,10 @@ if(NOT DEFINED CMAKE_SIZEOF_VOID_P
AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_CMAKE_SIZEOF_VOID_P) AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_CMAKE_SIZEOF_VOID_P)
message(WARNING "OpenCV: CMAKE_SIZEOF_VOID_P is not defined. Perhaps CMake toolchain is broken") message(WARNING "OpenCV: CMAKE_SIZEOF_VOID_P is not defined. Perhaps CMake toolchain is broken")
endif() endif()
if(NOT CMAKE_SIZEOF_VOID_P GREATER 0)
message(FATAL_ERROR "CMake fails to determine the bitness of the target platform.
Please check your CMake and compiler installation. If you are cross-compiling then ensure that your CMake toolchain file correctly sets the compiler details.")
endif()
message(STATUS "Detected processor: ${CMAKE_SYSTEM_PROCESSOR}") message(STATUS "Detected processor: ${CMAKE_SYSTEM_PROCESSOR}")
if(OPENCV_SKIP_SYSTEM_PROCESSOR_DETECTION) if(OPENCV_SKIP_SYSTEM_PROCESSOR_DETECTION)
@ -156,8 +160,10 @@ elseif(MSVC)
set(OpenCV_ARCH "ARM") set(OpenCV_ARCH "ARM")
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
set(OpenCV_ARCH "x64") set(OpenCV_ARCH "x64")
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
set(OpenCV_ARCH "x86")
else() else()
set(OpenCV_ARCH x86) message(FATAL_ERROR "Failed to determine system architecture")
endif() endif()
if(MSVC_VERSION EQUAL 1400) if(MSVC_VERSION EQUAL 1400)

@ -40,11 +40,14 @@ file(REMOVE "${OPENCV_DOWNLOAD_WITH_WGET}")
ocv_check_environment_variables(OPENCV_DOWNLOAD_MIRROR_ID) ocv_check_environment_variables(OPENCV_DOWNLOAD_MIRROR_ID)
function(ocv_init_download_mirror) function(ocv_init_download_mirror)
if(NOT GIT_FOUND)
return()
endif()
if(NOT DEFINED OPENCV_DOWNLOAD_MIRROR_ID) if(NOT DEFINED OPENCV_DOWNLOAD_MIRROR_ID)
# Run `git remote get-url origin` to get remote source # Run `git remote get-url origin` to get remote source
execute_process( execute_process(
COMMAND COMMAND
git remote get-url origin ${GIT_EXECUTABLE} remote get-url origin
WORKING_DIRECTORY WORKING_DIRECTORY
${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE RESULT_VARIABLE

Loading…
Cancel
Save