2012-01-03 21:48:12 +08:00
|
|
|
# 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)
|
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()
|
|
|
|
|
2012-03-03 23:49:23 +08:00
|
|
|
#added include directories in such way that directories from the OpenCV source tree go first
|
|
|
|
macro(ocv_include_directories)
|
|
|
|
set(__add_before "")
|
|
|
|
foreach(dir ${ARGN})
|
|
|
|
get_filename_component(__abs_dir "${dir}" ABSOLUTE)
|
|
|
|
if("${__abs_dir}" MATCHES "^${OpenCV_SOURCE_DIR}" OR "${__abs_dir}" MATCHES "^${OpenCV_BINARY_DIR}")
|
|
|
|
list(APPEND __add_before "${dir}")
|
|
|
|
else()
|
|
|
|
include_directories(AFTER "${dir}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
include_directories(BEFORE ${__add_before})
|
|
|
|
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:
|
2012-02-22 22:04:59 +08:00
|
|
|
# option(<option_variable> "help string describing the option" <initial value or boolean expression> [IF <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 "")
|
|
|
|
set(__varname "__value")
|
|
|
|
foreach(arg ${ARGN})
|
|
|
|
if(arg STREQUAL "IF" OR arg STREQUAL "if")
|
|
|
|
set(__varname "__condition")
|
|
|
|
else()
|
|
|
|
list(APPEND ${__varname} ${arg})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
unset(__varname)
|
2012-02-03 19:26:49 +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})
|
2012-02-22 22:04:59 +08:00
|
|
|
if("${__value}" MATCHES ";")
|
|
|
|
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()
|
2012-02-22 22:04:59 +08:00
|
|
|
unset(${variable} CACHE)
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|
2012-02-22 22:04:59 +08:00
|
|
|
unset(__condition)
|
|
|
|
unset(__value)
|
2012-01-03 21:48:12 +08:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
|
|
|
# Macros that checks if module have been installed.
|
|
|
|
# After it adds module to build and define
|
|
|
|
# constants passed as second arg
|
|
|
|
macro(CHECK_MODULE module_name define)
|
2012-02-22 22:04:59 +08:00
|
|
|
set(${define} 0)
|
|
|
|
if(PKG_CONFIG_FOUND)
|
|
|
|
set(ALIAS ALIASOF_${module_name})
|
|
|
|
set(ALIAS_FOUND ${ALIAS}_FOUND)
|
|
|
|
set(ALIAS_INCLUDE_DIRS ${ALIAS}_INCLUDE_DIRS)
|
|
|
|
set(ALIAS_LIBRARY_DIRS ${ALIAS}_LIBRARY_DIRS)
|
|
|
|
set(ALIAS_LIBRARIES ${ALIAS}_LIBRARIES)
|
|
|
|
|
|
|
|
PKG_CHECK_MODULES(${ALIAS} ${module_name})
|
|
|
|
|
|
|
|
if(${ALIAS_FOUND})
|
|
|
|
set(${define} 1)
|
|
|
|
foreach(P "${ALIAS_INCLUDE_DIRS}")
|
|
|
|
if(${P})
|
|
|
|
list(APPEND HIGHGUI_INCLUDE_DIRS ${${P}})
|
2012-01-03 21:48:12 +08:00
|
|
|
endif()
|
2012-02-22 22:04:59 +08:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
foreach(P "${ALIAS_LIBRARY_DIRS}")
|
|
|
|
if(${P})
|
|
|
|
list(APPEND HIGHGUI_LIBRARY_DIRS ${${P}})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
list(APPEND HIGHGUI_LIBRARIES ${${ALIAS_LIBRARIES}})
|
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()
|
|
|
|
|
2012-02-22 22:04:59 +08:00
|
|
|
|
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)
|
|
|
|
message(STATUS "${text}")
|
|
|
|
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}")
|
|
|
|
message(STATUS "${status_text}" "${status_then}")
|
|
|
|
else()
|
|
|
|
string(REPLACE ";" " " status_else "${status_else}")
|
|
|
|
message(STATUS "${status_text}" "${status_else}")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
string(REPLACE ";" " " status_cond "${status_cond}")
|
|
|
|
message(STATUS "${status_text}" "${status_cond}")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(STATUS "${text}")
|
|
|
|
endif()
|
2012-02-24 04:05:27 +08:00
|
|
|
endfunction()
|
2012-02-03 19:26:49 +08:00
|
|
|
|
2012-02-22 22:04:59 +08:00
|
|
|
|
2012-02-03 19:26:49 +08:00
|
|
|
# splits cmake libraries list of format "general;item1;debug;item2;release;item3" to two lists
|
|
|
|
macro(ocv_split_libs_list lst lstdbg lstopt)
|
2012-02-22 22:04:59 +08:00
|
|
|
set(${lstdbg} "")
|
|
|
|
set(${lstopt} "")
|
|
|
|
set(perv_keyword "")
|
|
|
|
foreach(word ${${lst}})
|
|
|
|
if(word STREQUAL "debug" OR word STREQUAL "optimized")
|
|
|
|
set(perv_keyword ${word})
|
|
|
|
elseif(word STREQUAL "general")
|
|
|
|
set(perv_keyword "")
|
|
|
|
elseif(perv_keyword STREQUAL "debug")
|
|
|
|
list(APPEND ${lstdbg} "${word}")
|
|
|
|
set(perv_keyword "")
|
|
|
|
elseif(perv_keyword STREQUAL "optimized")
|
|
|
|
list(APPEND ${lstopt} "${word}")
|
|
|
|
set(perv_keyword "")
|
|
|
|
else()
|
|
|
|
list(APPEND ${lstdbg} "${word}")
|
|
|
|
list(APPEND ${lstopt} "${word}")
|
|
|
|
set(perv_keyword "")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2012-02-03 19:26:49 +08:00
|
|
|
endmacro()
|
|
|
|
|
2012-02-22 22:04:59 +08:00
|
|
|
|
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()
|
|
|
|
|
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-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
|
|
|
|
|
|
|
|
|
|
|
# get absolute path with symlinks resolved
|
|
|
|
macro(ocv_get_real_path VAR PATHSTR)
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 2.8)
|
|
|
|
get_filename_component(${VAR} "${PATHSTR}" ABSOLUTE)
|
|
|
|
else()
|
|
|
|
get_filename_component(${VAR} "${PATHSTR}" REALPATH)
|
|
|
|
endif()
|
|
|
|
endmacro()
|