2019-04-19 18:54:51 +08:00
if ( COMMAND ocv_cmake_dump_vars ) # include guard
return ( )
endif ( )
2016-01-15 19:03:48 +08:00
include ( CMakeParseArguments )
2013-12-05 07:23:52 +08:00
# Debugging function
function ( ocv_cmake_dump_vars )
2018-03-26 19:30:49 +08:00
set ( OPENCV_SUPPRESS_DEPRECATIONS 1 ) # suppress deprecation warnings from variable_watch() guards
2017-07-19 17:37:36 +08:00
get_cmake_property ( __variableNames VARIABLES )
2013-12-05 07:23:52 +08:00
cmake_parse_arguments ( DUMP "" "TOFILE" "" ${ ARGN } )
set ( regex "${DUMP_UNPARSED_ARGUMENTS}" )
2016-01-15 19:38:25 +08:00
string ( TOLOWER "${regex}" regex_lower )
2017-07-19 17:37:36 +08:00
set ( __VARS "" )
foreach ( __variableName ${ __variableNames } )
string ( TOLOWER "${__variableName}" __variableName_lower )
if ( ( __variableName MATCHES "${regex}" OR __variableName_lower MATCHES "${regex_lower}" )
A N D N O T _ _ v a r i a b l e N a m e _ l o w e r M A T C H E S " ^ _ _ " )
2019-07-18 18:22:02 +08:00
get_property ( __value VARIABLE PROPERTY "${__variableName}" )
set ( __VARS "${__VARS}${__variableName}=${__value}\n" )
2013-12-05 07:23:52 +08:00
endif ( )
endforeach ( )
if ( DUMP_TOFILE )
2017-07-19 17:37:36 +08:00
file ( WRITE ${ CMAKE_BINARY_DIR } / ${ DUMP_TOFILE } "${__VARS}" )
2013-12-05 07:23:52 +08:00
else ( )
2017-07-19 17:37:36 +08:00
message ( AUTHOR_WARNING "${__VARS}" )
2013-12-05 07:23:52 +08:00
endif ( )
endfunction ( )
2018-01-29 23:02:00 +08:00
#
# CMake script hooks support
#
option ( OPENCV_DUMP_HOOKS_FLOW "Dump called OpenCV hooks" OFF )
macro ( ocv_cmake_hook_append hook_name )
set ( __var_name "__OPENCV_CMAKE_HOOKS_${hook_name}" )
set ( __value "${${__var_name}}" )
message ( STATUS "Registering hook '${hook_name}': ${ARGN}" )
list ( APPEND __value ${ ARGN } )
set ( ${ __var_name } "${__value}" CACHE INTERNAL "" )
endmacro ( )
macro ( ocv_cmake_hook hook_name )
set ( __var_name "__OPENCV_CMAKE_HOOKS_${hook_name}" )
if ( OPENCV_DUMP_HOOKS_FLOW )
message ( STATUS "Hook ${hook_name} ..." )
endif ( )
foreach ( __hook ${ ${__var_name } } )
#message(STATUS "Hook ${hook_name}: calling '${__hook}' ...")
if ( COMMAND "${__hook}" )
message ( FATAL_ERROR "Indirect calling of CMake commands is not supported yet" )
else ( )
include ( "${__hook}" )
endif ( )
endforeach ( )
endmacro ( )
macro ( ocv_cmake_reset_hooks )
get_cmake_property ( __variableNames VARIABLES )
foreach ( __variableName ${ __variableNames } )
if ( __variableName MATCHES "^__OPENCV_CMAKE_HOOKS_" )
unset ( ${ __variableName } )
unset ( ${ __variableName } CACHE )
endif ( )
endforeach ( )
endmacro ( )
macro ( ocv_cmake_hook_register_dir dir )
file ( GLOB hook_files RELATIVE "${dir}" "${dir}/*.cmake" )
foreach ( f ${ hook_files } )
if ( f MATCHES "^(.+)\\.cmake$" )
set ( hook_name "${CMAKE_MATCH_1}" )
ocv_cmake_hook_append ( ${ hook_name } "${dir}/${f}" )
endif ( )
endforeach ( )
endmacro ( )
2016-01-15 19:03:48 +08:00
function ( ocv_cmake_eval var_name )
if ( DEFINED ${ var_name } )
file ( WRITE "${CMAKE_BINARY_DIR}/CMakeCommand-${var_name}.cmake" ${ ${var_name } } )
include ( "${CMAKE_BINARY_DIR}/CMakeCommand-${var_name}.cmake" )
endif ( )
if ( ";${ARGN};" MATCHES ";ONCE;" )
unset ( ${ var_name } CACHE )
endif ( )
endfunction ( )
2013-12-05 07:23:52 +08:00
2016-01-11 22:54:14 +08:00
macro ( ocv_cmake_configure file_name var_name )
2018-01-03 03:16:51 +08:00
file ( READ "${file_name}" __config )
string ( CONFIGURE "${__config}" ${ var_name } ${ ARGN } )
2016-01-11 22:54:14 +08:00
endmacro ( )
macro ( ocv_update VAR )
if ( NOT DEFINED ${ VAR } )
2016-09-07 23:02:36 +08:00
if ( "x${ARGN}" STREQUAL "x" )
set ( ${ VAR } "" )
else ( )
set ( ${ VAR } ${ ARGN } )
endif ( )
2016-01-11 22:54:14 +08:00
else ( )
#ocv_debug_message("Preserve old value for ${VAR}: ${${VAR}}")
endif ( )
endmacro ( )
2019-12-11 06:35:36 +08:00
function ( _ocv_access_removed_variable VAR ACCESS )
if ( ACCESS STREQUAL "MODIFIED_ACCESS" )
set ( OPENCV_SUPPRESS_MESSAGE_REMOVED_VARIABLE_ ${ VAR } 1 PARENT_SCOPE )
return ( )
endif ( )
if ( ACCESS MATCHES "UNKNOWN_.*"
A N D N O T O P E N C V _ S U P P R E S S _ M E S S A G E _ R E M O V E D _ V A R I A B L E
A N D N O T O P E N C V _ S U P P R E S S _ M E S S A G E _ R E M O V E D _ V A R I A B L E _ $ { V A R }
)
message ( WARNING "OpenCV: Variable has been removed from CMake scripts: ${VAR}" )
set ( OPENCV_SUPPRESS_MESSAGE_REMOVED_VARIABLE_ ${ VAR } 1 PARENT_SCOPE ) # suppress similar messages
endif ( )
endfunction ( )
macro ( ocv_declare_removed_variable VAR )
if ( NOT DEFINED ${ VAR } ) # don't hit external variables
variable_watch ( ${ VAR } _ocv_access_removed_variable )
endif ( )
endmacro ( )
macro ( ocv_declare_removed_variables )
foreach ( _var ${ ARGN } )
ocv_declare_removed_variable ( ${ _var } )
endforeach ( )
endmacro ( )
2017-08-20 23:21:39 +08:00
# Search packages for the host system instead of packages for the target system
# in case of cross compilation these macros should be defined by the toolchain file
2012-01-03 21:48:12 +08:00
if ( NOT COMMAND find_host_package )
2012-02-03 19:26:49 +08:00
macro ( find_host_package )
find_package ( ${ ARGN } )
endmacro ( )
2012-01-03 21:48:12 +08:00
endif ( )
if ( NOT COMMAND find_host_program )
2012-02-03 19:26:49 +08:00
macro ( find_host_program )
find_program ( ${ ARGN } )
endmacro ( )
2012-01-03 21:48:12 +08:00
endif ( )
2013-10-24 23:04:41 +08:00
# assert macro
# Note: it doesn't support lists in arguments
# Usage samples:
# ocv_assert(MyLib_FOUND)
# ocv_assert(DEFINED MyLib_INCLUDE_DIRS)
macro ( ocv_assert )
if ( NOT ( ${ ARGN } ) )
string ( REPLACE ";" " " __assert_msg "${ARGN}" )
message ( AUTHOR_WARNING "Assertion failed: ${__assert_msg}" )
endif ( )
endmacro ( )
2012-01-03 21:48:12 +08:00
2014-08-01 22:11:20 +08:00
macro ( ocv_debug_message )
2018-09-17 19:55:42 +08:00
if ( OPENCV_CMAKE_DEBUG_MESSAGES )
string ( REPLACE ";" " " __msg "${ARGN}" )
message ( STATUS "${__msg}" )
endif ( )
2014-08-01 22:11:20 +08:00
endmacro ( )
2013-10-04 21:15:02 +08:00
macro ( ocv_check_environment_variables )
foreach ( _var ${ ARGN } )
2017-06-21 19:33:47 +08:00
if ( " ${${_var}}" STREQUAL " " AND DEFINED ENV{ ${ _var } } )
2013-10-04 21:15:02 +08:00
set ( __value "$ENV{${_var}}" )
file ( TO_CMAKE_PATH "${__value}" __value ) # Assume that we receive paths
set ( ${ _var } "${__value}" )
message ( STATUS "Update variable ${_var} from environment: ${${_var}}" )
endif ( )
endforeach ( )
endmacro ( )
2016-06-28 18:27:25 +08:00
macro ( ocv_path_join result_var P1 P2_ )
string ( REGEX REPLACE "^[/]+" "" P2 "${P2_}" )
if ( "${P1}" STREQUAL "" OR "${P1}" STREQUAL "." )
set ( ${ result_var } "${P2}" )
2016-01-11 22:54:14 +08:00
elseif ( "${P1}" STREQUAL "/" )
set ( ${ result_var } "/${P2}" )
elseif ( "${P2}" STREQUAL "" )
set ( ${ result_var } "${P1}" )
else ( )
set ( ${ result_var } "${P1}/${P2}" )
endif ( )
2018-11-01 09:37:40 +08:00
string ( REPLACE "\\\\" "\\" ${ result_var } "${${result_var}}" )
string ( REPLACE "//" "/" ${ result_var } "${${result_var}}" )
string ( REGEX REPLACE "(^|[/\\])[\\.][/\\]" "\\1" ${ result_var } "${${result_var}}" )
2016-06-28 18:27:25 +08:00
if ( "${${result_var}}" STREQUAL "" )
set ( ${ result_var } "." )
endif ( )
#message(STATUS "'${P1}' '${P2_}' => '${${result_var}}'")
2016-01-11 22:54:14 +08:00
endmacro ( )
2018-01-06 13:05:40 +08:00
# Used to parse Android SDK 'source.properties' files
# File lines format:
# - '<var_name>=<value>' (with possible 'space' symbols around '=')
# - '#<any comment>'
# Parsed values are saved into CMake variables:
# - '${var_prefix}_${var_name}'
# Flags:
# - 'CACHE_VAR <var1> <var2>' - put these properties into CMake internal cache
# - 'MSG_PREFIX <msg>' - prefix string for emitted messages
# - flag 'VALIDATE' - emit messages about missing values from required cached variables
# - flag 'WARNING' - emit CMake WARNING instead of STATUS messages
function ( ocv_parse_properties_file file var_prefix )
cmake_parse_arguments ( PARSE_PROPERTIES_PARAM "VALIDATE;WARNING" "" "CACHE_VAR;MSG_PREFIX" ${ ARGN } )
set ( __msg_type STATUS )
if ( PARSE_PROPERTIES_PARAM_WARNING )
set ( __msg_type WARNING )
endif ( )
if ( EXISTS "${file}" )
set ( SOURCE_PROPERTIES_REGEX "^[ ]*([^=:\n\" ' ]+ ) [ ] * = [ ] * ( . * ) $ " )
file ( STRINGS "${file}" SOURCE_PROPERTIES_LINES REGEX "^[ ]*[^#].*$" )
foreach ( line ${ SOURCE_PROPERTIES_LINES } )
if ( line MATCHES "${SOURCE_PROPERTIES_REGEX}" )
set ( __name "${CMAKE_MATCH_1}" )
set ( __value "${CMAKE_MATCH_2}" )
string ( REGEX REPLACE "[^a-zA-Z0-9_]" "_" __name ${ __name } )
if ( ";${PARSE_PROPERTIES_PARAM_CACHE_VAR};" MATCHES ";${__name};" )
set ( ${ var_prefix } _ ${ __name } "${__value}" CACHE INTERNAL "from ${file}" )
else ( )
set ( ${ var_prefix } _ ${ __name } "${__value}" PARENT_SCOPE )
endif ( )
else ( )
message ( ${ __msg_type } "${PARSE_PROPERTIES_PARAM_MSG_PREFIX}Can't parse source property: '${line}' (from ${file})" )
endif ( )
endforeach ( )
if ( PARSE_PROPERTIES_PARAM_VALIDATE )
set ( __missing "" )
foreach ( __name ${ PARSE_PROPERTIES_PARAM_CACHE_VAR } )
if ( NOT DEFINED ${ var_prefix } _ ${ __name } )
list ( APPEND __missing ${ __name } )
endif ( )
endforeach ( )
if ( __missing )
message ( ${ __msg_type } "${PARSE_PROPERTIES_PARAM_MSG_PREFIX}Can't read properties '${__missing}' from '${file}'" )
endif ( )
endif ( )
else ( )
message ( ${ __msg_type } "${PARSE_PROPERTIES_PARAM_MSG_PREFIX}Can't find file: ${file}" )
endif ( )
endfunction ( )
2014-08-01 22:11:20 +08:00
# rename modules target to world if needed
macro ( _ocv_fix_target target_var )
if ( BUILD_opencv_world )
if ( OPENCV_MODULE_ ${ ${target_var } }_IS_PART_OF_WORLD )
set ( ${ target_var } opencv_world )
endif ( )
endif ( )
endmacro ( )
2018-02-01 22:08:01 +08:00
# check if "sub" (file or dir) is below "dir"
2018-02-12 19:48:20 +08:00
function ( ocv_is_subdir res dir sub )
2018-02-01 22:08:01 +08:00
get_filename_component ( dir "${dir}" ABSOLUTE )
get_filename_component ( sub "${sub}" ABSOLUTE )
file ( TO_CMAKE_PATH "${dir}" dir )
file ( TO_CMAKE_PATH "${sub}" sub )
set ( dir "${dir}/" )
string ( LENGTH "${dir}" len )
string ( LENGTH "${sub}" len_sub )
if ( NOT len GREATER len_sub )
string ( SUBSTRING "${sub}" 0 ${ len } prefix )
endif ( )
if ( prefix AND prefix STREQUAL dir )
set ( ${ res } TRUE PARENT_SCOPE )
2016-10-04 23:11:46 +08:00
else ( )
2018-02-01 22:08:01 +08:00
set ( ${ res } FALSE PARENT_SCOPE )
2016-10-04 23:11:46 +08:00
endif ( )
endfunction ( )
2018-02-01 22:08:01 +08:00
function ( ocv_is_opencv_directory result_var dir )
set ( result FALSE )
foreach ( parent ${ OpenCV_SOURCE_DIR } ${ OpenCV_BINARY_DIR } ${ OPENCV_EXTRA_MODULES_PATH } )
2018-02-12 19:48:20 +08:00
ocv_is_subdir ( result "${parent}" "${dir}" )
2018-02-01 22:08:01 +08:00
if ( result )
break ( )
endif ( )
endforeach ( )
set ( ${ result_var } ${ result } PARENT_SCOPE )
endfunction ( )
2017-08-20 23:21:39 +08:00
# adds include directories in such a way that directories from the OpenCV source tree go first
2012-04-30 22:33:52 +08:00
function ( ocv_include_directories )
2014-08-01 22:11:20 +08:00
ocv_debug_message ( "ocv_include_directories( ${ARGN} )" )
2012-03-03 23:49:23 +08:00
set ( __add_before "" )
foreach ( dir ${ ARGN } )
2016-10-04 23:11:46 +08:00
ocv_is_opencv_directory ( __is_opencv_dir "${dir}" )
if ( __is_opencv_dir )
2012-03-03 23:49:23 +08:00
list ( APPEND __add_before "${dir}" )
2018-09-12 09:18:33 +08:00
elseif ( ( ( CV_GCC AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0" ) OR CV_CLANG ) AND
2016-10-04 00:38:19 +08:00
d i r M A T C H E S " / u s r / i n c l u d e $ " )
# workaround for GCC 6.x bug
2012-03-03 23:49:23 +08:00
else ( )
2012-06-09 23:00:04 +08:00
include_directories ( AFTER SYSTEM "${dir}" )
2012-03-03 23:49:23 +08:00
endif ( )
endforeach ( )
include_directories ( BEFORE ${ __add_before } )
2012-04-30 22:33:52 +08:00
endfunction ( )
2012-03-03 23:49:23 +08:00
2016-07-08 22:46:08 +08:00
function ( ocv_append_target_property target prop )
get_target_property ( val ${ target } ${ prop } )
if ( val )
set ( val "${val} ${ARGN}" )
set_target_properties ( ${ target } PROPERTIES ${ prop } "${val}" )
else ( )
set_target_properties ( ${ target } PROPERTIES ${ prop } "${ARGN}" )
endif ( )
endfunction ( )
2019-11-02 18:32:23 +08:00
if ( DEFINED OPENCV_DEPENDANT_TARGETS_LIST )
foreach ( v ${ OPENCV_DEPENDANT_TARGETS_LIST } )
unset ( ${ v } CACHE )
endforeach ( )
unset ( OPENCV_DEPENDANT_TARGETS_LIST CACHE )
endif ( )
2016-09-07 23:02:36 +08:00
function ( ocv_append_dependant_targets target )
#ocv_debug_message("ocv_append_dependant_targets(${target} ${ARGN})")
_ocv_fix_target ( target )
2019-11-02 18:32:23 +08:00
list ( FIND OPENCV_DEPENDANT_TARGETS_LIST "OPENCV_DEPENDANT_TARGETS_${target}" __id )
if ( __id EQUAL -1 )
list ( APPEND OPENCV_DEPENDANT_TARGETS_LIST "OPENCV_DEPENDANT_TARGETS_${target}" )
list ( SORT OPENCV_DEPENDANT_TARGETS_LIST )
set ( OPENCV_DEPENDANT_TARGETS_LIST "${OPENCV_DEPENDANT_TARGETS_LIST}" CACHE INTERNAL "" )
endif ( )
2016-09-07 23:02:36 +08:00
set ( OPENCV_DEPENDANT_TARGETS_ ${ target } "${OPENCV_DEPENDANT_TARGETS_${target}};${ARGN}" CACHE INTERNAL "" FORCE )
endfunction ( )
2017-08-20 23:21:39 +08:00
# adds include directories in such a way that directories from the OpenCV source tree go first
2014-08-01 22:11:20 +08:00
function ( ocv_target_include_directories target )
2016-09-07 23:02:36 +08:00
#ocv_debug_message("ocv_target_include_directories(${target} ${ARGN})")
2014-08-01 22:11:20 +08:00
_ocv_fix_target ( target )
set ( __params "" )
2018-03-26 19:30:49 +08:00
if ( CV_GCC AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0" AND
2016-10-04 00:38:19 +08:00
" ; $ { A R G N } ; " M A T C H E S " / u s r / i n c l u d e ; " )
return ( ) # workaround for GCC 6.x bug
endif ( )
2018-01-04 12:39:22 +08:00
set ( __params "" )
set ( __system_params "" )
set ( __var_name __params )
2014-08-01 22:11:20 +08:00
foreach ( dir ${ ARGN } )
2018-01-04 12:39:22 +08:00
if ( "${dir}" STREQUAL "SYSTEM" )
set ( __var_name __system_params )
2014-08-01 22:11:20 +08:00
else ( )
2018-01-04 12:39:22 +08:00
get_filename_component ( __abs_dir "${dir}" ABSOLUTE )
ocv_is_opencv_directory ( __is_opencv_dir "${dir}" )
if ( __is_opencv_dir )
list ( APPEND ${ __var_name } "${__abs_dir}" )
else ( )
list ( APPEND ${ __var_name } "${dir}" )
endif ( )
2014-08-01 22:11:20 +08:00
endif ( )
endforeach ( )
2014-08-13 22:08:08 +08:00
if ( HAVE_CUDA OR CMAKE_VERSION VERSION_LESS 2.8.11 )
2014-08-01 22:11:20 +08:00
include_directories ( ${ __params } )
2018-01-04 12:39:22 +08:00
include_directories ( SYSTEM ${ __system_params } )
2014-08-01 22:11:20 +08:00
else ( )
if ( TARGET ${ target } )
2018-01-04 12:39:22 +08:00
if ( __params )
target_include_directories ( ${ target } PRIVATE ${ __params } )
if ( OPENCV_DEPENDANT_TARGETS_ ${ target } )
foreach ( t ${ OPENCV_DEPENDANT_TARGETS_${target } } )
target_include_directories ( ${ t } PRIVATE ${ __params } )
endforeach ( )
endif ( )
endif ( )
if ( __system_params )
target_include_directories ( ${ target } SYSTEM PRIVATE ${ __system_params } )
if ( OPENCV_DEPENDANT_TARGETS_ ${ target } )
foreach ( t ${ OPENCV_DEPENDANT_TARGETS_${target } } )
target_include_directories ( ${ t } SYSTEM PRIVATE ${ __system_params } )
endforeach ( )
endif ( )
2016-09-07 23:02:36 +08:00
endif ( )
2014-08-01 22:11:20 +08:00
else ( )
2018-01-04 12:39:22 +08:00
if ( __params )
set ( __new_inc ${ OCV_TARGET_INCLUDE_DIRS_${target } } )
list ( APPEND __new_inc ${ __params } )
set ( OCV_TARGET_INCLUDE_DIRS_ ${ target } "${__new_inc}" CACHE INTERNAL "" )
endif ( )
if ( __system_params )
set ( __new_inc ${ OCV_TARGET_INCLUDE_SYSTEM_DIRS_${target } } )
list ( APPEND __new_inc ${ __system_params } )
set ( OCV_TARGET_INCLUDE_SYSTEM_DIRS_ ${ target } "${__new_inc}" CACHE INTERNAL "" )
endif ( )
2014-08-01 22:11:20 +08:00
endif ( )
endif ( )
endfunction ( )
2012-05-21 02:45:19 +08:00
# clears all passed variables
macro ( ocv_clear_vars )
foreach ( _var ${ ARGN } )
2016-06-15 20:51:19 +08:00
unset ( ${ _var } )
2012-05-21 02:45:19 +08:00
unset ( ${ _var } CACHE )
endforeach ( )
endmacro ( )
2012-01-03 21:48:12 +08:00
2020-12-02 20:34:24 +08:00
# Clears passed variables with INTERNAL type from CMake cache
macro ( ocv_clear_internal_cache_vars )
foreach ( _var ${ ARGN } )
get_property ( _propertySet CACHE ${ _var } PROPERTY TYPE SET )
if ( _propertySet )
get_property ( _type CACHE ${ _var } PROPERTY TYPE )
if ( _type STREQUAL "INTERNAL" )
message ( "Cleaning INTERNAL cached variable: ${_var}" )
unset ( ${ _var } CACHE )
endif ( )
endif ( )
endforeach ( )
unset ( _propertySet )
unset ( _type )
endmacro ( )
2012-06-13 00:11:30 +08:00
set ( OCV_COMPILER_FAIL_REGEX
2019-12-26 07:26:59 +08:00
" a r g u m e n t . * i s n o t v a l i d " # GCC 9+ (including support of unicode quotes)
2020-02-03 14:39:14 +08:00
" c o m m a n d [ - ] l i n e o p t i o n . * i s v a l i d f o r . * b u t n o t f o r C \ \ + \ \ + " # GNU
" c o m m a n d [ - ] l i n e o p t i o n . * i s v a l i d f o r . * b u t n o t f o r C " # GNU
2012-06-13 00:11:30 +08:00
" u n r e c o g n i z e d . * o p t i o n " # GNU
" u n k n o w n . * o p t i o n " # Clang
" i g n o r i n g u n k n o w n o p t i o n " # MSVC
" w a r n i n g D 9 0 0 2 " # MSVC, any lang
" o p t i o n . * n o t s u p p o r t e d " # Intel
" [ U u ] n k n o w n o p t i o n " # HP
" [ W w ] a r n i n g : [ O o ] p t i o n " # SunPro
" c o m m a n d o p t i o n . * i s n o t r e c o g n i z e d " # XL
2016-10-07 22:31:21 +08:00
" n o t s u p p o r t e d i n t h i s c o n f i g u r a t i o n , i g n o r e d " # AIX (';' is replaced with ',')
2012-06-13 00:11:30 +08:00
" F i l e w i t h u n k n o w n s u f f i x p a s s e d t o l i n k e r " # PGI
" W A R N I N G : u n k n o w n f l a g : " # Open64
)
2012-06-08 14:19:17 +08:00
2012-06-13 00:11:30 +08:00
MACRO ( ocv_check_compiler_flag LANG FLAG RESULT )
2016-09-07 23:02:36 +08:00
set ( _fname "${ARGN}" )
2012-06-13 21:19:43 +08:00
if ( NOT DEFINED ${ RESULT } )
2016-09-07 23:02:36 +08:00
if ( _fname )
# nothing
elseif ( "_${LANG}_" MATCHES "_CXX_" )
2012-06-13 21:19:43 +08:00
set ( _fname "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx" )
if ( "${CMAKE_CXX_FLAGS} ${FLAG} " MATCHES "-Werror " OR "${CMAKE_CXX_FLAGS} ${FLAG} " MATCHES "-Werror=unknown-pragmas " )
FILE ( WRITE "${_fname}" "int main() { return 0; }\n" )
else ( )
FILE ( WRITE "${_fname}" "#pragma\nint main() { return 0; }\n" )
endif ( )
elseif ( "_${LANG}_" MATCHES "_C_" )
set ( _fname "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c" )
if ( "${CMAKE_C_FLAGS} ${FLAG} " MATCHES "-Werror " OR "${CMAKE_C_FLAGS} ${FLAG} " MATCHES "-Werror=unknown-pragmas " )
FILE ( WRITE "${_fname}" "int main(void) { return 0; }\n" )
else ( )
FILE ( WRITE "${_fname}" "#pragma\nint main(void) { return 0; }\n" )
endif ( )
2013-01-29 21:08:26 +08:00
elseif ( "_${LANG}_" MATCHES "_OBJCXX_" )
set ( _fname "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.mm" )
if ( "${CMAKE_CXX_FLAGS} ${FLAG} " MATCHES "-Werror " OR "${CMAKE_CXX_FLAGS} ${FLAG} " MATCHES "-Werror=unknown-pragmas " )
FILE ( WRITE "${_fname}" "int main() { return 0; }\n" )
else ( )
FILE ( WRITE "${_fname}" "#pragma\nint main() { return 0; }\n" )
endif ( )
2012-06-13 21:19:43 +08:00
else ( )
unset ( _fname )
endif ( )
if ( _fname )
2016-09-07 23:02:36 +08:00
if ( NOT "x${ARGN}" STREQUAL "x" )
file ( RELATIVE_PATH __msg "${CMAKE_SOURCE_DIR}" "${ARGN}" )
set ( __msg " (check file: ${__msg})" )
else ( )
set ( __msg "" )
endif ( )
2019-08-20 21:19:37 +08:00
if ( CMAKE_REQUIRED_LIBRARIES )
set ( __link_libs LINK_LIBRARIES ${ CMAKE_REQUIRED_LIBRARIES } )
else ( )
set ( __link_libs )
endif ( )
set ( __cmake_flags "" )
if ( CMAKE_EXE_LINKER_FLAGS ) # CMP0056 do this on new CMake
list ( APPEND __cmake_flags "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}" )
endif ( )
# CMP0067 do this on new CMake
if ( DEFINED CMAKE_CXX_STANDARD )
list ( APPEND __cmake_flags "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" )
endif ( )
if ( DEFINED CMAKE_CXX_STANDARD_REQUIRED )
list ( APPEND __cmake_flags "-DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}" )
endif ( )
if ( DEFINED CMAKE_CXX_EXTENSIONS )
list ( APPEND __cmake_flags "-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}" )
endif ( )
2016-09-07 23:02:36 +08:00
MESSAGE ( STATUS "Performing Test ${RESULT}${__msg}" )
2012-06-13 21:19:43 +08:00
TRY_COMPILE ( ${ RESULT }
2013-08-22 19:46:13 +08:00
" $ { C M A K E _ B I N A R Y _ D I R } "
2012-06-13 21:19:43 +08:00
" $ { _ f n a m e } "
2019-08-20 21:19:37 +08:00
C M A K E _ F L A G S $ { _ _ c m a k e _ f l a g s }
2012-06-13 21:19:43 +08:00
C O M P I L E _ D E F I N I T I O N S " $ { F L A G } "
2019-08-20 21:19:37 +08:00
$ { _ _ l i n k _ l i b s }
2012-06-13 21:19:43 +08:00
O U T P U T _ V A R I A B L E O U T P U T )
2012-06-13 19:40:05 +08:00
2016-10-07 22:31:21 +08:00
if ( ${ RESULT } )
string ( REPLACE ";" "," OUTPUT_LINES "${OUTPUT}" )
string ( REPLACE "\n" ";" OUTPUT_LINES "${OUTPUT_LINES}" )
foreach ( _regex ${ OCV_COMPILER_FAIL_REGEX } )
if ( NOT ${ RESULT } )
break ( )
endif ( )
foreach ( _line ${ OUTPUT_LINES } )
if ( "${_line}" MATCHES "${_regex}" )
file ( APPEND ${ CMAKE_BINARY_DIR } ${ CMAKE_FILES_DIRECTORY } /CMakeError.log
" B u i l d o u t p u t c h e c k f a i l e d : \ n "
" R e g e x : ' $ { _ r e g e x } ' \ n "
" O u t p u t l i n e : ' $ { _ l i n e } ' \ n " )
set ( ${ RESULT } 0 )
break ( )
endif ( )
endforeach ( )
endforeach ( )
endif ( )
2012-06-13 00:11:30 +08:00
2012-06-13 21:19:43 +08:00
IF ( ${ RESULT } )
SET ( ${ RESULT } 1 CACHE INTERNAL "Test ${RESULT}" )
MESSAGE ( STATUS "Performing Test ${RESULT} - Success" )
ELSE ( ${ RESULT } )
MESSAGE ( STATUS "Performing Test ${RESULT} - Failed" )
SET ( ${ RESULT } "" CACHE INTERNAL "Test ${RESULT}" )
2016-10-07 22:31:21 +08:00
file ( APPEND ${ CMAKE_BINARY_DIR } ${ CMAKE_FILES_DIRECTORY } /CMakeError.log
" C o m p i l a t i o n f a i l e d : \ n "
" s o u r c e f i l e : ' $ { _ f n a m e } ' \ n "
" c h e c k o p t i o n : ' $ { F L A G } ' \ n "
" = = = = = B U I L D L O G = = = = = \ n "
" $ { O U T P U T } \ n "
" = = = = = E N D = = = = = \ n \ n " )
2012-06-13 21:19:43 +08:00
ENDIF ( ${ RESULT } )
else ( )
SET ( ${ RESULT } 0 )
endif ( )
2012-06-13 00:11:30 +08:00
endif ( )
ENDMACRO ( )
2012-06-08 14:19:17 +08:00
2016-09-07 23:02:36 +08:00
macro ( ocv_check_flag_support lang flag varname base_options )
if ( CMAKE_BUILD_TYPE )
set ( CMAKE_TRY_COMPILE_CONFIGURATION ${ CMAKE_BUILD_TYPE } )
endif ( )
2012-06-08 14:19:17 +08:00
if ( "_${lang}_" MATCHES "_CXX_" )
set ( _lang CXX )
2012-06-13 00:11:30 +08:00
elseif ( "_${lang}_" MATCHES "_C_" )
2012-06-08 14:19:17 +08:00
set ( _lang C )
2013-01-29 21:08:26 +08:00
elseif ( "_${lang}_" MATCHES "_OBJCXX_" )
set ( _lang OBJCXX )
2012-06-08 14:19:17 +08:00
else ( )
set ( _lang ${ lang } )
endif ( )
string ( TOUPPER "${flag}" ${ varname } )
string ( REGEX REPLACE "^(/|-)" "HAVE_${_lang}_" ${ varname } "${${varname}}" )
2020-01-21 22:19:30 +08:00
string ( REGEX REPLACE " -|-|=| |\\.|," "_" ${ varname } "${${varname}}" )
2012-06-08 14:19:17 +08:00
2016-09-07 23:02:36 +08:00
ocv_check_compiler_flag ( "${_lang}" "${base_options} ${flag}" ${ ${varname } } ${ ARGN } )
2012-06-08 14:19:17 +08:00
endmacro ( )
2019-03-13 13:52:31 +08:00
macro ( ocv_check_runtime_flag flag result )
set ( _fname "${ARGN}" )
if ( NOT DEFINED ${ result } )
file ( RELATIVE_PATH _rname "${CMAKE_SOURCE_DIR}" "${_fname}" )
message ( STATUS "Performing Runtime Test ${result} (check file: ${_rname})" )
try_run ( exec_return compile_result
" $ { C M A K E _ B I N A R Y _ D I R } "
" $ { _ f n a m e } "
C M A K E _ F L A G S " - D C M A K E _ E X E _ L I N K E R _ F L A G S = $ { C M A K E _ E X E _ L I N K E R _ F L A G S } " # CMP0056 do this on new CMake
C O M P I L E _ D E F I N I T I O N S " $ { f l a g } "
O U T P U T _ V A R I A B L E O U T P U T )
if ( ${ compile_result } )
if ( exec_return EQUAL 0 )
set ( ${ result } 1 CACHE INTERNAL "Runtime Test ${result}" )
message ( STATUS "Performing Runtime Test ${result} - Success" )
else ( )
message ( STATUS "Performing Runtime Test ${result} - Failed(${exec_return})" )
set ( ${ result } 0 CACHE INTERNAL "Runtime Test ${result}" )
endif ( )
else ( )
set ( ${ result } 0 CACHE INTERNAL "Runtime Test ${result}" )
message ( STATUS "Performing Runtime Test ${result} - Compiling Failed" )
endif ( )
if ( NOT ${ result } )
file ( APPEND ${ CMAKE_BINARY_DIR } ${ CMAKE_FILES_DIRECTORY } /CMakeError.log
" R u n t i m e T e s t f a i l e d : \ n "
" s o u r c e f i l e : ' $ { _ f n a m e } ' \ n "
" c h e c k o p t i o n : ' $ { f l a g } ' \ n "
" e x e c r e t u r n : $ { e x e c _ r e t u r n } \ n "
" = = = = = B U I L D A N D R U N T I M E L O G = = = = = \ n "
" $ { O U T P U T } \ n "
" = = = = = E N D = = = = = \ n \ n " )
endif ( )
endif ( )
endmacro ( )
2012-06-08 11:15:08 +08:00
# turns off warnings
macro ( ocv_warnings_disable )
if ( NOT ENABLE_NOISY_WARNINGS )
set ( _flag_vars "" )
set ( _msvc_warnings "" )
set ( _gxx_warnings "" )
2016-11-25 21:46:32 +08:00
set ( _icc_warnings "" )
2012-06-08 11:15:08 +08:00
foreach ( arg ${ ARGN } )
if ( arg MATCHES "^CMAKE_" )
list ( APPEND _flag_vars ${ arg } )
elseif ( arg MATCHES "^/wd" )
list ( APPEND _msvc_warnings ${ arg } )
elseif ( arg MATCHES "^-W" )
list ( APPEND _gxx_warnings ${ arg } )
2016-11-25 21:46:32 +08:00
elseif ( arg MATCHES "^-wd" OR arg MATCHES "^-Qwd" OR arg MATCHES "^/Qwd" )
list ( APPEND _icc_warnings ${ arg } )
2012-06-08 11:15:08 +08:00
endif ( )
endforeach ( )
if ( MSVC AND _msvc_warnings AND _flag_vars )
foreach ( var ${ _flag_vars } )
foreach ( warning ${ _msvc_warnings } )
set ( ${ var } "${${var}} ${warning}" )
endforeach ( )
endforeach ( )
2018-03-26 19:30:49 +08:00
elseif ( ( ( CV_GCC OR CV_CLANG ) OR ( UNIX AND CV_ICC ) ) AND _gxx_warnings AND _flag_vars )
2012-06-08 11:15:08 +08:00
foreach ( var ${ _flag_vars } )
foreach ( warning ${ _gxx_warnings } )
2012-06-08 14:19:17 +08:00
if ( NOT warning MATCHES "^-Wno-" )
2018-12-12 18:35:43 +08:00
string ( REGEX REPLACE "(^|[ ]+)${warning}(=[^ ]*)?([ ]+|$)" " " ${ var } "${${var}}" )
2012-06-08 11:15:08 +08:00
string ( REPLACE "-W" "-Wno-" warning "${warning}" )
2012-06-08 14:19:17 +08:00
endif ( )
2016-09-07 23:02:36 +08:00
ocv_check_flag_support ( ${ var } "${warning}" _varname "" )
2012-06-08 14:19:17 +08:00
if ( ${ _varname } )
2012-06-08 11:15:08 +08:00
set ( ${ var } "${${var}} ${warning}" )
endif ( )
endforeach ( )
endforeach ( )
endif ( )
2016-11-25 21:46:32 +08:00
if ( CV_ICC AND _icc_warnings AND _flag_vars )
foreach ( var ${ _flag_vars } )
foreach ( warning ${ _icc_warnings } )
if ( UNIX )
string ( REPLACE "-Qwd" "-wd" warning "${warning}" )
else ( )
string ( REPLACE "-wd" "-Qwd" warning "${warning}" )
endif ( )
2016-09-07 23:02:36 +08:00
ocv_check_flag_support ( ${ var } "${warning}" _varname "" )
2016-11-25 21:46:32 +08:00
if ( ${ _varname } )
set ( ${ var } "${${var}} ${warning}" )
endif ( )
endforeach ( )
endforeach ( )
endif ( )
2012-06-08 11:15:08 +08:00
unset ( _flag_vars )
unset ( _msvc_warnings )
unset ( _gxx_warnings )
2016-11-25 21:46:32 +08:00
unset ( _icc_warnings )
2012-06-08 11:15:08 +08:00
endif ( NOT ENABLE_NOISY_WARNINGS )
endmacro ( )
2017-08-21 11:31:21 +08:00
macro ( ocv_append_source_file_compile_definitions source )
2017-06-13 00:10:13 +08:00
get_source_file_property ( _value "${source}" COMPILE_DEFINITIONS )
if ( _value )
set ( _value ${ _value } ${ ARGN } )
else ( )
set ( _value ${ ARGN } )
endif ( )
set_source_files_properties ( "${source}" PROPERTIES COMPILE_DEFINITIONS "${_value}" )
endmacro ( )
2014-10-17 18:37:25 +08:00
macro ( add_apple_compiler_options the_module )
2016-09-07 23:02:36 +08:00
ocv_check_flag_support ( OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS "" )
2014-10-17 18:37:25 +08:00
if ( HAVE_OBJC_EXCEPTIONS )
foreach ( source ${ OPENCV_MODULE_${the_module } _SOURCES} )
if ( "${source}" MATCHES "\\.mm$" )
get_source_file_property ( flags "${source}" COMPILE_FLAGS )
if ( flags )
2014-10-17 20:46:47 +08:00
set ( flags "${_flags} -fobjc-exceptions" )
2014-10-17 18:37:25 +08:00
else ( )
2014-10-17 20:46:47 +08:00
set ( flags "-fobjc-exceptions" )
2014-10-17 18:37:25 +08:00
endif ( )
set_source_files_properties ( "${source}" PROPERTIES COMPILE_FLAGS "${flags}" )
endif ( )
endforeach ( )
endif ( )
endmacro ( )
2012-01-03 21:48:12 +08:00
# Provides an option that the user can optionally select.
# Can accept condition to control when option is available for user.
# Usage:
2018-12-07 20:57:25 +08:00
# option(<option_variable>
# "help string describing the option"
# <initial value or boolean expression>
# [VISIBLE_IF <condition>]
# [VERIFY <condition>])
2012-01-03 21:48:12 +08:00
macro ( OCV_OPTION variable description value )
2012-02-22 22:04:59 +08:00
set ( __value ${ value } )
set ( __condition "" )
2018-12-07 20:57:25 +08:00
set ( __verification )
2012-02-22 22:04:59 +08:00
set ( __varname "__value" )
foreach ( arg ${ ARGN } )
2018-12-07 20:57:25 +08:00
if ( arg STREQUAL "IF" OR arg STREQUAL "if" OR arg STREQUAL "VISIBLE_IF" )
2012-02-22 22:04:59 +08:00
set ( __varname "__condition" )
2018-12-07 20:57:25 +08:00
elseif ( arg STREQUAL "VERIFY" )
set ( __varname "__verification" )
2012-02-22 22:04:59 +08:00
else ( )
list ( APPEND ${ __varname } ${ arg } )
endif ( )
endforeach ( )
unset ( __varname )
2015-01-15 23:40:33 +08:00
if ( __condition STREQUAL "" )
2012-02-22 22:04:59 +08:00
set ( __condition 2 GREATER 1 )
2012-02-03 19:26:49 +08:00
endif ( )
2012-02-22 22:04:59 +08:00
2012-02-03 19:26:49 +08:00
if ( ${ __condition } )
2015-01-15 23:40:33 +08:00
if ( __value MATCHES ";" )
2012-02-22 22:04:59 +08:00
if ( ${ __value } )
option ( ${ variable } "${description}" ON )
else ( )
option ( ${ variable } "${description}" OFF )
endif ( )
elseif ( DEFINED ${ __value } )
if ( ${ __value } )
option ( ${ variable } "${description}" ON )
else ( )
option ( ${ variable } "${description}" OFF )
endif ( )
else ( )
option ( ${ variable } "${description}" ${ __value } )
endif ( )
2012-02-03 19:26:49 +08:00
else ( )
2018-11-17 04:23:10 +08:00
if ( DEFINED ${ variable } AND "${${variable}}" # emit warnings about turned ON options only.
A N D NOT ( OPENCV_HIDE_WARNING_UNSUPPORTED_OPTION OR "$ENV{OPENCV_HIDE_WARNING_UNSUPPORTED_OPTION}" )
)
2018-10-23 19:45:51 +08:00
message ( WARNING "Unexpected option: ${variable} (=${${variable}})\nCondition: IF (${__condition})" )
endif ( )
if ( OPENCV_UNSET_UNSUPPORTED_OPTION )
unset ( ${ variable } CACHE )
2018-01-08 02:16:38 +08:00
endif ( )
2012-02-03 19:26:49 +08:00
endif ( )
2018-12-07 20:57:25 +08:00
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 ( )
2012-02-22 22:04:59 +08:00
unset ( __condition )
unset ( __value )
2012-01-03 21:48:12 +08:00
endmacro ( )
2018-12-07 20:57:25 +08:00
# 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
" O p t i o n $ { v a r } i s e n a b l e d b u t c o r r e s p o n d i n g d e p e n d e n c y "
" h a v e n o t b e e n f o u n d : \ " $ { O P E N C V _ V E R I F Y _ $ { v a r } } \ " i s F A L S E " )
elseif ( NOT ${ var } AND evaluated )
list ( APPEND broken_options ${ var } )
message ( WARNING
" O p t i o n $ { v a r } i s d i s a b l e d o r u n s e t b u t c o r r e s p o n d i n g d e p e n d e n c y "
" h a v e b e e n e x p l i c i t l y t u r n e d o n : \ " $ { O P E N C V _ V E R I F Y _ $ { v a r } } \ " i s T R U E " )
endif ( )
endforeach ( )
if ( broken_options )
string ( REPLACE ";" "\n" broken_options "${broken_options}" )
message ( FATAL_ERROR
" S o m e d e p e n d e n c i e s h a v e n o t b e e n f o u n d o r h a v e b e e n f o r c e d , "
" u n s e t E N A B L E _ C O N F I G _ V E R I F I C A T I O N o p t i o n t o i g n o r e t h e s e f a i l u r e s "
" o r c h a n g e f o l l o w i n g o p t i o n s : \ n $ { b r o k e n _ o p t i o n s } " )
endif ( )
endfunction ( )
2016-11-28 04:31:04 +08:00
# Usage: ocv_append_build_options(HIGHGUI FFMPEG)
macro ( ocv_append_build_options var_prefix pkg_prefix )
2019-04-16 05:29:17 +08:00
foreach ( suffix INCLUDE_DIRS LIBRARIES LIBRARY_DIRS LINK_LIBRARIES )
2016-11-28 04:31:04 +08:00
if ( ${ pkg_prefix } _ ${ suffix } )
list ( APPEND ${ var_prefix } _ ${ suffix } ${ ${pkg_prefix } _ ${ suffix } } )
list ( REMOVE_DUPLICATES ${ var_prefix } _ ${ suffix } )
endif ( )
endforeach ( )
endmacro ( )
2018-03-20 18:26:13 +08:00
function ( ocv_append_source_files_cxx_compiler_options files_var )
set ( __flags "${ARGN}" )
ocv_check_flag_support ( CXX "${__flags}" __HAVE_COMPILER_OPTIONS_VAR "" )
if ( ${ __HAVE_COMPILER_OPTIONS_VAR } )
foreach ( source ${ ${files_var } } )
if ( "${source}" MATCHES "\\.(cpp|cc|cxx)$" )
get_source_file_property ( flags "${source}" COMPILE_FLAGS )
if ( flags )
set ( flags "${flags} ${__flags}" )
else ( )
set ( flags "${__flags}" )
endif ( )
set_source_files_properties ( "${source}" PROPERTIES COMPILE_FLAGS "${flags}" )
endif ( )
endforeach ( )
endif ( )
endfunction ( )
2016-11-28 04:31:04 +08:00
# Usage is similar to CMake 'pkg_check_modules' command
# It additionally controls HAVE_${define} and ${define}_${modname}_FOUND variables
macro ( ocv_check_modules define )
unset ( HAVE_ ${ define } )
foreach ( m ${ ARGN } )
if ( m MATCHES "(.*[^><])(>=|=|<=)(.*)" )
set ( __modname "${CMAKE_MATCH_1}" )
else ( )
set ( __modname "${m}" )
endif ( )
unset ( ${ define } _ ${ __modname } _FOUND )
endforeach ( )
2019-04-26 20:13:16 +08:00
if ( PKG_CONFIG_FOUND OR PkgConfig_FOUND )
2019-04-16 05:29:17 +08:00
pkg_check_modules ( ${ define } ${ ARGN } )
endif ( )
2016-11-28 04:31:04 +08:00
if ( ${ define } _FOUND )
set ( HAVE_ ${ define } 1 )
endif ( )
foreach ( m ${ ARGN } )
if ( m MATCHES "(.*[^><])(>=|=|<=)(.*)" )
set ( __modname "${CMAKE_MATCH_1}" )
else ( )
set ( __modname "${m}" )
endif ( )
if ( NOT DEFINED ${ define } _ ${ __modname } _FOUND AND ${ define } _FOUND )
set ( ${ define } _ ${ __modname } _FOUND 1 )
endif ( )
endforeach ( )
2019-04-16 05:29:17 +08:00
if ( ${ define } _FOUND AND ${ define } _LIBRARIES )
if ( ${ define } _LINK_LIBRARIES_XXXXX ) # CMake 3.12+: https://gitlab.kitware.com/cmake/cmake/merge_requests/2068
set ( ${ define } _LIBRARIES "${${define}_LINK_LIBRARIES}" CACHE INTERNAL "" )
else ( )
unset ( _libs ) # absolute paths
unset ( _libs_paths ) # -L args
foreach ( flag ${ ${define } _LDFLAGS} )
if ( flag MATCHES "^-L(.*)" )
list ( APPEND _libs_paths ${ CMAKE_MATCH_1 } )
elseif ( IS_ABSOLUTE "${flag}" )
list ( APPEND _libs "${flag}" )
elseif ( flag MATCHES "^-l(.*)" )
set ( _lib "${CMAKE_MATCH_1}" )
if ( _libs_paths )
find_library ( pkgcfg_lib_ ${ define } _ ${ _lib } NAMES ${ _lib }
H I N T S $ { _ l i b s _ p a t h s } N O _ D E F A U L T _ P A T H )
endif ( )
find_library ( pkgcfg_lib_ ${ define } _ ${ _lib } NAMES ${ _lib } )
mark_as_advanced ( pkgcfg_lib_ ${ define } _ ${ _lib } )
if ( pkgcfg_lib_ ${ define } _ ${ _lib } )
list ( APPEND _libs "${pkgcfg_lib_${define}_${_lib}}" )
else ( )
2019-08-15 01:33:49 +08:00
message ( WARNING "ocv_check_modules(${define}): can't find library '${_lib}'. Specify 'pkgcfg_lib_${define}_${_lib}' manually" )
2019-04-16 05:29:17 +08:00
list ( APPEND _libs "${_lib}" )
endif ( )
else ( )
# -pthread
#message(WARNING "ocv_check_modules(${define}): unknown LDFLAG '${flag}'")
endif ( )
endforeach ( )
set ( ${ define } _LINK_LIBRARIES "${_libs}" )
set ( ${ define } _LIBRARIES "${_libs}" CACHE INTERNAL "" )
unset ( _lib )
unset ( _libs )
unset ( _libs_paths )
2012-01-03 21:48:12 +08:00
endif ( )
2012-02-22 22:04:59 +08:00
endif ( )
2012-01-03 21:48:12 +08:00
endmacro ( )
2019-04-16 05:29:17 +08:00
2017-08-17 06:49:17 +08:00
if ( NOT DEFINED CMAKE_ARGC ) # Guard CMake standalone invocations
2012-02-22 22:04:59 +08:00
2018-01-03 09:40:22 +08:00
# Use this option carefully, CMake's install() will install symlinks instead of real files
# It is fine for development, but should not be used by real installations
set ( __symlink_default OFF ) # preprocessing is required for old CMake like 2.8.12
if ( DEFINED ENV{BUILD_USE_SYMLINKS} )
set ( __symlink_default $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 ( )
set ( OPENCV_DEPHELPER "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dephelper" CACHE INTERNAL "" )
file ( MAKE_DIRECTORY ${ OPENCV_DEPHELPER } )
if ( BUILD_USE_SYMLINKS )
set ( __file0 "${CMAKE_CURRENT_LIST_FILE}" )
set ( __file1 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/symlink_test" )
if ( NOT IS_SYMLINK "${__file1}" )
execute_process ( COMMAND ${ CMAKE_COMMAND } -E create_symlink "${__file0}" "${__file1}"
R E S U L T _ V A R I A B L E S Y M L I N K _ R E S U L T )
if ( NOT SYMLINK_RESULT EQUAL 0 )
file ( REMOVE "${__file1}" )
endif ( )
if ( NOT IS_SYMLINK "${__file1}" )
set ( BUILD_USE_SYMLINKS 0 CACHE INTERNAL "" )
endif ( )
endif ( )
if ( NOT BUILD_USE_SYMLINKS )
message ( STATUS "Build symlinks are not available (disabled)" )
endif ( )
endif ( )
2017-12-31 03:58:57 +08:00
set ( OPENCV_BUILD_INFO_STR "" CACHE INTERNAL "" )
2012-04-14 05:50:59 +08:00
function ( ocv_output_status msg )
message ( STATUS "${msg}" )
string ( REPLACE "\\" "\\\\" msg "${msg}" )
string ( REPLACE "\" " " \\\"" msg "${msg}" )
2019-03-18 22:57:05 +08:00
string ( REGEX REPLACE "^\n+|\n+$" "" msg "${msg}" )
if ( msg MATCHES "\n" )
message ( WARNING "String to be inserted to version_string.inc has an unexpected line break: '${msg}'" )
string ( REPLACE "\n" "\\n" msg "${msg}" )
endif ( )
2017-12-31 03:58:57 +08:00
set ( OPENCV_BUILD_INFO_STR "${OPENCV_BUILD_INFO_STR}\" ${ msg } \\n\"\n" CACHE INTERNAL "" )
2012-04-14 05:50:59 +08:00
endfunction ( )
2012-04-30 22:33:52 +08:00
macro ( ocv_finalize_status )
2017-12-31 03:58:57 +08:00
set ( OPENCV_BUILD_INFO_FILE "${CMAKE_BINARY_DIR}/version_string.tmp" )
if ( EXISTS "${OPENCV_BUILD_INFO_FILE}" )
file ( READ "${OPENCV_BUILD_INFO_FILE}" __content )
else ( )
set ( __content "" )
endif ( )
if ( "${__content}" STREQUAL "${OPENCV_BUILD_INFO_STR}" )
#message(STATUS "${OPENCV_BUILD_INFO_FILE} contains the same content")
else ( )
file ( WRITE "${OPENCV_BUILD_INFO_FILE}" "${OPENCV_BUILD_INFO_STR}" )
endif ( )
unset ( __content )
unset ( OPENCV_BUILD_INFO_STR CACHE )
2012-04-30 22:33:52 +08:00
if ( NOT OPENCV_SKIP_STATUS_FINALIZATION )
2014-08-01 22:11:20 +08:00
if ( DEFINED OPENCV_MODULE_opencv_core_BINARY_DIR )
execute_process ( COMMAND ${ CMAKE_COMMAND } -E copy_if_different "${OPENCV_BUILD_INFO_FILE}" "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version_string.inc" OUTPUT_QUIET )
2012-04-30 22:33:52 +08:00
endif ( )
endif ( )
2017-07-21 21:42:28 +08:00
if ( UNIX )
install ( FILES "${OpenCV_SOURCE_DIR}/platforms/scripts/valgrind.supp"
" $ { O p e n C V _ S O U R C E _ D I R } / p l a t f o r m s / s c r i p t s / v a l g r i n d _ 3 r d p a r t y . s u p p "
D E S T I N A T I O N " $ { O P E N C V _ O T H E R _ I N S T A L L _ P A T H } " C O M P O N E N T " d e v " )
endif ( )
2012-04-30 22:33:52 +08:00
endmacro ( )
2012-02-24 04:05:27 +08:00
# Status report function.
2012-01-03 21:48:12 +08:00
# Automatically align right column and selects text based on condition.
# Usage:
# status(<text>)
# status(<heading> <value1> [<value2> ...])
# status(<heading> <condition> THEN <text for TRUE> ELSE <text for FALSE> )
2012-02-24 04:05:27 +08:00
function ( status text )
2012-02-22 22:04:59 +08:00
set ( status_cond )
set ( status_then )
set ( status_else )
set ( status_current_name "cond" )
foreach ( arg ${ ARGN } )
if ( arg STREQUAL "THEN" )
set ( status_current_name "then" )
elseif ( arg STREQUAL "ELSE" )
set ( status_current_name "else" )
else ( )
list ( APPEND status_ ${ status_current_name } ${ arg } )
endif ( )
endforeach ( )
2012-01-03 21:48:12 +08:00
2012-02-22 22:04:59 +08:00
if ( DEFINED status_cond )
set ( status_placeholder_length 32 )
string ( RANDOM LENGTH ${ status_placeholder_length } ALPHABET " " status_placeholder )
string ( LENGTH "${text}" status_text_length )
if ( status_text_length LESS status_placeholder_length )
string ( SUBSTRING "${text}${status_placeholder}" 0 ${ status_placeholder_length } status_text )
elseif ( DEFINED status_then OR DEFINED status_else )
2012-04-14 05:50:59 +08:00
ocv_output_status ( "${text}" )
2012-02-22 22:04:59 +08:00
set ( status_text "${status_placeholder}" )
else ( )
set ( status_text "${text}" )
endif ( )
if ( DEFINED status_then OR DEFINED status_else )
if ( ${ status_cond } )
string ( REPLACE ";" " " status_then "${status_then}" )
2012-04-14 05:50:59 +08:00
string ( REGEX REPLACE "^[ \t]+" "" status_then "${status_then}" )
ocv_output_status ( "${status_text} ${status_then}" )
2012-02-22 22:04:59 +08:00
else ( )
string ( REPLACE ";" " " status_else "${status_else}" )
2012-04-14 05:50:59 +08:00
string ( REGEX REPLACE "^[ \t]+" "" status_else "${status_else}" )
ocv_output_status ( "${status_text} ${status_else}" )
2012-02-22 22:04:59 +08:00
endif ( )
else ( )
string ( REPLACE ";" " " status_cond "${status_cond}" )
2012-04-14 05:50:59 +08:00
string ( REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}" )
ocv_output_status ( "${status_text} ${status_cond}" )
2012-02-22 22:04:59 +08:00
endif ( )
else ( )
2012-04-14 05:50:59 +08:00
ocv_output_status ( "${text}" )
2012-02-22 22:04:59 +08:00
endif ( )
2012-02-24 04:05:27 +08:00
endfunction ( )
2012-02-03 19:26:49 +08:00
2017-08-17 06:49:17 +08:00
endif ( ) # NOT DEFINED CMAKE_ARGC
2012-02-22 22:04:59 +08:00
2017-11-14 22:07:04 +08:00
#
# Generate a list of enabled features basing on conditions:
# IF <cond> THEN <title>: check condition and append title to the result if it is true
# ELSE <title>: return provided value instead of empty result
# EXCLUSIVE: break after first successful condition
#
# Usage:
2018-02-01 22:08:01 +08:00
# ocv_build_features_string(out [EXCLUSIVE] [IF feature THEN title] ... [ELSE title])
2017-11-14 22:07:04 +08:00
#
function ( ocv_build_features_string out )
set ( result )
list ( REMOVE_AT ARGV 0 )
foreach ( arg ${ ARGV } )
if ( arg STREQUAL "EXCLUSIVE" )
set ( exclusive TRUE )
elseif ( arg STREQUAL "IF" )
set ( then FALSE )
set ( cond )
elseif ( arg STREQUAL "THEN" )
set ( then TRUE )
set ( title )
elseif ( arg STREQUAL "ELSE" )
set ( then FALSE )
set ( else TRUE )
else ( )
if ( then )
if ( ${ cond } )
list ( APPEND result "${arg}" )
if ( exclusive )
break ( )
endif ( )
endif ( )
elseif ( else )
if ( NOT result )
set ( result "${arg}" )
endif ( )
else ( )
list ( APPEND cond ${ arg } )
endif ( )
endif ( )
endforeach ( )
set ( ${ out } ${ result } PARENT_SCOPE )
endfunction ( )
2012-02-03 19:26:49 +08:00
# remove all matching elements from the list
macro ( ocv_list_filterout lst regex )
foreach ( item ${ ${lst } } )
if ( item MATCHES "${regex}" )
list ( REMOVE_ITEM ${ lst } "${item}" )
endif ( )
endforeach ( )
endmacro ( )
2018-01-01 23:56:14 +08:00
# filter matching elements from the list
macro ( ocv_list_filter lst regex )
set ( dst ${ ARGN } )
if ( NOT dst )
set ( dst ${ lst } )
endif ( )
set ( __result ${ ${lst } } )
foreach ( item ${ __result } )
if ( NOT item MATCHES "${regex}" )
list ( REMOVE_ITEM __result "${item}" )
endif ( )
endforeach ( )
set ( ${ dst } ${ __result } )
endmacro ( )
2012-02-22 22:04:59 +08:00
2012-02-03 19:26:49 +08:00
# stable & safe duplicates removal macro
macro ( ocv_list_unique __lst )
if ( ${ __lst } )
list ( REMOVE_DUPLICATES ${ __lst } )
endif ( )
endmacro ( )
2012-02-22 22:04:59 +08:00
2012-02-03 19:26:49 +08:00
# safe list reversal macro
macro ( ocv_list_reverse __lst )
if ( ${ __lst } )
list ( REVERSE ${ __lst } )
endif ( )
endmacro ( )
2012-02-22 22:04:59 +08:00
2012-02-03 19:26:49 +08:00
# safe list sorting macro
macro ( ocv_list_sort __lst )
if ( ${ __lst } )
list ( SORT ${ __lst } )
endif ( )
endmacro ( )
2012-02-22 22:04:59 +08:00
2012-03-26 03:57:58 +08:00
# add prefix to each item in the list
macro ( ocv_list_add_prefix LST PREFIX )
set ( __tmp "" )
foreach ( item ${ ${LST } } )
list ( APPEND __tmp "${PREFIX}${item}" )
endforeach ( )
set ( ${ LST } ${ __tmp } )
unset ( __tmp )
endmacro ( )
# add suffix to each item in the list
macro ( ocv_list_add_suffix LST SUFFIX )
set ( __tmp "" )
foreach ( item ${ ${LST } } )
list ( APPEND __tmp "${item}${SUFFIX}" )
endforeach ( )
set ( ${ LST } ${ __tmp } )
unset ( __tmp )
endmacro ( )
2017-08-20 23:21:39 +08:00
# gets and removes the first element from the list
2012-06-18 14:53:13 +08:00
macro ( ocv_list_pop_front LST VAR )
if ( ${ LST } )
list ( GET ${ LST } 0 ${ VAR } )
list ( REMOVE_AT ${ LST } 0 )
else ( )
set ( ${ VAR } "" )
endif ( )
endmacro ( )
2018-02-01 22:08:01 +08:00
# Get list of duplicates in the list of input items.
# ocv_get_duplicates(<output list> <element> [<element> ...])
function ( ocv_get_duplicates res )
if ( ARGC LESS 2 )
message ( FATAL_ERROR "Invalid call to ocv_get_duplicates" )
endif ( )
set ( lst ${ ARGN } )
list ( SORT lst )
set ( prev_item )
foreach ( item ${ lst } )
if ( item STREQUAL prev_item )
list ( APPEND dups ${ item } )
endif ( )
set ( prev_item ${ item } )
endforeach ( )
set ( ${ res } ${ dups } PARENT_SCOPE )
endfunction ( )
2012-06-18 14:53:13 +08:00
2012-02-03 19:26:49 +08:00
# simple regex escaping routine (does not cover all cases!!!)
macro ( ocv_regex_escape var regex )
string ( REGEX REPLACE "([+.*^$])" "\\\\1" ${ var } "${regex}" )
endmacro ( )
2012-03-15 17:20:16 +08:00
2012-03-26 03:57:58 +08:00
# convert list of paths to full paths
2012-06-18 14:53:13 +08:00
macro ( ocv_convert_to_full_paths VAR )
2012-03-26 03:57:58 +08:00
if ( ${ VAR } )
set ( __tmp "" )
foreach ( path ${ ${VAR } } )
get_filename_component ( ${ VAR } "${path}" ABSOLUTE )
list ( APPEND __tmp "${${VAR}}" )
endforeach ( )
set ( ${ VAR } ${ __tmp } )
unset ( __tmp )
endif ( )
2012-04-14 05:50:59 +08:00
endmacro ( )
2014-02-04 17:25:47 +08:00
# convert list of paths to libraries names without lib prefix
2015-03-30 19:58:37 +08:00
function ( ocv_convert_to_lib_name var )
set ( tmp "" )
2014-02-04 17:25:47 +08:00
foreach ( path ${ ARGN } )
2017-08-17 06:49:17 +08:00
get_filename_component ( tmp_name "${path}" NAME )
ocv_get_libname ( tmp_name "${tmp_name}" )
2015-03-30 19:58:37 +08:00
list ( APPEND tmp "${tmp_name}" )
2014-02-04 17:25:47 +08:00
endforeach ( )
2015-03-30 19:58:37 +08:00
set ( ${ var } ${ tmp } PARENT_SCOPE )
endfunction ( )
2014-02-04 17:25:47 +08:00
2013-08-07 16:53:48 +08:00
# add install command
function ( ocv_install_target )
2017-01-21 00:16:01 +08:00
if ( APPLE_FRAMEWORK AND BUILD_SHARED_LIBS )
install ( TARGETS ${ ARGN } FRAMEWORK DESTINATION ${ OPENCV_3P_LIB_INSTALL_PATH } )
else ( )
install ( TARGETS ${ ARGN } )
endif ( )
2013-08-07 16:53:48 +08:00
2013-10-16 03:05:40 +08:00
set ( isPackage 0 )
unset ( __package )
unset ( __target )
foreach ( e ${ ARGN } )
if ( NOT DEFINED __target )
set ( __target "${e}" )
endif ( )
if ( isPackage EQUAL 1 )
set ( __package "${e}" )
break ( )
endif ( )
if ( e STREQUAL "EXPORT" )
set ( isPackage 1 )
endif ( )
endforeach ( )
if ( DEFINED __package )
list ( APPEND ${ __package } _TARGETS ${ __target } )
set ( ${ __package } _TARGETS "${${__package}_TARGETS}" CACHE INTERNAL "List of ${__package} targets" )
endif ( )
2018-04-09 21:21:27 +08:00
if ( MSVC )
2018-10-11 00:16:32 +08:00
set ( __target "${ARGV0}" )
2019-04-19 18:54:51 +08:00
# 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 ( )
endif ( )
2018-10-11 00:16:32 +08:00
if ( INSTALL_PDB AND NOT INSTALL_IGNORE_PDB
A N D N O T O P E N C V _ $ { _ _ t a r g e t } _ P D B _ S K I P
)
2018-04-09 21:21:27 +08:00
set ( __location_key "ARCHIVE" ) # static libs
get_target_property ( __target_type ${ __target } TYPE )
if ( "${__target_type}" STREQUAL "SHARED_LIBRARY" )
set ( __location_key "RUNTIME" ) # shared libs (.DLL)
endif ( )
set ( processDst 0 )
2013-08-07 16:53:48 +08:00
set ( isDst 0 )
2013-10-24 00:28:22 +08:00
unset ( __dst )
2013-08-07 16:53:48 +08:00
foreach ( e ${ ARGN } )
if ( isDst EQUAL 1 )
2013-10-24 00:28:22 +08:00
set ( __dst "${e}" )
2013-08-07 16:53:48 +08:00
break ( )
endif ( )
2018-04-09 21:21:27 +08:00
if ( processDst EQUAL 1 AND e STREQUAL "DESTINATION" )
2013-08-07 16:53:48 +08:00
set ( isDst 1 )
endif ( )
2018-04-09 21:21:27 +08:00
if ( e STREQUAL "${__location_key}" )
set ( processDst 1 )
2013-08-07 16:53:48 +08:00
else ( )
2018-04-09 21:21:27 +08:00
set ( processDst 0 )
2013-08-07 16:53:48 +08:00
endif ( )
endforeach ( )
2013-10-24 00:28:22 +08:00
# message(STATUS "Process ${__target} dst=${__dst}...")
if ( DEFINED __dst )
2018-04-09 21:21:27 +08:00
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}" )
2014-08-01 22:11:20 +08:00
endif ( )
2018-10-11 00:16:32 +08:00
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 ( )
2018-04-09 21:21:27 +08:00
# message(STATUS "Adding PDB file installation rule: target=${__target} dst=${__dst} component=${__pdb_install_component}")
2019-04-19 18:54:51 +08:00
if ( "${__target_type}" STREQUAL "SHARED_LIBRARY" OR "${__target_type}" STREQUAL "MODULE_LIBRARY" )
2018-10-11 00:16:32 +08:00
install ( FILES "$<TARGET_PDB_FILE:${__target}>" DESTINATION "${__dst}"
C O M P O N E N T $ { _ _ p d b _ i n s t a l l _ c o m p o n e n t } O P T I O N A L $ { _ _ p d b _ e x c l u d e _ f r o m _ a l l } )
2018-04-09 21:21:27 +08:00
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"
2018-10-11 00:16:32 +08:00
D E S T I N A T I O N " $ { _ _ d s t } " C O N F I G U R A T I O N S D e b u g
C O M P O N E N T $ { _ _ p d b _ i n s t a l l _ c o m p o n e n t } O P T I O N A L $ { _ _ p d b _ e x c l u d e _ f r o m _ a l l } )
2018-04-09 21:21:27 +08:00
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"
2018-10-11 00:16:32 +08:00
D E S T I N A T I O N " $ { _ _ d s t } " C O N F I G U R A T I O N S R e l e a s e
C O M P O N E N T $ { _ _ p d b _ i n s t a l l _ c o m p o n e n t } O P T I O N A L $ { _ _ p d b _ e x c l u d e _ f r o m _ a l l } )
2014-08-01 22:11:20 +08:00
endif ( )
else ( )
2018-04-09 21:21:27 +08:00
message ( WARNING "PDB files installation is not supported (need CMake >= 3.1.0)" )
2013-10-24 00:28:22 +08:00
endif ( )
endif ( )
2013-08-07 16:53:48 +08:00
endif ( )
endif ( )
endfunction ( )
2018-02-27 02:10:21 +08:00
# ocv_install_3rdparty_licenses(<library-name> <filename1> [<filename2> ..])
function ( ocv_install_3rdparty_licenses library )
foreach ( filename ${ ARGN } )
2019-04-02 22:47:03 +08:00
set ( filepath "${filename}" )
if ( NOT IS_ABSOLUTE "${filepath}" )
set ( filepath "${CMAKE_CURRENT_LIST_DIR}/${filepath}" )
endif ( )
2018-02-27 02:10:21 +08:00
get_filename_component ( name "${filename}" NAME )
install (
2019-04-02 22:47:03 +08:00
F I L E S " $ { f i l e p a t h } "
D E S T I N A T I O N " $ { O P E N C V _ L I C E N S E S _ I N S T A L L _ P A T H } "
2018-02-27 02:10:21 +08:00
C O M P O N E N T l i c e n s e s
R E N A M E " $ { l i b r a r y } - $ { n a m e } "
2019-04-02 22:47:03 +08:00
)
2018-02-27 02:10:21 +08:00
endforeach ( )
endfunction ( )
2013-08-07 16:53:48 +08:00
2012-04-14 05:50:59 +08:00
# read set of version defines from the header file
macro ( ocv_parse_header FILENAME FILE_VAR )
set ( vars_regex "" )
set ( __parnet_scope OFF )
set ( __add_cache OFF )
foreach ( name ${ ARGN } )
2016-11-23 17:44:44 +08:00
if ( ${ name } STREQUAL "PARENT_SCOPE" )
2012-04-14 05:50:59 +08:00
set ( __parnet_scope ON )
2016-11-23 17:44:44 +08:00
elseif ( ${ name } STREQUAL "CACHE" )
2012-04-14 05:50:59 +08:00
set ( __add_cache ON )
elseif ( vars_regex )
set ( vars_regex "${vars_regex}|${name}" )
else ( )
set ( vars_regex "${name}" )
endif ( )
endforeach ( )
if ( EXISTS "${FILENAME}" )
file ( STRINGS "${FILENAME}" ${ FILE_VAR } REGEX "#define[ \t]+(${vars_regex})[ \t]+[0-9]+" )
else ( )
unset ( ${ FILE_VAR } )
endif ( )
foreach ( name ${ ARGN } )
2016-11-23 17:44:44 +08:00
if ( NOT ${ name } STREQUAL "PARENT_SCOPE" AND NOT ${ name } STREQUAL "CACHE" )
2012-04-14 05:50:59 +08:00
if ( ${ FILE_VAR } )
if ( ${ FILE_VAR } MATCHES ".+[ \t]${name}[ \t]+([0-9]+).*" )
string ( REGEX REPLACE ".+[ \t]${name}[ \t]+([0-9]+).*" "\\1" ${ name } "${${FILE_VAR}}" )
else ( )
set ( ${ name } "" )
endif ( )
if ( __add_cache )
set ( ${ name } ${ ${name } } CACHE INTERNAL "${name} parsed from ${FILENAME}" FORCE )
elseif ( __parnet_scope )
set ( ${ name } "${${name}}" PARENT_SCOPE )
endif ( )
else ( )
unset ( ${ name } CACHE )
endif ( )
endif ( )
endforeach ( )
endmacro ( )
# read single version define from the header file
2012-07-10 03:16:38 +08:00
macro ( ocv_parse_header2 LIBNAME HDR_PATH VARNAME )
ocv_clear_vars ( ${ LIBNAME } _VERSION_MAJOR
$ { L I B N A M E } _ V E R S I O N _ M A J O R
$ { L I B N A M E } _ V E R S I O N _ M I N O R
$ { L I B N A M E } _ V E R S I O N _ P A T C H
$ { L I B N A M E } _ V E R S I O N _ T W E A K
$ { L I B N A M E } _ V E R S I O N _ S T R I N G )
2012-04-14 05:50:59 +08:00
set ( ${ LIBNAME } _H "" )
if ( EXISTS "${HDR_PATH}" )
file ( STRINGS "${HDR_PATH}" ${ LIBNAME } _H REGEX "^#define[ \t]+${VARNAME}[ \t]+\" [^\ "]*\" .* $ " LIMIT_COUNT 1 )
endif ( )
2012-07-10 03:16:38 +08:00
2012-04-14 05:50:59 +08:00
if ( ${ LIBNAME } _H )
string ( REGEX REPLACE "^.*[ \t]${VARNAME}[ \t]+\" ( [0-9]+ ) .* $ " " \\1" ${ LIBNAME } _VERSION_MAJOR "${${LIBNAME}_H}" )
string ( REGEX REPLACE "^.*[ \t]${VARNAME}[ \t]+\" [0-9]+\\.([0-9]+ ) . * $ " " \ \ 1 " $ { L I B N A M E } _ V E R S I O N _ M I N O R " $ { $ { L I B N A M E } _ H } " )
string ( REGEX REPLACE "^.*[ \t]${VARNAME}[ \t]+\" [0-9]+\\.[0-9]+\\.([0-9]+ ) . * $ " " \ \ 1 " $ { L I B N A M E } _ V E R S I O N _ P A T C H " $ { $ { L I B N A M E } _ H } " )
2012-07-10 03:16:38 +08:00
set ( ${ LIBNAME } _VERSION_MAJOR ${ ${LIBNAME } _VERSION_MAJOR} ${ ARGN } )
set ( ${ LIBNAME } _VERSION_MINOR ${ ${LIBNAME } _VERSION_MINOR} ${ ARGN } )
set ( ${ LIBNAME } _VERSION_PATCH ${ ${LIBNAME } _VERSION_PATCH} ${ ARGN } )
set ( ${ LIBNAME } _VERSION_STRING "${${LIBNAME}_VERSION_MAJOR}.${${LIBNAME}_VERSION_MINOR}.${${LIBNAME}_VERSION_PATCH}" )
2012-04-14 05:50:59 +08:00
# append a TWEAK version if it exists:
set ( ${ LIBNAME } _VERSION_TWEAK "" )
if ( "${${LIBNAME}_H}" MATCHES "^.*[ \t]${VARNAME}[ \t]+\" [0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+ ) . * $ " )
2012-07-10 03:16:38 +08:00
set ( ${ LIBNAME } _VERSION_TWEAK "${CMAKE_MATCH_1}" ${ ARGN } )
endif ( )
if ( ${ LIBNAME } _VERSION_TWEAK )
set ( ${ LIBNAME } _VERSION_STRING "${${LIBNAME}_VERSION_STRING}.${${LIBNAME}_VERSION_TWEAK}" ${ ARGN } )
else ( )
set ( ${ LIBNAME } _VERSION_STRING "${${LIBNAME}_VERSION_STRING}" ${ ARGN } )
2012-04-14 05:50:59 +08:00
endif ( )
endif ( )
endmacro ( )
2012-08-21 17:59:27 +08:00
2019-04-16 05:29:17 +08:00
# TODO remove this
2013-05-14 22:20:01 +08:00
# read single version info from the pkg file
2019-04-16 05:29:17 +08:00
macro ( ocv_parse_pkg ver_varname LIBNAME PKG_PATH )
2013-05-14 22:20:01 +08:00
if ( EXISTS "${PKG_PATH}/${LIBNAME}.pc" )
file ( STRINGS "${PKG_PATH}/${LIBNAME}.pc" line_to_parse REGEX "^Version:[ \t]+[0-9.]*.*$" LIMIT_COUNT 1 )
2019-04-16 05:29:17 +08:00
STRING ( REGEX REPLACE ".*Version: ([^ ]+).*" "\\1" ${ ver_varname } "${line_to_parse}" )
2013-05-14 22:20:01 +08:00
endif ( )
endmacro ( )
2012-08-21 17:59:27 +08:00
################################################################################################
# short command to setup source group
function ( ocv_source_group group )
2014-08-01 22:11:20 +08:00
if ( BUILD_opencv_world AND OPENCV_MODULE_ ${ the_module } _IS_PART_OF_WORLD )
set ( group "${the_module}\\${group}" )
endif ( )
2013-12-05 07:23:52 +08:00
cmake_parse_arguments ( SG "" "DIRBASE" "GLOB;GLOB_RECURSE;FILES" ${ ARGN } )
set ( files "" )
if ( SG_FILES )
list ( APPEND files ${ SG_FILES } )
endif ( )
if ( SG_GLOB )
file ( GLOB srcs ${ SG_GLOB } )
list ( APPEND files ${ srcs } )
endif ( )
if ( SG_GLOB_RECURSE )
file ( GLOB_RECURSE srcs ${ SG_GLOB_RECURSE } )
list ( APPEND files ${ srcs } )
endif ( )
if ( SG_DIRBASE )
foreach ( f ${ files } )
file ( RELATIVE_PATH fpart "${SG_DIRBASE}" "${f}" )
if ( fpart MATCHES "^\\.\\." )
message ( AUTHOR_WARNING "Can't detect subpath for source_group command: Group=${group} FILE=${f} DIRBASE=${SG_DIRBASE}" )
set ( fpart "" )
else ( )
get_filename_component ( fpart "${fpart}" PATH )
if ( fpart )
set ( fpart "/${fpart}" ) # add '/'
string ( REPLACE "/" "\\" fpart "${fpart}" )
endif ( )
endif ( )
source_group ( "${group}${fpart}" FILES ${ f } )
endforeach ( )
else ( )
source_group ( ${ group } FILES ${ files } )
endif ( )
2013-08-21 21:26:54 +08:00
endfunction ( )
2014-08-01 22:11:20 +08:00
2017-08-17 06:49:17 +08:00
macro ( __ocv_push_target_link_libraries )
2017-01-16 23:12:38 +08:00
if ( NOT TARGET ${ target } )
if ( NOT DEFINED OPENCV_MODULE_ ${ target } _LOCATION )
message ( FATAL_ERROR "ocv_target_link_libraries: invalid target: '${target}'" )
endif ( )
2017-08-17 06:49:17 +08:00
set ( OPENCV_MODULE_ ${ target } _LINK_DEPS ${ OPENCV_MODULE_${target } _LINK_DEPS} ${ ARGN } CACHE INTERNAL "" FORCE )
2017-01-16 23:12:38 +08:00
else ( )
2017-08-17 06:49:17 +08:00
target_link_libraries ( ${ target } ${ ARGN } )
endif ( )
endmacro ( )
function ( ocv_target_link_libraries target )
set ( LINK_DEPS ${ ARGN } )
_ocv_fix_target ( target )
2019-12-13 22:52:40 +08:00
set ( LINK_MODE "PRIVATE" )
2017-08-17 06:49:17 +08:00
set ( LINK_PENDING "" )
foreach ( dep ${ LINK_DEPS } )
if ( " ${dep}" STREQUAL " ${target}" )
# prevent "link to itself" warning (world problem)
2019-12-13 22:52:40 +08:00
elseif ( " ${dep}" STREQUAL " LINK_PRIVATE" OR " ${dep}" STREQUAL " LINK_PUBLIC" # deprecated
O R " $ { d e p } " S T R E Q U A L " P R I V A T E " O R " $ { d e p } " S T R E Q U A L " P U B L I C " O R " $ { d e p } " S T R E Q U A L " I N T E R F A C E "
)
2017-08-17 06:49:17 +08:00
if ( NOT LINK_PENDING STREQUAL "" )
__ocv_push_target_link_libraries ( ${ LINK_MODE } ${ LINK_PENDING } )
set ( LINK_PENDING "" )
set ( LINK_MODE "${dep}" )
endif ( )
else ( )
if ( BUILD_opencv_world )
if ( OPENCV_MODULE_ ${ dep } _IS_PART_OF_WORLD )
set ( dep opencv_world )
endif ( )
endif ( )
list ( APPEND LINK_PENDING "${dep}" )
endif ( )
endforeach ( )
if ( NOT LINK_PENDING STREQUAL "" )
__ocv_push_target_link_libraries ( ${ LINK_MODE } ${ LINK_PENDING } )
2017-01-16 23:12:38 +08:00
endif ( )
2014-08-01 22:11:20 +08:00
endfunction ( )
2017-09-01 00:13:07 +08:00
function ( ocv_target_compile_definitions target )
_ocv_fix_target ( target )
2017-12-16 03:21:51 +08:00
if ( NOT TARGET ${ target } )
if ( NOT DEFINED OPENCV_MODULE_ ${ target } _LOCATION )
message ( FATAL_ERROR "ocv_target_compile_definitions: invalid target: '${target}'" )
endif ( )
set ( OPENCV_MODULE_ ${ target } _COMPILE_DEFINITIONS ${ OPENCV_MODULE_${target } _COMPILE_DEFINITIONS} ${ ARGN } CACHE INTERNAL "" FORCE )
else ( )
target_compile_definitions ( ${ target } ${ ARGN } )
endif ( )
2017-09-01 00:13:07 +08:00
endfunction ( )
2014-08-01 22:11:20 +08:00
function ( _ocv_append_target_includes target )
if ( DEFINED OCV_TARGET_INCLUDE_DIRS_ ${ target } )
target_include_directories ( ${ target } PRIVATE ${ OCV_TARGET_INCLUDE_DIRS_${target } } )
2016-09-07 23:02:36 +08:00
if ( OPENCV_DEPENDANT_TARGETS_ ${ target } )
foreach ( t ${ OPENCV_DEPENDANT_TARGETS_${target } } )
target_include_directories ( ${ t } PRIVATE ${ OCV_TARGET_INCLUDE_DIRS_${target } } )
endforeach ( )
endif ( )
2014-08-01 22:11:20 +08:00
unset ( OCV_TARGET_INCLUDE_DIRS_ ${ target } CACHE )
endif ( )
2018-01-04 12:39:22 +08:00
if ( DEFINED OCV_TARGET_INCLUDE_SYSTEM_DIRS_ ${ target } )
target_include_directories ( ${ target } SYSTEM PRIVATE ${ OCV_TARGET_INCLUDE_SYSTEM_DIRS_${target } } )
if ( OPENCV_DEPENDANT_TARGETS_ ${ target } )
foreach ( t ${ OPENCV_DEPENDANT_TARGETS_${target } } )
target_include_directories ( ${ t } SYSTEM PRIVATE ${ OCV_TARGET_INCLUDE_SYSTEM_DIRS_${target } } )
endforeach ( )
endif ( )
unset ( OCV_TARGET_INCLUDE_SYSTEM_DIRS_ ${ target } CACHE )
endif ( )
2014-08-01 22:11:20 +08:00
endfunction ( )
function ( ocv_add_executable target )
add_executable ( ${ target } ${ ARGN } )
_ocv_append_target_includes ( ${ target } )
endfunction ( )
function ( ocv_add_library target )
2016-01-14 21:59:33 +08:00
if ( HAVE_CUDA AND ARGN MATCHES "\\.cu" )
ocv_include_directories ( ${ CUDA_INCLUDE_DIRS } )
ocv_cuda_compile ( cuda_objs ${ ARGN } )
2015-01-19 23:03:29 +08:00
set ( OPENCV_MODULE_ ${ target } _CUDA_OBJECTS ${ cuda_objs } CACHE INTERNAL "Compiled CUDA object files" )
2014-08-13 22:07:31 +08:00
endif ( )
add_library ( ${ target } ${ ARGN } ${ cuda_objs } )
2015-01-19 23:03:29 +08:00
2017-01-21 00:16:01 +08:00
if ( APPLE_FRAMEWORK AND BUILD_SHARED_LIBS )
message ( STATUS "Setting Apple target properties for ${target}" )
set ( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG 1 )
set_target_properties ( ${ target } PROPERTIES
F R A M E W O R K T R U E
M A C O S X _ F R A M E W O R K _ I D E N T I F I E R o r g . o p e n c v
M A C O S X _ F R A M E W O R K _ I N F O _ P L I S T $ { C M A K E _ B I N A R Y _ D I R } / i o s / I n f o . p l i s t
# "current version" in semantic format in Mach-O binary file
V E R S I O N $ { O P E N C V _ L I B V E R S I O N }
# "compatibility version" in semantic format in Mach-O binary file
S O V E R S I O N $ { O P E N C V _ L I B V E R S I O N }
I N S T A L L _ R P A T H " "
I N S T A L L _ N A M E _ D I R " @ r p a t h "
B U I L D _ W I T H _ I N S T A L L _ R P A T H 1
L I B R A R Y _ O U T P U T _ N A M E " o p e n c v 2 "
X C O D E _ A T T R I B U T E _ T A R G E T E D _ D E V I C E _ F A M I L Y " 1 , 2 "
#PUBLIC_HEADER "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/cvconfig.h"
#XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
)
endif ( )
2014-08-01 22:11:20 +08:00
_ocv_append_target_includes ( ${ target } )
2014-08-13 22:07:31 +08:00
endfunction ( )
2015-04-06 21:12:00 +08:00
2017-04-25 21:48:50 +08:00
macro ( ocv_get_libname var_name )
get_filename_component ( __libname "${ARGN}" NAME )
2017-11-08 21:06:48 +08:00
# libopencv_core.so.3.3 -> opencv_core
2017-11-16 00:54:46 +08:00
string ( REGEX REPLACE "^lib(.+)\\.(a|so|dll)(\\.[.0-9]+)?$" "\\1" __libname "${__libname}" )
2017-11-08 21:06:48 +08:00
# MacOSX: libopencv_core.3.3.1.dylib -> opencv_core
string ( REGEX REPLACE "^lib(.+[^.0-9])\\.([.0-9]+\\.)?dylib$" "\\1" __libname "${__libname}" )
2017-04-25 21:48:50 +08:00
set ( ${ var_name } "${__libname}" )
endmacro ( )
2015-04-06 21:12:00 +08:00
# build the list of opencv libs and dependencies for all modules
# _modules - variable to hold list of all modules
# _extra - variable to hold list of extra dependencies
# _3rdparty - variable to hold list of prebuilt 3rdparty libraries
macro ( ocv_get_all_libs _modules _extra _3rdparty )
set ( ${ _modules } "" )
set ( ${ _extra } "" )
set ( ${ _3rdparty } "" )
foreach ( m ${ OPENCV_MODULES_PUBLIC } )
2015-06-18 01:07:56 +08:00
if ( TARGET ${ m } )
get_target_property ( deps ${ m } INTERFACE_LINK_LIBRARIES )
if ( NOT deps )
set ( deps "" )
endif ( )
else ( )
2015-05-19 21:15:54 +08:00
set ( deps "" )
endif ( )
2015-12-22 22:10:33 +08:00
set ( _rev_deps "${deps};${m}" )
ocv_list_reverse ( _rev_deps )
foreach ( dep ${ _rev_deps } )
if ( DEFINED OPENCV_MODULE_ ${ dep } _LOCATION )
list ( INSERT ${ _modules } 0 ${ dep } )
endif ( )
endforeach ( )
2015-04-06 21:12:00 +08:00
foreach ( dep ${ deps } ${ OPENCV_LINKER_LIBS } )
2015-04-08 19:15:20 +08:00
if ( NOT DEFINED OPENCV_MODULE_ ${ dep } _LOCATION )
2017-08-17 06:49:17 +08:00
if ( dep MATCHES "^\\$<LINK_ONLY:([^>]+)>$" )
set ( dep "${CMAKE_MATCH_1}" )
endif ( )
if ( dep MATCHES "^\\$<" )
message ( WARNING "Unexpected CMake generator expression: ${dep}" )
endif ( )
2015-04-08 19:15:20 +08:00
if ( TARGET ${ dep } )
2017-04-25 21:48:50 +08:00
get_target_property ( _type ${ dep } TYPE )
2019-12-13 22:52:40 +08:00
if ( ( _type STREQUAL "STATIC_LIBRARY" AND BUILD_SHARED_LIBS )
O R _ t y p e S T R E Q U A L " I N T E R F A C E _ L I B R A R Y "
O R D E F I N E D O P E N C V _ M O D U L E _ $ { d e p } _ L O C A T I O N # OpenCV modules
)
2017-04-25 21:48:50 +08:00
# nothing
2015-05-19 21:15:54 +08:00
else ( )
2017-04-25 21:48:50 +08:00
get_target_property ( _output ${ dep } IMPORTED_LOCATION )
if ( NOT _output )
get_target_property ( _output ${ dep } ARCHIVE_OUTPUT_DIRECTORY )
get_target_property ( _output_name ${ dep } OUTPUT_NAME )
if ( NOT _output_name )
set ( _output_name "${dep}" )
endif ( )
else ( )
get_filename_component ( _output_name "${_output}" NAME )
endif ( )
string ( FIND "${_output}" "${CMAKE_BINARY_DIR}" _POS )
if ( _POS EQUAL 0 )
ocv_get_libname ( _libname "${_output_name}" )
2017-08-17 06:49:17 +08:00
list ( INSERT ${ _3rdparty } 0 ${ dep } )
2017-04-25 21:48:50 +08:00
else ( )
if ( _output )
list ( INSERT ${ _extra } 0 ${ _output } )
else ( )
list ( INSERT ${ _extra } 0 ${ dep } )
endif ( )
endif ( )
2015-05-19 21:15:54 +08:00
endif ( )
2015-04-08 19:15:20 +08:00
else ( )
list ( INSERT ${ _extra } 0 ${ dep } )
endif ( )
2015-04-06 21:12:00 +08:00
endif ( )
endforeach ( )
endforeach ( )
2015-12-12 20:15:41 +08:00
ocv_list_filterout ( ${ _modules } "^[\$]<" )
ocv_list_filterout ( ${ _3rdparty } "^[\$]<" )
ocv_list_filterout ( ${ _extra } "^[\$]<" )
2015-04-06 21:12:00 +08:00
# convert CMake lists to makefile literals
foreach ( lst ${ _modules } ${ _3rdparty } ${ _extra } )
ocv_list_unique ( ${ lst } )
ocv_list_reverse ( ${ lst } )
endforeach ( )
endmacro ( )
2015-06-05 17:39:56 +08:00
2014-12-12 23:21:57 +08:00
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 "${test_kind}" MATCHES "^(Accuracy|Performance|Sanity)$" )
message ( FATAL_ERROR "Unknown test kind : ${test_kind}" )
endif ( )
if ( NOT TARGET "${the_target}" )
message ( FATAL_ERROR "${the_target} is not a CMake target" )
endif ( )
string ( TOLOWER "${test_kind}" test_kind_lower )
set ( test_report_dir "${CMAKE_BINARY_DIR}/test-reports/${test_kind_lower}" )
file ( MAKE_DIRECTORY "${test_report_dir}" )
add_test ( NAME "${test_name}"
C O M M A N D " $ { t h e _ t a r g e t } "
" - - g t e s t _ o u t p u t = x m l : $ { t h e _ t a r g e t } . x m l "
$ { A R G N } )
set_tests_properties ( "${test_name}" PROPERTIES
L A B E L S " $ { O P E N C V _ M O D U L E _ $ { t h e _ m o d u l e } _ L A B E L } ; $ { t e s t _ k i n d } "
W O R K I N G _ D I R E C T O R Y " $ { t e s t _ r e p o r t _ d i r } " )
if ( OPENCV_TEST_DATA_PATH )
set_tests_properties ( "${test_name}" PROPERTIES
E N V I R O N M E N T " O P E N C V _ T E S T _ D A T A _ P A T H = $ { O P E N C V _ T E S T _ D A T A _ P A T H } " )
endif ( )
endif ( )
endfunction ( )
2016-11-30 01:28:59 +08:00
macro ( ocv_add_testdata basedir dest_subdir )
if ( BUILD_TESTS )
if ( NOT CMAKE_CROSSCOMPILING AND NOT INSTALL_TESTS )
file ( COPY ${ basedir } /
D E S T I N A T I O N $ { C M A K E _ B I N A R Y _ D I R } / $ { O P E N C V _ T E S T _ D A T A _ I N S T A L L _ P A T H } / $ { d e s t _ s u b d i r }
2016-12-19 19:58:56 +08:00
$ { A R G N }
2016-11-30 01:28:59 +08:00
)
endif ( )
if ( INSTALL_TESTS )
install ( DIRECTORY ${ basedir } /
2017-07-25 11:56:03 +08:00
D E S T I N A T I O N $ { O P E N C V _ T E S T _ D A T A _ I N S T A L L _ P A T H } / $ { d e s t _ s u b d i r }
2016-12-19 19:58:56 +08:00
C O M P O N E N T " t e s t s "
2016-11-30 01:28:59 +08:00
$ { A R G N }
)
endif ( )
endif ( )
endmacro ( )
2017-06-20 18:55:17 +08:00
macro ( ocv_generate_vs_version_file DESTINATION )
cmake_parse_arguments ( VS_VER "" "NAME;FILEDESCRIPTION;FILEVERSION;INTERNALNAME;COPYRIGHT;ORIGINALFILENAME;PRODUCTNAME;PRODUCTVERSION;COMMENTS;FILEVERSION_QUAD;PRODUCTVERSION_QUAD" "" ${ ARGN } )
macro ( __vs_ver_update_variable name )
if ( VS_VER_NAME AND DEFINED OPENCV_ ${ VS_VER_NAME } _VS_VER_ ${ name } )
set ( OPENCV_VS_VER_ ${ name } "${OPENCV_${VS_VER_NAME}_VS_VER_${name}}" )
elseif ( VS_VER_ ${ name } )
set ( OPENCV_VS_VER_ ${ name } "${VS_VER_${name}}" )
endif ( )
endmacro ( )
__vs_ver_update_variable ( FILEVERSION_QUAD )
__vs_ver_update_variable ( PRODUCTVERSION_QUAD )
macro ( __vs_ver_update_str_variable name )
if ( VS_VER_NAME AND DEFINED OPENCV_ ${ VS_VER_NAME } _VS_VER_ ${ name } )
set ( OPENCV_VS_VER_ ${ name } _STR "${OPENCV_${VS_VER_NAME}_VS_VER_${name}}" )
elseif ( VS_VER_ ${ name } )
set ( OPENCV_VS_VER_ ${ name } _STR "${VS_VER_${name}}" )
endif ( )
endmacro ( )
__vs_ver_update_str_variable ( FILEDESCRIPTION )
__vs_ver_update_str_variable ( FILEVERSION )
__vs_ver_update_str_variable ( INTERNALNAME )
__vs_ver_update_str_variable ( COPYRIGHT )
__vs_ver_update_str_variable ( ORIGINALFILENAME )
__vs_ver_update_str_variable ( PRODUCTNAME )
__vs_ver_update_str_variable ( PRODUCTVERSION )
__vs_ver_update_str_variable ( COMMENTS )
if ( OPENCV_VS_VER_COPYRIGHT_STR )
set ( OPENCV_VS_VER_HAVE_COPYRIGHT_STR 1 )
else ( )
set ( OPENCV_VS_VER_HAVE_COPYRIGHT_STR 0 )
endif ( )
if ( OPENCV_VS_VER_COMMENTS_STR )
set ( OPENCV_VS_VER_HAVE_COMMENTS_STR 1 )
else ( )
set ( OPENCV_VS_VER_HAVE_COMMENTS_STR 0 )
endif ( )
configure_file ( "${OpenCV_SOURCE_DIR}/cmake/templates/vs_version.rc.in" "${DESTINATION}" @ONLY )
endmacro ( )
2017-08-17 06:49:17 +08:00
macro ( ocv_cmake_script_append_var content_var )
foreach ( var_name ${ ARGN } )
set ( ${ content_var } " ${ ${content_var } }
set ( ${ var_name } \"${${var_name}}\")
" )
endforeach ( )
endmacro ( )
2018-01-03 09:40:22 +08:00
macro ( ocv_copyfiles_append_file list_var src dst )
list ( LENGTH ${ list_var } __id )
list ( APPEND ${ list_var } ${ __id } )
set ( ${ list_var } _SRC_ ${ __id } "${src}" )
set ( ${ list_var } _DST_ ${ __id } "${dst}" )
endmacro ( )
macro ( ocv_copyfiles_append_dir list_var src dst )
set ( __glob ${ ARGN } )
list ( LENGTH ${ list_var } __id )
list ( APPEND ${ list_var } ${ __id } )
set ( ${ list_var } _SRC_ ${ __id } "${src}" )
set ( ${ list_var } _DST_ ${ __id } "${dst}" )
set ( ${ list_var } _MODE_ ${ __id } "COPYDIR" )
if ( __glob )
set ( ${ list_var } _GLOB_ ${ __id } ${ __glob } )
endif ( )
endmacro ( )
macro ( ocv_copyfiles_make_config_string content_var list_var )
set ( var_name "${list_var}" )
set ( ${ content_var } " ${ ${content_var } }
set ( ${ var_name } \"${${var_name}}\")
" )
foreach ( __id ${ ${list_var } } )
set ( ${ content_var } " ${ ${content_var } }
set ( ${ list_var } _SRC_ ${ __id } \"${${list_var}_SRC_${__id}}\")
set ( ${ list_var } _DST_ ${ __id } \"${${list_var}_DST_${__id}}\")
" )
if ( DEFINED ${ list_var } _MODE_ ${ __id } )
set ( ${ content_var } "${${content_var}}set(${list_var}_MODE_${__id} \" ${ ${list_var } _MODE_ ${ __id } }\ ")\n" )
endif ( )
if ( DEFINED ${ list_var } _GLOB_ ${ __id } )
set ( ${ content_var } "${${content_var}}set(${list_var}_GLOB_${__id} \" ${ ${list_var } _GLOB_ ${ __id } }\ ")\n" )
endif ( )
endforeach ( )
endmacro ( )
macro ( ocv_copyfiles_make_config_file filename_var list_var )
ocv_copyfiles_make_config_string ( ${ list_var } _CONFIG ${ list_var } )
set ( ${ filename_var } "${CMAKE_CURRENT_BINARY_DIR}/copyfiles-${list_var}.cmake" )
file ( WRITE "${${filename_var}}" "${${list_var}_CONFIG}" )
endmacro ( )
macro ( ocv_copyfiles_add_forced_target target list_var comment_str )
ocv_copyfiles_make_config_file ( CONFIG_FILE ${ list_var } )
ocv_cmake_byproducts ( __byproducts BYPRODUCTS "${OPENCV_DEPHELPER}/${target}" )
add_custom_target ( ${ target }
$ { _ _ b y p r o d u c t s } # required for add_custom_target() by ninja
C O M M A N D $ { C M A K E _ C O M M A N D }
" - D C O N F I G _ F I L E : P A T H = $ { C O N F I G _ F I L E } "
" - D C O P Y L I S T _ V A R : S T R I N G = $ { l i s t _ v a r } "
" - D D E P H E L P E R = $ { O P E N C V _ D E P H E L P E R } / $ { t a r g e t } "
- P " $ { O p e n C V _ S O U R C E _ D I R } / c m a k e / c o p y _ f i l e s . c m a k e "
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ B I N A R Y _ D I R }
C O M M E N T " $ { c o m m e n t _ s t r } "
D E P E N D S " $ { O p e n C V _ S O U R C E _ D I R } / c m a k e / c o p y _ f i l e s . c m a k e "
# ninja warn about file(WRITE): "${SRC_COPY_CONFIG_FILE}"
)
endmacro ( )
macro ( ocv_copyfiles_add_target target list_var comment_str )
set ( deps ${ ARGN } )
ocv_copyfiles_make_config_file ( CONFIG_FILE ${ list_var } )
add_custom_command ( OUTPUT "${OPENCV_DEPHELPER}/${target}"
C O M M A N D $ { C M A K E _ C O M M A N D }
" - D C O N F I G _ F I L E : P A T H = $ { C O N F I G _ F I L E } "
" - D C O P Y L I S T _ V A R : S T R I N G = $ { l i s t _ v a r } "
" - D D E P H E L P E R = $ { O P E N C V _ D E P H E L P E R } / $ { t a r g e t } "
- P " $ { O p e n C V _ S O U R C E _ D I R } / c m a k e / c o p y _ f i l e s . c m a k e "
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ B I N A R Y _ D I R }
C O M M E N T " $ { c o m m e n t _ s t r } "
D E P E N D S " $ { O p e n C V _ S O U R C E _ D I R } / c m a k e / c o p y _ f i l e s . c m a k e " $ { d e p s }
# ninja warn about file(WRITE): "${SRC_COPY_CONFIG_FILE}"
)
add_custom_target ( ${ target } DEPENDS "${OPENCV_DEPHELPER}/${target}" )
endmacro ( )
2018-01-18 21:37:19 +08:00
2018-02-12 19:48:20 +08:00
macro ( ocv_get_smart_file_name output_var fpath )
ocv_is_subdir ( __subir "${OpenCV_BINARY_DIR}" "${fpath}" )
if ( __subir )
file ( RELATIVE_PATH ${ output_var } "${OpenCV_BINARY_DIR}" "${fpath}" )
set ( ${ output_var } "<BUILD>/${${output_var}}" )
else ( )
ocv_is_subdir ( __subir "${OpenCV_SOURCE_DIR}" "${fpath}" )
if ( __subir )
file ( RELATIVE_PATH ${ output_var } "${OpenCV_SOURCE_DIR}" "${fpath}" )
else ( )
set ( ${ output_var } "${fpath}" )
endif ( )
endif ( )
unset ( __subir )
endmacro ( )
2018-01-18 21:37:19 +08:00
# Needed by install(DIRECTORY ...)
if ( NOT CMAKE_VERSION VERSION_LESS 3.1 )
set ( compatible_MESSAGE_NEVER MESSAGE_NEVER )
else ( )
set ( compatible_MESSAGE_NEVER "" )
endif ( )
2018-04-28 20:46:56 +08:00
macro ( ocv_git_describe var_name path )
if ( GIT_FOUND )
2018-07-02 09:45:28 +08:00
execute_process ( COMMAND "${GIT_EXECUTABLE}" describe --tags --exact-match --dirty
2018-04-28 20:46:56 +08:00
W O R K I N G _ D I R E C T O R Y " $ { p a t h } "
O U T P U T _ V A R I A B L E $ { v a r _ n a m e }
R E S U L T _ V A R I A B L E G I T _ R E S U L T
E R R O R _ Q U I E T
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
if ( NOT GIT_RESULT EQUAL 0 )
execute_process ( COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "[0-9].[0-9].[0-9]*" --exclude "[^-]*-cvsdk"
W O R K I N G _ D I R E C T O R Y " $ { p a t h } "
O U T P U T _ V A R I A B L E $ { v a r _ n a m e }
R E S U L T _ V A R I A B L E G I T _ R E S U L T
E R R O R _ Q U I E T
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
if ( NOT GIT_RESULT EQUAL 0 ) # --exclude is not supported by 'git'
# match only tags with complete OpenCV versions (ignores -alpha/-beta/-rc suffixes)
execute_process ( COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty --match "[0-9].[0-9]*[0-9]"
W O R K I N G _ D I R E C T O R Y " $ { p a t h } "
O U T P U T _ V A R I A B L E $ { v a r _ n a m e }
R E S U L T _ V A R I A B L E G I T _ R E S U L T
E R R O R _ Q U I E T
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
if ( NOT GIT_RESULT EQUAL 0 )
set ( ${ var_name } "unknown" )
endif ( )
endif ( )
endif ( )
else ( )
set ( ${ var_name } "unknown" )
endif ( )
endmacro ( )
2019-03-16 19:50:23 +08:00
# ocv_update_file(filepath content [VERBOSE])
# - write content to file
# - will not change modification time in case when file already exists and content has not changed
function ( ocv_update_file filepath content )
if ( EXISTS "${filepath}" )
file ( READ "${filepath}" actual_content )
else ( )
set ( actual_content "" )
endif ( )
if ( "${actual_content}" STREQUAL "${content}" )
if ( ";${ARGN};" MATCHES ";VERBOSE;" )
message ( STATUS "${filepath} contains the same content" )
endif ( )
else ( )
file ( WRITE "${filepath}" "${content}" )
endif ( )
endfunction ( )
2020-10-28 03:00:25 +08:00
if ( NOT BUILD_SHARED_LIBS AND ( CMAKE_VERSION VERSION_LESS "3.14.0" ) )
ocv_update ( OPENCV_3RDPARTY_EXCLUDE_FROM_ALL "" ) # avoid CMake warnings: https://gitlab.kitware.com/cmake/cmake/-/issues/18938
else ( )
ocv_update ( OPENCV_3RDPARTY_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL" )
endif ( )