Johannes Ruehle 12 tahun lalu
induk
melakukan
c1f29c6142

+ 5 - 2
CMakeLists.txt

@@ -26,8 +26,11 @@ ENDIF()
 # add the binary tree to the search path for include files
 #include_directories ("${PROJECT_BINARY_DIR}")
 
-SET(CMAKE_USE_RELATIVE_PATHS ON)
-check_symbol_exists("__assert_fail" "assert.h" HAVE_ASSERT_FAIL)
+#SET(CMAKE_USE_RELATIVE_PATHS ON)
+#check_symbol_exists("__assert_fail" "assert.h" HAVE_ASSERT_FAIL)
+
+include(cmake/OpenCVUtils.cmake REQUIRE)
+include(cmake/NiceModules.cmake REQUIRE)
 
 
 INCLUDE_DIRECTORIES(".")

+ 209 - 0
cmake/NiceModules.cmake

@@ -0,0 +1,209 @@
+# clean flags for modules enabled on previous cmake run
+# this is necessary to correctly handle modules removal
+foreach(mod ${OPENCV_MODULES_BUILD} ${OPENCV_MODULES_DISABLED_USER} ${OPENCV_MODULES_DISABLED_AUTO} ${OPENCV_MODULES_DISABLED_FORCE})
+  if(HAVE_${mod})
+    unset(HAVE_${mod} CACHE)
+  endif()
+  unset(OPENCV_MODULE_${mod}_REQ_DEPS CACHE)
+  unset(OPENCV_MODULE_${mod}_OPT_DEPS CACHE)
+endforeach()
+
+# clean modules info which needs to be recalculated
+set(OPENCV_MODULES_PUBLIC         "" CACHE INTERNAL "List of OpenCV modules marked for export")
+set(OPENCV_MODULES_BUILD          "" CACHE INTERNAL "List of OpenCV modules included into the build")
+set(OPENCV_MODULES_DISABLED_USER  "" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
+set(OPENCV_MODULES_DISABLED_AUTO  "" CACHE INTERNAL "List of OpenCV modules implicitly disabled due to dependencies")
+set(OPENCV_MODULES_DISABLED_FORCE "" CACHE INTERNAL "List of OpenCV modules which can not be build in current configuration")
+
+
+
+
+
+# collect modules from specified directories
+# NB: must be called only once!
+macro(ocv_glob_modules)
+  if(DEFINED OPENCV_INITIAL_PASS)
+    message(FATAL_ERROR "OpenCV has already loaded its modules. Calling ocv_glob_modules second time is not allowed.")
+  endif()
+  set(__directories_observed "")
+
+  # collect modules
+  set(OPENCV_INITIAL_PASS ON)
+  foreach(__path ${ARGN})
+    ocv_get_real_path(__path "${__path}")
+
+    list(FIND __directories_observed "${__path}" __pathIdx)
+    if(__pathIdx GREATER -1)
+      message(FATAL_ERROR "The directory ${__path} is observed for OpenCV modules second time.")
+    endif()
+    list(APPEND __directories_observed "${__path}")
+
+    file(GLOB __ocvmodules RELATIVE "${__path}" "${__path}/*")
+    if(__ocvmodules)
+      list(SORT __ocvmodules)
+      foreach(mod ${__ocvmodules})
+        ocv_get_real_path(__modpath "${__path}/${mod}")
+	message(STATUS "${__modpath}")
+        if(EXISTS "${__modpath}/CMakeLists.txt")
+	  message(STATUS "${__modpath} adding subdir")
+          list(FIND __directories_observed "${__modpath}" __pathIdx)
+          if(__pathIdx GREATER -1)
+            message(FATAL_ERROR "The module from ${__modpath} is already loaded.")
+          endif()
+          list(APPEND __directories_observed "${__modpath}")
+
+          if(OCV_MODULE_RELOCATE_ON_INITIAL_PASS)
+            #file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
+            file(COPY "${__modpath}/CMakeLists.txt" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
+            add_subdirectory("${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
+            if("${OPENCV_MODULE_opencv_${mod}_LOCATION}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
+              set(OPENCV_MODULE_opencv_${mod}_LOCATION "${__modpath}" CACHE PATH "" FORCE)
+            endif()
+          else()
+            add_subdirectory("${__modpath}" "${CMAKE_CURRENT_BINARY_DIR}/${mod}/.${mod}")
+          endif()
+        endif()
+      endforeach()
+    endif()
+  endforeach()
+  ocv_clear_vars(__ocvmodules __directories_observed __path __modpath __pathIdx)
+
+  # resolve dependencies
+#  __ocv_flatten_module_dependencies()
+
+  # create modules
+  set(OPENCV_INITIAL_PASS OFF PARENT_SCOPE)
+  set(OPENCV_INITIAL_PASS OFF)
+  foreach(m ${OPENCV_MODULES_BUILD})
+    message(STATUS "${OPENCV_MODULES_BUILD}")
+    if(m MATCHES "^opencv_")
+      string(REGEX REPLACE "^opencv_" "" __shortname "${m}")
+      add_subdirectory("${OPENCV_MODULE_${m}_LOCATION}" "${CMAKE_CURRENT_BINARY_DIR}/${__shortname}")
+    endif()
+  endforeach()
+  unset(__shortname)
+endmacro()
+
+
+# adds dependencies to OpenCV module
+# Usage:
+#   add_dependencies(opencv_<name> [REQUIRED] [<list of dependencies>] [OPTIONAL <list of modules>])
+# Notes:
+# * <list of dependencies> - can include full names of modules or full pathes to shared/static libraries or cmake targets
+macro(ocv_add_dependencies full_modname)
+  #we don't clean the dependencies here to allow this macro several times for every module
+  foreach(d "REQUIRED" ${ARGN})
+    if(d STREQUAL "REQUIRED")
+      set(__depsvar OPENCV_MODULE_${full_modname}_REQ_DEPS)
+    elseif(d STREQUAL "OPTIONAL")
+      set(__depsvar OPENCV_MODULE_${full_modname}_OPT_DEPS)
+    else()
+      list(APPEND ${__depsvar} "${d}")
+    endif()
+  endforeach()
+  unset(__depsvar)
+
+  ocv_list_unique(OPENCV_MODULE_${full_modname}_REQ_DEPS)
+  ocv_list_unique(OPENCV_MODULE_${full_modname}_OPT_DEPS)
+
+  set(OPENCV_MODULE_${full_modname}_REQ_DEPS ${OPENCV_MODULE_${full_modname}_REQ_DEPS} CACHE INTERNAL "Required dependencies of ${full_modname} module")
+  set(OPENCV_MODULE_${full_modname}_OPT_DEPS ${OPENCV_MODULE_${full_modname}_OPT_DEPS} CACHE INTERNAL "Optional dependencies of ${full_modname} module")
+endmacro()
+
+
+# declare new OpenCV module in current folder
+# Usage:
+#   ocv_add_module(<name> [INTERNAL|BINDINGS] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
+# Example:
+#   ocv_add_module(yaom INTERNAL opencv_core opencv_highgui opencv_flann OPTIONAL opencv_gpu)
+macro(ocv_add_module _name)
+  string(TOLOWER "${_name}" name)
+  string(REGEX REPLACE "^opencv_" "" ${name} "${name}")
+  set(the_module opencv_${name})
+
+  # the first pass - collect modules info, the second pass - create targets
+  if(OPENCV_INITIAL_PASS)
+    #guard agains redefinition
+    if(";${OPENCV_MODULES_BUILD};${OPENCV_MODULES_DISABLED_USER};" MATCHES ";${the_module};")
+      message(FATAL_ERROR "Redefinition of the ${the_module} module.
+  at:                    ${CMAKE_CURRENT_SOURCE_DIR}
+  previously defined at: ${OPENCV_MODULE_${the_module}_LOCATION}
+")
+    endif()
+
+    if(NOT DEFINED the_description)
+      set(the_description "The ${name} OpenCV module")
+    endif()
+
+    if(NOT DEFINED BUILD_${the_module}_INIT)
+      set(BUILD_${the_module}_INIT ON)
+    endif()
+
+    # create option to enable/disable this module
+#    option(BUILD_${the_module} "Include ${the_module} module into the OpenCV build" ${BUILD_${the_module}_INIT})
+
+    # remember the module details
+    set(OPENCV_MODULE_${the_module}_DESCRIPTION "${the_description}" CACHE INTERNAL "Brief description of ${the_module} module")
+    set(OPENCV_MODULE_${the_module}_LOCATION    "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Location of ${the_module} module sources")
+
+    # parse list of dependencies
+    if("${ARGV1}" STREQUAL "INTERNAL" OR "${ARGV1}" STREQUAL "BINDINGS")
+      set(OPENCV_MODULE_${the_module}_CLASS "${ARGV1}" CACHE INTERNAL "The cathegory of the module")
+      set(__ocv_argn__ ${ARGN})
+      list(REMOVE_AT __ocv_argn__ 0)
+      ocv_add_dependencies(${the_module} ${__ocv_argn__})
+      unset(__ocv_argn__)
+    else()
+      set(OPENCV_MODULE_${the_module}_CLASS "PUBLIC" CACHE INTERNAL "The cathegory of the module")
+      ocv_add_dependencies(${the_module} ${ARGN})
+      if(BUILD_${the_module})
+        set(OPENCV_MODULES_PUBLIC ${OPENCV_MODULES_PUBLIC} "${the_module}" CACHE INTERNAL "List of OpenCV modules marked for export")
+      endif()
+    endif()
+
+    # add self to the world dependencies
+    if(NOT DEFINED OPENCV_MODULE_IS_PART_OF_WORLD AND NOT OPENCV_MODULE_${the_module}_CLASS STREQUAL "BINDINGS" OR OPENCV_MODULE_IS_PART_OF_WORLD)
+      ocv_add_dependencies(opencv_world OPTIONAL ${the_module})
+    endif()
+
+    if(BUILD_${the_module})
+      set(OPENCV_MODULES_BUILD ${OPENCV_MODULES_BUILD} "${the_module}" CACHE INTERNAL "List of OpenCV modules included into the build")
+    else()
+      set(OPENCV_MODULES_DISABLED_USER ${OPENCV_MODULES_DISABLED_USER} "${the_module}" CACHE INTERNAL "List of OpenCV modules explicitly disabled by user")
+    endif()
+
+    # TODO: add submodules if any
+
+    # stop processing of current file
+#    return()
+  else(OPENCV_INITIAL_PASS)
+    if(NOT BUILD_${the_module})
+      return() # extra protection from redefinition
+    endif()
+    project(${the_module})
+  endif(OPENCV_INITIAL_PASS)
+endmacro()
+
+
+# setup include paths for the list of passed modules
+macro(ocv_include_modules)
+  foreach(d ${ARGN})
+    if(d MATCHES "^opencv_" AND HAVE_${d})
+      if (EXISTS "${OPENCV_MODULE_${d}_LOCATION}/include")
+        ocv_include_directories("${OPENCV_MODULE_${d}_LOCATION}/include")
+      endif()
+    elseif(EXISTS "${d}")
+      ocv_include_directories("${d}")
+    endif()
+  endforeach()
+endmacro()
+
+# setup include path for OpenCV headers for specified module
+# ocv_module_include_directories(<extra include directories/extra include modules>)
+macro(ocv_module_include_directories)
+  ocv_include_directories("${OPENCV_MODULE_${the_module}_LOCATION}/include"
+                          "${OPENCV_MODULE_${the_module}_LOCATION}/src"
+                          "${CMAKE_CURRENT_BINARY_DIR}" # for precompiled headers
+                          )
+  ocv_include_modules(${OPENCV_MODULE_${the_module}_DEPS} ${ARGN})
+endmacro()

+ 499 - 0
cmake/OpenCVUtils.cmake

@@ -0,0 +1,499 @@
+# 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)
+  macro(find_host_package)
+    find_package(${ARGN})
+  endmacro()
+endif()
+if(NOT COMMAND find_host_program)
+  macro(find_host_program)
+    find_program(${ARGN})
+  endmacro()
+endif()
+
+# adds include directories in such way that directories from the OpenCV source tree go first
+function(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 SYSTEM "${dir}")
+    endif()
+  endforeach()
+  include_directories(BEFORE ${__add_before})
+endfunction()
+
+# clears all passed variables
+macro(ocv_clear_vars)
+  foreach(_var ${ARGN})
+    unset(${_var} CACHE)
+  endforeach()
+endmacro()
+
+set(OCV_COMPILER_FAIL_REGEX
+    "command line option .* is valid for .* but not for C\\+\\+" # GNU
+    "command line option .* is valid for .* but not for C" # GNU
+    "unrecognized .*option"                     # GNU
+    "unknown .*option"                          # Clang
+    "ignoring unknown option"                   # MSVC
+    "warning D9002"                             # MSVC, any lang
+    "option .*not supported"                    # Intel
+    "[Uu]nknown option"                         # HP
+    "[Ww]arning: [Oo]ption"                     # SunPro
+    "command option .* is not recognized"       # XL
+    "not supported in this configuration; ignored"       # AIX
+    "File with unknown suffix passed to linker" # PGI
+    "WARNING: unknown flag:"                    # Open64
+  )
+
+MACRO(ocv_check_compiler_flag LANG FLAG RESULT)
+  if(NOT DEFINED ${RESULT})
+    if("_${LANG}_" MATCHES "_CXX_")
+      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()
+    else()
+      unset(_fname)
+    endif()
+    if(_fname)
+      MESSAGE(STATUS "Performing Test ${RESULT}")
+      TRY_COMPILE(${RESULT}
+        ${CMAKE_BINARY_DIR}
+        "${_fname}"
+        COMPILE_DEFINITIONS "${FLAG}"
+        OUTPUT_VARIABLE OUTPUT)
+
+      FOREACH(_regex ${OCV_COMPILER_FAIL_REGEX})
+        IF("${OUTPUT}" MATCHES "${_regex}")
+          SET(${RESULT} 0)
+          break()
+        ENDIF()
+      ENDFOREACH()
+
+      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}")
+      ENDIF(${RESULT})
+    else()
+      SET(${RESULT} 0)
+    endif()
+  endif()
+ENDMACRO()
+
+macro(ocv_check_flag_support lang flag varname)
+  if("_${lang}_" MATCHES "_CXX_")
+    set(_lang CXX)
+  elseif("_${lang}_" MATCHES "_C_")
+    set(_lang C)
+  else()
+    set(_lang ${lang})
+  endif()
+
+  string(TOUPPER "${flag}" ${varname})
+  string(REGEX REPLACE "^(/|-)" "HAVE_${_lang}_" ${varname} "${${varname}}")
+  string(REGEX REPLACE " -|-|=| |\\." "_" ${varname} "${${varname}}")
+
+  ocv_check_compiler_flag("${_lang}" "${ARGN} ${flag}" ${${varname}})
+endmacro()
+
+# turns off warnings
+macro(ocv_warnings_disable)
+  if(NOT ENABLE_NOISY_WARNINGS)
+    set(_flag_vars "")
+    set(_msvc_warnings "")
+    set(_gxx_warnings "")
+    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})
+      endif()
+    endforeach()
+    if(MSVC AND _msvc_warnings AND _flag_vars)
+      foreach(var ${_flag_vars})
+        foreach(warning ${_msvc_warnings})
+          set(${var} "${${var}} ${warning}")
+        endforeach()
+      endforeach()
+    elseif(CV_COMPILER_IS_GNU AND _gxx_warnings AND _flag_vars)
+      foreach(var ${_flag_vars})
+        foreach(warning ${_gxx_warnings})
+          if(NOT warning MATCHES "^-Wno-")
+            string(REPLACE "${warning}" "" ${var} "${${var}}")
+            string(REPLACE "-W" "-Wno-" warning "${warning}")
+          endif()
+          ocv_check_flag_support(${var} "${warning}" _varname)
+          if(${_varname})
+            set(${var} "${${var}} ${warning}")
+          endif()
+        endforeach()
+      endforeach()
+    endif()
+    unset(_flag_vars)
+    unset(_msvc_warnings)
+    unset(_gxx_warnings)
+  endif(NOT ENABLE_NOISY_WARNINGS)
+endmacro()
+
+# Provides an option that the user can optionally select.
+# Can accept condition to control when option is available for user.
+# Usage:
+#   option(<option_variable> "help string describing the option" <initial value or boolean expression> [IF <condition>])
+macro(OCV_OPTION variable description value)
+  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)
+  if("${__condition}" STREQUAL "")
+    set(__condition 2 GREATER 1)
+  endif()
+
+  if(${__condition})
+    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()
+  else()
+    unset(${variable} CACHE)
+  endif()
+  unset(__condition)
+  unset(__value)
+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)
+  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}})
+        endif()
+      endforeach()
+
+      foreach(P "${ALIAS_LIBRARY_DIRS}")
+        if(${P})
+          list(APPEND HIGHGUI_LIBRARY_DIRS ${${P}})
+        endif()
+      endforeach()
+
+      list(APPEND HIGHGUI_LIBRARIES ${${ALIAS_LIBRARIES}})
+    endif()
+  endif()
+endmacro()
+
+
+set(OPENCV_BUILD_INFO_FILE "${OpenCV_BINARY_DIR}/version_string.tmp")
+file(REMOVE "${OPENCV_BUILD_INFO_FILE}")
+function(ocv_output_status msg)
+  message(STATUS "${msg}")
+  string(REPLACE "\\" "\\\\" msg "${msg}")
+  string(REPLACE "\"" "\\\"" msg "${msg}")
+  file(APPEND "${OPENCV_BUILD_INFO_FILE}" "\"${msg}\\n\"\n")
+endfunction()
+
+macro(ocv_finalize_status)
+  if(NOT OPENCV_SKIP_STATUS_FINALIZATION)
+    if(TARGET opencv_core)
+      execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENCV_BUILD_INFO_FILE}" "${opencv_core_BINARY_DIR}/version_string.inc" OUTPUT_QUIET)
+    endif()
+  endif()
+endmacro()
+
+
+# Status report function.
+# 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> )
+function(status text)
+  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()
+
+  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)
+      ocv_output_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}")
+        string(REGEX REPLACE "^[ \t]+" "" status_then "${status_then}")
+        ocv_output_status("${status_text} ${status_then}")
+      else()
+        string(REPLACE ";" " " status_else "${status_else}")
+        string(REGEX REPLACE "^[ \t]+" "" status_else "${status_else}")
+        ocv_output_status("${status_text} ${status_else}")
+      endif()
+    else()
+      string(REPLACE ";" " " status_cond "${status_cond}")
+      string(REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}")
+      ocv_output_status("${status_text} ${status_cond}")
+    endif()
+  else()
+    ocv_output_status("${text}")
+  endif()
+endfunction()
+
+
+# splits cmake libraries list of format "general;item1;debug;item2;release;item3" to two lists
+macro(ocv_split_libs_list lst lstdbg lstopt)
+  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()
+endmacro()
+
+
+# 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()
+
+
+# stable & safe duplicates removal macro
+macro(ocv_list_unique __lst)
+  if(${__lst})
+    list(REMOVE_DUPLICATES ${__lst})
+  endif()
+endmacro()
+
+
+# safe list reversal macro
+macro(ocv_list_reverse __lst)
+  if(${__lst})
+    list(REVERSE ${__lst})
+  endif()
+endmacro()
+
+
+# safe list sorting macro
+macro(ocv_list_sort __lst)
+  if(${__lst})
+    list(SORT ${__lst})
+  endif()
+endmacro()
+
+
+# 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()
+
+
+# gets and removes the first element from list
+macro(ocv_list_pop_front LST VAR)
+  if(${LST})
+    list(GET ${LST} 0 ${VAR})
+    list(REMOVE_AT ${LST} 0)
+  else()
+    set(${VAR} "")
+  endif()
+endmacro()
+
+
+# simple regex escaping routine (does not cover all cases!!!)
+macro(ocv_regex_escape var regex)
+  string(REGEX REPLACE "([+.*^$])" "\\\\1" ${var} "${regex}")
+endmacro()
+
+
+# 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()
+
+
+# convert list of paths to full paths
+macro(ocv_convert_to_full_paths VAR)
+  if(${VAR})
+    set(__tmp "")
+    foreach(path ${${VAR}})
+      get_filename_component(${VAR} "${path}" ABSOLUTE)
+      list(APPEND __tmp "${${VAR}}")
+    endforeach()
+    set(${VAR} ${__tmp})
+    unset(__tmp)
+  endif()
+endmacro()
+
+
+# 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})
+    if("${name}" STREQUAL "PARENT_SCOPE")
+      set(__parnet_scope ON)
+    elseif("${name}" STREQUAL "CACHE")
+      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})
+    if(NOT "${name}" STREQUAL "PARENT_SCOPE" AND NOT "${name}" STREQUAL "CACHE")
+      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
+macro(ocv_parse_header2 LIBNAME HDR_PATH VARNAME SCOPE)
+  set(${LIBNAME}_H "")
+  if(EXISTS "${HDR_PATH}")
+    file(STRINGS "${HDR_PATH}" ${LIBNAME}_H REGEX "^#define[ \t]+${VARNAME}[ \t]+\"[^\"]*\".*$" LIMIT_COUNT 1)
+  endif()
+  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" ${LIBNAME}_VERSION_MINOR  "${${LIBNAME}_H}")
+    string(REGEX REPLACE "^.*[ \t]${VARNAME}[ \t]+\"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ${LIBNAME}_VERSION_PATCH "${${LIBNAME}_H}")
+    set(${LIBNAME}_VERSION_MAJOR ${${LIBNAME}_VERSION_MAJOR} ${SCOPE})
+    set(${LIBNAME}_VERSION_MINOR ${${LIBNAME}_VERSION_MINOR} ${SCOPE})
+    set(${LIBNAME}_VERSION_PATCH ${${LIBNAME}_VERSION_PATCH} ${SCOPE})
+    set(${LIBNAME}_VERSION_STRING "${${LIBNAME}_VERSION_MAJOR}.${${LIBNAME}_VERSION_MINOR}.${${LIBNAME}_VERSION_PATCH}" ${SCOPE})
+
+    # 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]+).*$")
+      set(${LIBNAME}_VERSION_TWEAK "${CMAKE_MATCH_1}" ${SCOPE})
+      set(${LIBNAME}_VERSION_STRING "${${LIBNAME}_VERSION_STRING}.${${LIBNAME}_VERSION_TWEAK}" ${SCOPE})
+    endif()
+  else()
+    ocv_clear_vars(${LIBNAME}_VERSION_MAJOR
+                   ${LIBNAME}_VERSION_MAJOR
+                   ${LIBNAME}_VERSION_MINOR
+                   ${LIBNAME}_VERSION_PATCH
+                   ${LIBNAME}_VERSION_TWEAK
+                   ${LIBNAME}_VERSION_STRING)
+  endif()
+endmacro()

+ 0 - 9
core/CMakeDefinesConfig.h.in

@@ -1,9 +0,0 @@
-#ifndef CMAKEDEFINESCONFIG_H
-#define CMAKEDEFINESCONFIG_H
-
-#cmakedefine USE_TEST
-
-#cmakedefine WIN32
-
-
-#endif

+ 19 - 15
core/CMakeLists.txt

@@ -1,25 +1,29 @@
+set(NICE_CURR_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+message(STATUS "${NICE_CURR_DIR}")
+ocv_glob_modules(${NICE_CURR_DIR})
 
-CONFIGURE_FILE(
-  "CMakeDefinesConfig.h.in"
-  "${PROJECT_BINARY_DIR}/CMakeDefinesConfig.h"
-)
-include_directories("${PROJECT_BINARY_DIR}")
 
-INCLUDE_DIRECTORIES(basics)
-INCLUDE_DIRECTORIES(algebra)
-INCLUDE_DIRECTORIES(vector)
-INCLUDE_DIRECTORIES(optimization)
-INCLUDE_DIRECTORIES(image)
+#CONFIGURE_FILE(
+#  "CMakeDefinesConfig.h.in"
+#  "${PROJECT_BINARY_DIR}/CMakeDefinesConfig.h"
+#)
+#include_directories("${PROJECT_BINARY_DIR}")
+
+#INCLUDE_DIRECTORIES(basics)
+#INCLUDE_DIRECTORIES(algebra)
+#INCLUDE_DIRECTORIES(vector)
+#INCLUDE_DIRECTORIES(optimization)
+#INCLUDE_DIRECTORIES(image)
 #INCLUDE_DIRECTORIES(iceconversion)
 #INCLUDE_DIRECTORIES(imagedisplay)
 #INCLUDE_DIRECTORIES(matlabAccess)
 #INCLUDE_DIRECTORIES(progs)
 
-ADD_SUBDIRECTORY(basics)
-ADD_SUBDIRECTORY(algebra)
-ADD_SUBDIRECTORY(vector)
-ADD_SUBDIRECTORY(optimization)
-ADD_SUBDIRECTORY(image)
+#ADD_SUBDIRECTORY(basics)
+#ADD_SUBDIRECTORY(algebra)
+#ADD_SUBDIRECTORY(vector)
+#ADD_SUBDIRECTORY(optimization)
+#ADD_SUBDIRECTORY(image)
 
 #SET(core_src 
 #${core_basics_src} 

+ 0 - 0
core/algebra/CMakeLists.txt → core/algebra/CMakeLists.txt.old


+ 0 - 0
core/basics/CMakeLists.txt → core/basics/CMakeLists.txt.old


+ 0 - 0
core/image/CMakeLists.txt → core/image/CMakeLists.txt.old


+ 0 - 0
core/optimization/CMakeLists.txt → core/optimization/CMakeLists.txt.old


+ 7 - 14
core/vector/CMakeLists.txt

@@ -1,16 +1,9 @@
-SET(core_vector_src Algorithms.cpp Algorithms.tcc
-Distance.cpp
-Distance.tcc
-Eigen.tcc
-ippwrapper.cpp
-ippwrapper.tcc
-MatrixT.tcc
-RowMatrixT.tcc
-SparseVectorT.tcc
-VectorT.tcc
-VVector.cpp
-)
+message(STATUS "vector_location: ${OPENCV_MODULE_vector_LOCATION}")
 
-ADD_LIBRARY(core_vector ${NICE_BUILD_LIBS_STATIC_SHARED} ${core_vector_src})
+ocv_add_module(vector)
 
-INSTALL(TARGETS core_vector DESTINATION libs)
+message(STATUS "vector_location: ${OPENCV_MODULE_vector_LOCATION}")
+
+ocv_module_include_directories()
+#ocv_glob_module_sources()
+#ocv_create_module()

+ 16 - 0
core/vector/CMakeLists.txt.old

@@ -0,0 +1,16 @@
+SET(core_vector_src Algorithms.cpp Algorithms.tcc
+Distance.cpp
+Distance.tcc
+Eigen.tcc
+ippwrapper.cpp
+ippwrapper.tcc
+MatrixT.tcc
+RowMatrixT.tcc
+SparseVectorT.tcc
+VectorT.tcc
+VVector.cpp
+)
+
+ADD_LIBRARY(core_vector ${NICE_BUILD_LIBS_STATIC_SHARED} ${core_vector_src})
+
+INSTALL(TARGETS core_vector DESTINATION libs)

+ 49 - 1
readme.txt

@@ -12,4 +12,52 @@ boost::timer ??
 stringtools highly os dependented
 ->recursive dir scan with "ls -r" syntax!!
 use 3rd party lib like boost oder qt
-use boost regex for regex syntax in stringtools::regex bla
+use boost regex for regex syntax in stringtools::regex bla
+
+
+-----------------------------------------------------------------------
+macro add_all_subdirs()
+
+set(_all_headers)
+set(_all_sources)
+set(_all_linkings)
+
+#ge
+foreach dir in subdirlist
+{
+  add_directories( dir )
+  #add header, sources, linkings from subdir to _all_* variables
+
+}  
+
+
+
+endmacro
+
+#####################
+
+
+set(NICE_CURR_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+
+
+
+#### geile funktionen der OpenCV:
+---aus OpenCVUtils.cmake:
+macro(ocv_convert_to_full_paths VAR) # convert list of paths to full paths
+macro(ocv_get_real_path VAR PATHSTR) # get absolute path with symlinks resolved
+macro(ocv_list_add_suffix LST SUFFIX) # add suffix to each item in the list
+macro(ocv_list_add_prefix LST PREFIX) # add prefix to each item in the list
+macro(ocv_list_unique __lst)# stable & safe duplicates removal macro
+
+
+
+OpenCVModule.cmake
+ocv_glob_modules(pathcurrdir) -->in modules
+  in jedem untermodel, eg core
+  ocv_add_module(modname)
+    sets variable "the_module" => set(the_module opencv_${name})
+    extra abhängikeitens über zweites argument in der funktion, eg. ocv_add_module(core ${ZLIB_Lbla})
+  ocv_module_include_directories() ( auch mit zusatzincludes dann übergeben ${ZLib_include_Dir})
+  ocv_glob_module_sources() holt cpps und hpp h aus unterordnern -- sources bilden
+  ocv_create_module (binary build the module ->add_library,  set_target etc
+