+# Debugging function
+function(ocv_cmake_dump_vars)
+ cmake_parse_arguments(DUMP "" "TOFILE" "" ${ARGN})
+ set(regex "${DUMP_UNPARSED_ARGUMENTS}")
+ get_cmake_property(_variableNames VARIABLES)
+ set(VARS "")
+ foreach(_variableName ${_variableNames})
+ if(_variableName MATCHES "${regex}")
+ set(VARS "${VARS}${_variableName}=${${_variableName}}\n")
+ endif()
+ endforeach()
+ if(DUMP_TOFILE)
+ file(WRITE ${CMAKE_BINARY_DIR}/${DUMP_TOFILE} "${VARS}")
+ else()
+ message(AUTHOR_WARNING "${VARS}")
+ endif()
+endfunction()
+
+
# Search packages for host system instead of packages for target system
# in case of cross compilation thess macro should be defined by toolchain file
if(NOT COMMAND find_host_package)
endmacro()
endif()
+# 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()
+
macro(ocv_check_environment_variables)
foreach(_var ${ARGN})
if(NOT DEFINED ${_var} AND DEFINED ENV{${_var}})
endmacro()
+# convert list of paths to libraries names without lib prefix
+macro(ocv_convert_to_lib_name var)
+ set(__tmp "")
+ foreach(path ${ARGN})
+ get_filename_component(__tmp_name "${path}" NAME_WE)
+ string(REGEX REPLACE "^lib" "" __tmp_name ${__tmp_name})
+ list(APPEND __tmp "${__tmp_name}")
+ endforeach()
+ set(${var} ${__tmp})
+ unset(__tmp)
+ unset(__tmp_name)
+endmacro()
+
+
# add install command
function(ocv_install_target)
install(TARGETS ${ARGN})
set(isArchive 0)
set(isDst 0)
+ unset(__dst)
foreach(e ${ARGN})
if(isDst EQUAL 1)
- set(DST "${e}")
+ set(__dst "${e}")
break()
endif()
if(isArchive EQUAL 1 AND e STREQUAL "DESTINATION")
endif()
endforeach()
-# message(STATUS "Process ${__target} dst=${DST}...")
- if(NOT DEFINED DST)
- set(DST "OPENCV_LIB_INSTALL_PATH")
- endif()
-
- get_target_property(fname ${__target} LOCATION_DEBUG)
- string(REPLACE ".lib" ".pdb" fname "${fname}")
- install(FILES ${fname} DESTINATION ${DST} CONFIGURATIONS Debug)
+# message(STATUS "Process ${__target} dst=${__dst}...")
+ if(DEFINED __dst)
+ get_target_property(fname ${__target} LOCATION_DEBUG)
+ if(fname MATCHES "\\.lib$")
+ string(REGEX REPLACE "\\.lib$" ".pdb" fname "${fname}")
+ install(FILES ${fname} DESTINATION ${__dst} CONFIGURATIONS Debug)
+ endif()
- get_target_property(fname ${__target} LOCATION_RELEASE)
- string(REPLACE ".lib" ".pdb" fname "${fname}")
- install(FILES ${fname} DESTINATION ${DST} CONFIGURATIONS Release)
+ get_target_property(fname ${__target} LOCATION_RELEASE)
+ if(fname MATCHES "\\.lib$")
+ string(REGEX REPLACE "\\.lib$" ".pdb" fname "${fname}")
+ install(FILES ${fname} DESTINATION ${__dst} CONFIGURATIONS Release)
+ endif()
+ endif()
endif()
endif()
endfunction()
################################################################################################
# short command to setup source group
function(ocv_source_group group)
- cmake_parse_arguments(OCV_SOURCE_GROUP "" "" "GLOB" ${ARGN})
- file(GLOB srcs ${OCV_SOURCE_GROUP_GLOB})
- source_group(${group} FILES ${srcs})
+ 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()
endfunction()