Skip to content

Commit 76f495d

Browse files
authored
Merge pull request opencv#26105 from mshabunin:fix-cmake-3.30
build: minor changes for cmake 3.30 and some cleanup
2 parents 8561f45 + 32d3d6f commit 76f495d

File tree

3 files changed

+29
-71
lines changed

3 files changed

+29
-71
lines changed

CMakeLists.txt

Lines changed: 18 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,20 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_PIC})
121121
ocv_cmake_hook(PRE_CMAKE_BOOTSTRAP)
122122

123123
# Bootstrap CMake system: setup CMAKE_SYSTEM_NAME and other vars
124+
125+
# workaround: https://gitlab.kitware.com/cmake/cmake/-/issues/20989
124126
if(OPENCV_WORKAROUND_CMAKE_20989)
125127
set(CMAKE_SYSTEM_PROCESSOR_BACKUP ${CMAKE_SYSTEM_PROCESSOR})
126128
endif()
127-
enable_language(CXX C)
129+
130+
project(OpenCV CXX C)
131+
128132
if(OPENCV_WORKAROUND_CMAKE_20989)
129133
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR_BACKUP})
130134
endif()
131135

136+
enable_testing()
137+
132138
ocv_cmake_hook(POST_CMAKE_BOOTSTRAP)
133139

134140
if(NOT OPENCV_SKIP_CMAKE_SYSTEM_FILE)
@@ -151,10 +157,6 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # https://cmake.org/cmake/help/
151157
endif()
152158
endif()
153159

154-
enable_testing()
155-
156-
project(OpenCV CXX C)
157-
158160
if(MSVC)
159161
set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE)
160162
endif()
@@ -163,70 +165,30 @@ ocv_cmake_eval(DEBUG_PRE ONCE)
163165

164166
ocv_clear_vars(OpenCVModules_TARGETS)
165167

166-
include(cmake/OpenCVDownload.cmake)
167-
168-
set(BUILD_LIST "" CACHE STRING "Build only listed modules (comma-separated, e.g. 'videoio,dnn,ts')")
169-
170168
# ----------------------------------------------------------------------------
171-
# Break in case of popular CMake configuration mistakes
169+
# Autodetect if we are in a GIT repository
172170
# ----------------------------------------------------------------------------
173-
if(NOT CMAKE_SIZEOF_VOID_P GREATER 0)
174-
message(FATAL_ERROR "CMake fails to determine the bitness of the target platform.
175-
Please check your CMake and compiler installation. If you are cross-compiling then ensure that your CMake toolchain file correctly sets the compiler details.")
171+
find_host_package(Git QUIET)
172+
173+
if(NOT DEFINED OPENCV_VCSVERSION AND GIT_FOUND)
174+
ocv_git_describe(OPENCV_VCSVERSION "${OpenCV_SOURCE_DIR}")
175+
elseif(NOT DEFINED OPENCV_VCSVERSION)
176+
# We don't have git:
177+
set(OPENCV_VCSVERSION "unknown")
176178
endif()
177179

180+
include(cmake/OpenCVDownload.cmake)
181+
178182
# ----------------------------------------------------------------------------
179183
# Detect compiler and target platform architecture
180184
# ----------------------------------------------------------------------------
181185
include(cmake/OpenCVDetectCXXCompiler.cmake)
182186
ocv_cmake_hook(POST_DETECT_COMPILER)
183187

184-
# Add these standard paths to the search paths for FIND_LIBRARY
185-
# to find libraries from these locations first
186-
if(UNIX AND NOT ANDROID)
187-
if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8)
188-
if(EXISTS /lib64)
189-
list(APPEND CMAKE_LIBRARY_PATH /lib64)
190-
else()
191-
list(APPEND CMAKE_LIBRARY_PATH /lib)
192-
endif()
193-
if(EXISTS /usr/lib64)
194-
list(APPEND CMAKE_LIBRARY_PATH /usr/lib64)
195-
else()
196-
list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
197-
endif()
198-
elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4)
199-
if(EXISTS /lib32)
200-
list(APPEND CMAKE_LIBRARY_PATH /lib32)
201-
else()
202-
list(APPEND CMAKE_LIBRARY_PATH /lib)
203-
endif()
204-
if(EXISTS /usr/lib32)
205-
list(APPEND CMAKE_LIBRARY_PATH /usr/lib32)
206-
else()
207-
list(APPEND CMAKE_LIBRARY_PATH /usr/lib)
208-
endif()
209-
endif()
210-
endif()
211-
212-
# Add these standard paths to the search paths for FIND_PATH
213-
# to find include files from these locations first
214-
if(MINGW)
215-
if(EXISTS /mingw)
216-
list(APPEND CMAKE_INCLUDE_PATH /mingw)
217-
endif()
218-
if(EXISTS /mingw32)
219-
list(APPEND CMAKE_INCLUDE_PATH /mingw32)
220-
endif()
221-
if(EXISTS /mingw64)
222-
list(APPEND CMAKE_INCLUDE_PATH /mingw64)
223-
endif()
224-
endif()
225-
226188
# ----------------------------------------------------------------------------
227189
# OpenCV cmake options
228190
# ----------------------------------------------------------------------------
229-
191+
set(BUILD_LIST "" CACHE STRING "Build only listed modules (comma-separated, e.g. 'videoio,dnn,ts')")
230192
OCV_OPTION(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" OFF)
231193

232194
# 3rd party libs
@@ -660,19 +622,6 @@ ocv_include_directories(${OPENCV_CONFIG_FILE_INCLUDE_DIR})
660622
# ----------------------------------------------------------------------------
661623
set(OPENCV_EXTRA_MODULES_PATH "" CACHE PATH "Where to look for additional OpenCV modules (can be ;-separated list of paths)")
662624

663-
# ----------------------------------------------------------------------------
664-
# Autodetect if we are in a GIT repository
665-
# ----------------------------------------------------------------------------
666-
find_host_package(Git QUIET)
667-
668-
if(NOT DEFINED OPENCV_VCSVERSION AND GIT_FOUND)
669-
ocv_git_describe(OPENCV_VCSVERSION "${OpenCV_SOURCE_DIR}")
670-
elseif(NOT DEFINED OPENCV_VCSVERSION)
671-
# We don't have git:
672-
set(OPENCV_VCSVERSION "unknown")
673-
endif()
674-
675-
676625
# ----------------------------------------------------------------------------
677626
# OpenCV compiler and linker options
678627
# ----------------------------------------------------------------------------

cmake/OpenCVDetectCXXCompiler.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ if(NOT DEFINED CMAKE_SIZEOF_VOID_P
8383
AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_CMAKE_SIZEOF_VOID_P)
8484
message(WARNING "OpenCV: CMAKE_SIZEOF_VOID_P is not defined. Perhaps CMake toolchain is broken")
8585
endif()
86+
if(NOT CMAKE_SIZEOF_VOID_P GREATER 0)
87+
message(FATAL_ERROR "CMake fails to determine the bitness of the target platform.
88+
Please check your CMake and compiler installation. If you are cross-compiling then ensure that your CMake toolchain file correctly sets the compiler details.")
89+
endif()
8690

8791
message(STATUS "Detected processor: ${CMAKE_SYSTEM_PROCESSOR}")
8892
if(OPENCV_SKIP_SYSTEM_PROCESSOR_DETECTION)
@@ -156,8 +160,10 @@ elseif(MSVC)
156160
set(OpenCV_ARCH "ARM")
157161
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
158162
set(OpenCV_ARCH "x64")
163+
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
164+
set(OpenCV_ARCH "x86")
159165
else()
160-
set(OpenCV_ARCH x86)
166+
message(FATAL_ERROR "Failed to determine system architecture")
161167
endif()
162168

163169
if(MSVC_VERSION EQUAL 1400)

cmake/OpenCVDownload.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ file(REMOVE "${OPENCV_DOWNLOAD_WITH_WGET}")
4040
ocv_check_environment_variables(OPENCV_DOWNLOAD_MIRROR_ID)
4141

4242
function(ocv_init_download_mirror)
43+
if(NOT GIT_FOUND)
44+
return()
45+
endif()
4346
if(NOT DEFINED OPENCV_DOWNLOAD_MIRROR_ID)
4447
# Run `git remote get-url origin` to get remote source
4548
execute_process(
4649
COMMAND
47-
git remote get-url origin
50+
${GIT_EXECUTABLE} remote get-url origin
4851
WORKING_DIRECTORY
4952
${CMAKE_SOURCE_DIR}
5053
RESULT_VARIABLE

0 commit comments

Comments
 (0)