Commit 05131af8 authored by Maksim Shabunin's avatar Maksim Shabunin Committed by Alexander Alekhin

Merge pull request #13367 from mshabunin:cmake-verify

* Added dependency verification mechanism for cmake
parent 492a072e
This diff is collapsed.
...@@ -571,14 +571,21 @@ endmacro() ...@@ -571,14 +571,21 @@ endmacro()
# Provides an option that the user can optionally select. # Provides an option that the user can optionally select.
# Can accept condition to control when option is available for user. # Can accept condition to control when option is available for user.
# Usage: # Usage:
# option(<option_variable> "help string describing the option" <initial value or boolean expression> [IF <condition>]) # option(<option_variable>
# "help string describing the option"
# <initial value or boolean expression>
# [VISIBLE_IF <condition>]
# [VERIFY <condition>])
macro(OCV_OPTION variable description value) macro(OCV_OPTION variable description value)
set(__value ${value}) set(__value ${value})
set(__condition "") set(__condition "")
set(__verification)
set(__varname "__value") set(__varname "__value")
foreach(arg ${ARGN}) foreach(arg ${ARGN})
if(arg STREQUAL "IF" OR arg STREQUAL "if") if(arg STREQUAL "IF" OR arg STREQUAL "if" OR arg STREQUAL "VISIBLE_IF")
set(__varname "__condition") set(__varname "__condition")
elseif(arg STREQUAL "VERIFY")
set(__varname "__verification")
else() else()
list(APPEND ${__varname} ${arg}) list(APPEND ${__varname} ${arg})
endif() endif()
...@@ -614,10 +621,46 @@ macro(OCV_OPTION variable description value) ...@@ -614,10 +621,46 @@ macro(OCV_OPTION variable description value)
unset(${variable} CACHE) unset(${variable} CACHE)
endif() endif()
endif() endif()
if(__verification)
set(OPENCV_VERIFY_${variable} "${__verification}") # variable containing condition to verify
list(APPEND OPENCV_VERIFICATIONS "${variable}") # list of variable names (WITH_XXX;WITH_YYY;...)
endif()
unset(__condition) unset(__condition)
unset(__value) unset(__value)
endmacro() endmacro()
# Check that each variable stored in OPENCV_VERIFICATIONS list
# is consistent with actual detection result (stored as condition in OPENCV_VERIFY_...) variables
function(ocv_verify_config)
set(broken_options)
foreach(var ${OPENCV_VERIFICATIONS})
set(evaluated FALSE)
if(${OPENCV_VERIFY_${var}})
set(evaluated TRUE)
endif()
status("Verifying ${var}=${${var}} => '${OPENCV_VERIFY_${var}}'=${evaluated}")
if (${var} AND NOT evaluated)
list(APPEND broken_options ${var})
message(WARNING
"Option ${var} is enabled but corresponding dependency "
"have not been found: \"${OPENCV_VERIFY_${var}}\" is FALSE")
elseif(NOT ${var} AND evaluated)
list(APPEND broken_options ${var})
message(WARNING
"Option ${var} is disabled or unset but corresponding dependency "
"have been explicitly turned on: \"${OPENCV_VERIFY_${var}}\" is TRUE")
endif()
endforeach()
if(broken_options)
string(REPLACE ";" "\n" broken_options "${broken_options}")
message(FATAL_ERROR
"Some dependencies have not been found or have been forced, "
"unset ENABLE_CONFIG_VERIFICATION option to ignore these failures "
"or change following options:\n${broken_options}")
endif()
endfunction()
# Usage: ocv_append_build_options(HIGHGUI FFMPEG) # Usage: ocv_append_build_options(HIGHGUI FFMPEG)
macro(ocv_append_build_options var_prefix pkg_prefix) macro(ocv_append_build_options var_prefix pkg_prefix)
foreach(suffix INCLUDE_DIRS LIBRARIES LIBRARY_DIRS) foreach(suffix INCLUDE_DIRS LIBRARIES LIBRARY_DIRS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment