1 if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER};${CMAKE_CXX_COMPILER_LAUNCHER}" MATCHES "ccache")
2 set(CMAKE_COMPILER_IS_CCACHE 1) # TODO: FIXIT Avoid setting of CMAKE_ variables
3 set(OPENCV_COMPILER_IS_CCACHE 1)
5 function(access_CMAKE_COMPILER_IS_CCACHE)
6 if(NOT OPENCV_SUPPRESS_DEPRECATIONS)
7 message(WARNING "DEPRECATED: CMAKE_COMPILER_IS_CCACHE is replaced to OPENCV_COMPILER_IS_CCACHE.")
10 variable_watch(CMAKE_COMPILER_IS_CCACHE access_CMAKE_COMPILER_IS_CCACHE)
11 if(ENABLE_CCACHE AND NOT OPENCV_COMPILER_IS_CCACHE AND NOT CMAKE_GENERATOR MATCHES "Xcode")
12 # This works fine with Unix Makefiles and Ninja generators
13 find_host_program(CCACHE_PROGRAM ccache)
15 message(STATUS "Looking for ccache - found (${CCACHE_PROGRAM})")
16 get_property(__OLD_RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
17 if(__OLD_RULE_LAUNCH_COMPILE)
18 message(STATUS "Can't replace CMake compiler launcher")
20 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
21 # NOTE: Actually this check doesn't work as expected.
22 # "RULE_LAUNCH_COMPILE" is ignored by CMake during try_compile() step.
23 # ocv_check_compiler_flag(CXX "" IS_CCACHE_WORKS)
24 set(IS_CCACHE_WORKS 1)
26 set(OPENCV_COMPILER_IS_CCACHE 1)
28 message(STATUS "Unable to compile program with enabled ccache, reverting...")
29 set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${__OLD_RULE_LAUNCH_COMPILE}")
33 message(STATUS "Looking for ccache - not found")
37 if((CV_CLANG AND NOT CMAKE_GENERATOR MATCHES "Xcode") # PCH has no support for Clang
38 OR OPENCV_COMPILER_IS_CCACHE
40 set(ENABLE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
43 macro(add_extra_compiler_option option)
44 ocv_check_flag_support(CXX "${option}" _varname "${OPENCV_EXTRA_CXX_FLAGS} ${ARGN}")
46 set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} ${option}")
49 ocv_check_flag_support(C "${option}" _varname "${OPENCV_EXTRA_C_FLAGS} ${ARGN}")
51 set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} ${option}")
55 macro(add_extra_compiler_option_force option)
56 set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} ${option}")
57 set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} ${option}")
61 # Gets environment variable and puts its value to the corresponding preprocessor definition
62 # Useful for WINRT that has no access to environment variables
63 macro(add_env_definitions option)
64 set(value $ENV{${option}})
65 if("${value}" STREQUAL "")
66 message(WARNING "${option} environment variable is empty. Please set it to appropriate location to get correct results")
68 string(REPLACE "\\" "\\\\" value ${value})
70 add_definitions("-D${option}=\"${value}\"")
74 # OpenCV fails some tests when 'char' is 'unsigned' by default
75 add_extra_compiler_option(-fsigned-char)
79 if(NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " /fp:")
81 add_extra_compiler_option("/fp:fast")
83 add_extra_compiler_option("/fp:precise")
87 if(NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " /fp:"
88 AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fp-model"
90 if(NOT ENABLE_FAST_MATH)
91 add_extra_compiler_option("-fp-model precise")
94 elseif(CV_GCC OR CV_CLANG)
96 add_extra_compiler_option(-ffast-math)
100 if(CV_GCC OR CV_CLANG)
101 # High level of warnings.
102 add_extra_compiler_option(-W)
104 # clang-cl interprets -Wall as MSVC would: -Weverything, which is more than
106 add_extra_compiler_option(-Wall)
108 add_extra_compiler_option(-Werror=return-type)
109 add_extra_compiler_option(-Werror=non-virtual-dtor)
110 add_extra_compiler_option(-Werror=address)
111 add_extra_compiler_option(-Werror=sequence-point)
112 add_extra_compiler_option(-Wformat)
113 add_extra_compiler_option(-Werror=format-security -Wformat)
114 add_extra_compiler_option(-Wmissing-declarations)
115 add_extra_compiler_option(-Wmissing-prototypes)
116 add_extra_compiler_option(-Wstrict-prototypes)
117 add_extra_compiler_option(-Wundef)
118 add_extra_compiler_option(-Winit-self)
119 add_extra_compiler_option(-Wpointer-arith)
120 add_extra_compiler_option(-Wshadow)
121 add_extra_compiler_option(-Wsign-promo)
122 add_extra_compiler_option(-Wuninitialized)
123 add_extra_compiler_option(-Winit-self)
124 if(CV_GCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0) AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0))
125 add_extra_compiler_option(-Wno-psabi)
128 if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT ENABLE_PRECOMPILED_HEADERS)
129 add_extra_compiler_option(-Wsuggest-override)
130 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
131 add_extra_compiler_option(-Winconsistent-missing-override)
135 if(ENABLE_NOISY_WARNINGS)
136 add_extra_compiler_option(-Wcast-align)
137 add_extra_compiler_option(-Wstrict-aliasing=2)
139 add_extra_compiler_option(-Wno-delete-non-virtual-dtor)
140 add_extra_compiler_option(-Wno-unnamed-type-template-args)
141 add_extra_compiler_option(-Wno-comment)
142 if(NOT OPENCV_SKIP_IMPLICIT_FALLTHROUGH
143 AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES "implicit-fallthrough"
144 AND (CV_GCC AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0)
146 add_extra_compiler_option(-Wimplicit-fallthrough=3)
148 if(CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
149 add_extra_compiler_option(-Wno-strict-overflow) # Issue appears when compiling surf.cpp from opencv_contrib/modules/xfeatures2d
151 if(CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
152 add_extra_compiler_option(-Wno-missing-field-initializers) # GCC 4.x emits warnings about {}, fixed in GCC 5+
155 add_extra_compiler_option(-fdiagnostics-show-option)
157 # The -Wno-long-long is required in 64bit systems when including system headers.
159 add_extra_compiler_option(-Wno-long-long)
163 if(UNIX AND NOT ANDROID AND NOT (APPLE AND CV_CLANG)) # TODO
164 add_extra_compiler_option(-pthread)
168 add_extra_compiler_option(-Qunused-arguments)
171 if(OPENCV_WARNINGS_ARE_ERRORS)
172 add_extra_compiler_option(-Werror)
176 add_extra_compiler_option(-Wno-semicolon-before-method-body)
179 # Other optimizations
180 if(ENABLE_OMIT_FRAME_POINTER)
181 add_extra_compiler_option(-fomit-frame-pointer)
182 elseif(DEFINED ENABLE_OMIT_FRAME_POINTER)
183 add_extra_compiler_option(-fno-omit-frame-pointer)
188 add_extra_compiler_option("-pg -g")
189 # turn off incompatible options
190 foreach(flags CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
191 OPENCV_EXTRA_FLAGS_RELEASE OPENCV_EXTRA_FLAGS_DEBUG OPENCV_EXTRA_C_FLAGS OPENCV_EXTRA_CXX_FLAGS)
192 string(REPLACE "-fomit-frame-pointer" "" ${flags} "${${flags}}")
193 string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}")
194 string(REPLACE "-fdata-sections" "" ${flags} "${${flags}}")
198 # TODO: Clang/C2 is not supported
199 elseif(((IOS OR ANDROID) AND NOT BUILD_SHARED_LIBS) AND NOT OPENCV_FORCE_FUNCTIONS_SECTIONS)
200 # don't create separate sections for functions/data, reduce package size
202 # Remove unreferenced functions: function level linking
203 add_extra_compiler_option(-ffunction-sections)
204 add_extra_compiler_option(-fdata-sections)
205 if(NOT OPENCV_SKIP_GC_SECTIONS)
207 set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS} -Wl,-dead_strip")
208 set(OPENCV_EXTRA_SHARED_LINKER_FLAGS "${OPENCV_EXTRA_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
210 set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS} -Wl,--gc-sections")
211 set(OPENCV_EXTRA_SHARED_LINKER_FLAGS "${OPENCV_EXTRA_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
218 set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} --coverage")
219 set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} --coverage")
220 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
223 if(ENABLE_INSTRUMENTATION)
225 message(WARNING "ENABLE_INSTRUMENTATION requires C++11 support")
227 set(WITH_VTK OFF) # There are issues with VTK 6.0
231 add_extra_compiler_option(-flto)
234 add_extra_compiler_option(-flto=thin)
237 set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} -DNDEBUG")
238 if(NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} ${OPENCV_EXTRA_FLAGS_DEBUG} " MATCHES "-O")
239 set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG} -O0")
241 set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
243 if(BUILD_WITH_DEBUG_INFO)
244 # https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
245 # '-g' is equal to '-g2', '-g1' produces minimal information, enough for making backtraces
246 ocv_update(OPENCV_DEBUG_OPTION "-g1")
247 if(NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${OPENCV_EXTRA_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS_RELEASE}" MATCHES " -g")
248 set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} ${OPENCV_DEBUG_OPTION}")
254 #TODO Code refactoring is required to resolve security warnings
255 #if(NOT ENABLE_BUILD_HARDENING)
256 set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS")
259 if(BUILD_WITH_DEBUG_INFO)
260 set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} /Zi")
261 set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE} /debug")
262 set(OPENCV_EXTRA_SHARED_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_SHARED_LINKER_FLAGS_RELEASE} /debug")
265 # Remove unreferenced functions: function level linking
266 set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /Gy")
267 if(NOT MSVC_VERSION LESS 1400)
268 set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /bigobj")
271 if(OPENCV_WARNINGS_ARE_ERRORS)
272 set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /WX")
276 set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} /GL")
277 set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE} /LTCG")
280 if(NOT MSVC_VERSION LESS 1800 AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
281 set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /FS")
282 set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} /FS")
286 include(cmake/OpenCVCompilerOptimizations.cmake)
287 if(COMMAND ocv_compiler_optimization_options)
288 ocv_compiler_optimization_options()
290 if(COMMAND ocv_compiler_optimization_options_finalize)
291 ocv_compiler_optimization_options_finalize()
294 # set default visibility to hidden
295 if((CV_GCC OR CV_CLANG)
297 AND NOT OPENCV_SKIP_VISIBILITY_HIDDEN
298 AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fvisibility")
299 add_extra_compiler_option(-fvisibility=hidden)
300 add_extra_compiler_option(-fvisibility-inlines-hidden)
303 # workaround gcc bug for aligned ld/st
304 # https://github.com/opencv/opencv/issues/13211
305 if((PPC64LE AND NOT CMAKE_CROSSCOMPILING) OR OPENCV_FORCE_COMPILER_CHECK_VSX_ALIGNED)
306 ocv_check_runtime_flag("${CPU_BASELINE_FLAGS}" OPENCV_CHECK_VSX_ALIGNED "${OpenCV_SOURCE_DIR}/cmake/checks/runtime/cpu_vsx_aligned.cpp")
307 if(NOT OPENCV_CHECK_VSX_ALIGNED)
308 add_extra_compiler_option_force(-DCV_COMPILER_VSX_BROKEN_ALIGNED)
311 # validate inline asm with fixes register number and constraints wa, wd, wf
313 ocv_check_compiler_flag(CXX "${CPU_BASELINE_FLAGS}" OPENCV_CHECK_VSX_ASM "${OpenCV_SOURCE_DIR}/cmake/checks/cpu_vsx_asm.cpp")
314 if(NOT OPENCV_CHECK_VSX_ASM)
315 add_extra_compiler_option_force(-DCV_COMPILER_VSX_BROKEN_ASM)
319 # combine all "extra" options
320 if(NOT OPENCV_SKIP_EXTRA_COMPILER_FLAGS)
321 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_C_FLAGS}")
322 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}")
323 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OPENCV_EXTRA_FLAGS_RELEASE}")
324 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${OPENCV_EXTRA_FLAGS_RELEASE}")
325 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OPENCV_EXTRA_FLAGS_DEBUG}")
326 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${OPENCV_EXTRA_FLAGS_DEBUG}")
327 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPENCV_EXTRA_EXE_LINKER_FLAGS}")
328 set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}")
329 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}")
330 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OPENCV_EXTRA_SHARED_LINKER_FLAGS}")
331 set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${OPENCV_EXTRA_SHARED_LINKER_FLAGS_RELEASE}")
332 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${OPENCV_EXTRA_SHARED_LINKER_FLAGS_DEBUG}")
336 if(NOT ENABLE_NOISY_WARNINGS)
337 if(MSVC_VERSION EQUAL 1400)
338 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4510 /wd4610 /wd4312 /wd4201 /wd4244 /wd4328 /wd4267)
342 foreach(flags CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
343 string(REPLACE "/Zm1000" "" ${flags} "${${flags}}")
346 # Enable 'extern "C"' and asynchronous (division by zero, access violation) exceptions
347 if(NOT OPENCV_SKIP_MSVC_EXCEPTIONS_FLAG)
348 foreach(flags CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
349 string(REGEX REPLACE " /EH[^ ]* " " " ${flags} " ${${flags}}")
351 if(NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_DEBUG}" MATCHES " /EH")
352 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHa")
356 if(NOT ENABLE_NOISY_WARNINGS)
357 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127) # conditional expression is constant
358 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4251) # class 'std::XXX' needs to have dll-interface to be used by clients of YYY
359 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4324) # 'struct_name' : structure was padded due to __declspec(align())
360 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4275) # non dll-interface class 'std::exception' used as base for dll-interface class 'cv::Exception'
361 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4512) # Assignment operator could not be generated
362 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4589) # Constructor of abstract class 'cv::ORB' ignores initializer for virtual base class 'cv::Algorithm'
365 if(CV_ICC AND NOT ENABLE_NOISY_WARNINGS)
366 foreach(flags CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_DEBUG)
367 string(REGEX REPLACE "( |^)/W[0-9]+( |$)" "\\1\\2" ${flags} "${${flags}}")
369 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qwd673") # PCH warning
373 if(APPLE AND NOT CMAKE_CROSSCOMPILING AND NOT DEFINED ENV{LDFLAGS} AND EXISTS "/usr/local/lib")
374 link_directories("/usr/local/lib")
377 if(ENABLE_BUILD_HARDENING)
378 include(${CMAKE_CURRENT_LIST_DIR}/OpenCVCompilerDefenses.cmake)
382 include(cmake/OpenCVCRTLinkage.cmake)
383 add_definitions(-D_VARIADIC_MAX=10)
386 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
387 get_directory_property(__DIRECTORY_COMPILE_DEFINITIONS COMPILE_DEFINITIONS)
388 if((NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} ${OPENCV_EXTRA_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS_RELEASE} ${__DIRECTORY_COMPILE_DEFINITIONS}" MATCHES "_WIN32_WINNT"
389 AND NOT OPENCV_CMAKE_SKIP_MACRO_WIN32_WINNT)
390 OR OPENCV_CMAKE_FORCE_MACRO_WIN32_WINNT
392 # https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
393 # Target Windows 7 API
394 set(OPENCV_CMAKE_MACRO_WIN32_WINNT "0x0601" CACHE STRING "Value of _WIN32_WINNT macro")
395 add_definitions(-D_WIN32_WINNT=${OPENCV_CMAKE_MACRO_WIN32_WINNT})
399 # Enable compiler options for OpenCV modules/apps/samples only (ignore 3rdparty)
400 macro(ocv_add_modules_compiler_options)
401 if(MSVC AND NOT OPENCV_SKIP_MSVC_W4_OPTION)
402 foreach(flags CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
403 string(REPLACE "/W3" "/W4" ${flags} "${${flags}}")
406 if(OPENCV_ENABLE_MEMORY_SANITIZER)
407 add_definitions(-DOPENCV_ENABLE_MEMORY_SANITIZER=1)
411 # adjust -Wl,-rpath-link
413 if((NOT CMAKE_CROSSCOMPILING OR OPENCV_ENABLE_LINKER_RPATH_LINK_ORIGIN) AND NOT OPENCV_SKIP_LINKER_RPATH_LINK_ORIGIN)
414 if(DEFINED CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN)
415 list(APPEND CMAKE_PLATFORM_RUNTIME_PATH "${CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN}")
417 list(APPEND CMAKE_PLATFORM_RUNTIME_PATH "\$ORIGIN")
419 elseif(NOT OPENCV_SKIP_LINKER_RPATH_LINK_BINARY_LIB)
420 list(APPEND CMAKE_PLATFORM_RUNTIME_PATH "${LIBRARY_OUTPUT_PATH}")
423 if(OPENCV_EXTRA_RPATH_LINK_PATH)
424 string(REPLACE ":" ";" OPENCV_EXTRA_RPATH_LINK_PATH_ "${OPENCV_EXTRA_RPATH_LINK_PATH}")
425 list(APPEND CMAKE_PLATFORM_RUNTIME_PATH ${OPENCV_EXTRA_RPATH_LINK_PATH_})
426 if(NOT CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG)
427 message(WARNING "OPENCV_EXTRA_RPATH_LINK_PATH may not work properly because CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG is not defined (not supported)")