CMakeLists.txt 5.14 KB
Newer Older
a  
Kai Westerkamp committed
1
set(the_description "All the selected OpenCV modules in a single binary")
wester committed
2 3 4
set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
set(BUILD_opencv_world_INIT OFF)

wester committed
5
if(IOS OR NOT BUILD_SHARED_LIBS)
wester committed
6 7 8 9 10 11
  set(OPENCV_MODULE_TYPE STATIC)
  set(OPENCV_WORLD_FLAGS_PROPERTY STATIC_LIBRARY_FLAGS)
else()
  set(OPENCV_WORLD_FLAGS_PROPERTY LINK_FLAGS)
endif()

wester committed
12
ocv_add_module(world opencv_core)
wester committed
13

wester committed
14 15 16 17
if(MSVC)
  foreach(_var CMAKE_EXE_LINKER_FLAGS_RELEASE CMAKE_MODULE_LINKER_FLAGS_RELEASE CMAKE_SHARED_LINKER_FLAGS_RELEASE
               CMAKE_EXE_LINKER_FLAGS_DEBUG   CMAKE_MODULE_LINKER_FLAGS_DEBUG   CMAKE_SHARED_LINKER_FLAGS_DEBUG)
    string(REPLACE "/INCREMENTAL:NO" "/INCREMENTAL:YES" ${_var} "${${_var}}")
wester committed
18 19 20
  endforeach()
endif()

wester committed
21 22 23
ocv_glob_module_sources()
ocv_module_include_directories()
ocv_create_module(SKIP_LINK)
wester committed
24

wester committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#TODO: try to use try_compile to find real object file extension/location
if(CMAKE_GENERATOR MATCHES "^Visual.*$")
  set(have_cfg 1)
  set(objpath0 "<MODULE_NAME>.dir/<CONFIGURATION>/<SRC_NAME_WE>.obj")
elseif (CMAKE_GENERATOR MATCHES Xcode)
  set(have_cfg 1)
  set(objpath0 "OpenCV.build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/<MODULE_NAME>.build/Objects-normal/$(CURRENT_ARCH)/<SRC_NAME_WE>.o")
else()
  set(have_cfg 0)
  set(objpath0 "CMakeFiles/<MODULE_NAME>.dir/<RELATIVE_SRC_NAME>.o")
  if(MINGW OR MSVC)
    set(objpath0 "${objpath0}bj")
  endif()
endif()

set(objlist "")
a  
Kai Westerkamp committed
41
foreach(m ${OPENCV_MODULE_${the_module}_DEPS})
wester committed
42 43 44 45 46 47
  # build order dependencies
  add_dependencies(${the_module} ${m})
  # link dependencies
  string(REGEX REPLACE "(general|debug|optimized);opencv_[^;]*(;|$)" "" _link_deps "${${m}_LIB_DEPENDS}")
  if(_link_deps)
    target_link_libraries(${the_module} ${_link_deps})
wester committed
48
  endif()
wester committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

  string(REGEX REPLACE "<MODULE_NAME>" "${m}" objpath1 "${${m}_BINARY_DIR}/${objpath0}")
  foreach(srcname ${OPENCV_MODULE_${m}_SOURCES})
    if(srcname MATCHES "\\.(cpp|mm|c|cxx|cc|o|obj)$")
      if(srcname MATCHES "\\.(o|obj)$")
        if(IS_ABSOLUTE "${srcname}")
          set(objpath3 "${srcname}")
        else()
          set(objpath3 "${${m}_SOURCE_DIR}/${srcname}")
        endif()
      else()
        if(IS_ABSOLUTE "${srcname}")
          if(srcname MATCHES "/(qrc|moc)_[^/]*\\.cxx$")
            # QT generated sources
            file(RELATIVE_PATH srcname "${${m}_BINARY_DIR}" "${srcname}")
          else()
            file(RELATIVE_PATH srcname "${OPENCV_MODULE_${m}_LOCATION}" "${srcname}")
          endif()
        endif()
        string(REPLACE ".." "__" srcname "${srcname}")
        #NAME_WE intentionally not used since it interprets first period as start of extension (http://cmake.org/Bug/view.php?id=12282)
        get_filename_component(srcname_we "${srcname}" NAME)
        string(REGEX REPLACE "\\.[^.]+$" "" srcname_we "${srcname_we}")
        string(REGEX REPLACE <SRC_NAME_WE> "${srcname_we}" objpath2 "${objpath1}")
        string(REGEX REPLACE <RELATIVE_SRC_NAME> "${srcname}" objpath3 "${objpath2}")
      endif()
      if(CMAKE_GENERATOR MATCHES Makefiles)
        file(RELATIVE_PATH objpath4 "${CMAKE_CURRENT_BINARY_DIR}" "${objpath3}")
      else()
        set(objpath4 ${objpath3})
      endif()
      list(APPEND objlist "\"${objpath4}\"")
    endif()
  endforeach()
wester committed
83 84 85
endforeach()


wester committed
86 87 88 89 90 91 92 93 94
macro(ios_include_3party_libs)
  foreach(l ${ARGN})
    add_dependencies(${the_module} ${l})
    string(REGEX REPLACE "<MODULE_NAME>" "${l}" objpath1 "${CMAKE_BINARY_DIR}/3rdparty/${l}/${objpath0}")
    file(GLOB sources ${CMAKE_SOURCE_DIR}/3rdparty/${l}/*.c)
    foreach(srcname ${sources})
      if(IS_ABSOLUTE "${srcname}")
        file(RELATIVE_PATH srcname "${CMAKE_SOURCE_DIR}/3rdparty/${l}" "${srcname}")
      endif()
wester committed
95

wester committed
96 97 98 99 100 101 102 103 104 105 106 107
      string(REPLACE ".." "__" srcname "${srcname}")
      #NAME_WE intentionally not used since it interprets first period as start of extension (http://cmake.org/Bug/view.php?id=12282)
      get_filename_component(srcname_we "${srcname}" NAME)
      string(REGEX REPLACE "\\.[^.]+$" "" srcname_we "${srcname_we}")
      string(REGEX REPLACE <SRC_NAME_WE> "${srcname_we}" objpath2 "${objpath1}")
      string(REGEX REPLACE <RELATIVE_SRC_NAME> "${srcname}" objpath3 "${objpath2}")

      list(APPEND objlist "\"${objpath3}\"")
    endforeach() # (srcname ${sources})
  endforeach()
  ocv_list_filterout(objlist jmemansi) # <<= dirty fix
endmacro()
wester committed
108

wester committed
109 110
if(IOS AND WITH_PNG)
  ios_include_3party_libs(zlib libpng)
wester committed
111
endif()
wester committed
112 113 114

if(IOS AND WITH_JPEG)
  ios_include_3party_libs(libjpeg)
wester committed
115
endif()
wester committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129

string(REPLACE ";" " " objlist "${objlist}")

if(have_cfg)
  string(REGEX REPLACE "<CONFIGURATION>" "Debug" objlist_dbg "${objlist}")
  string(REGEX REPLACE "<CONFIGURATION>" "Release" objlist_rls "${objlist}")
  set_target_properties(${the_module} PROPERTIES
    ${OPENCV_WORLD_FLAGS_PROPERTY}_DEBUG ${objlist_dbg}
    ${OPENCV_WORLD_FLAGS_PROPERTY}_RELEASE ${objlist_rls})
else()
  file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/world_objects.list" "${objlist}")
  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/world_objects.list" "${CMAKE_CURRENT_BINARY_DIR}/world_objects.rsp" OUTPUT_QUIET)
  set_target_properties(${the_module} PROPERTIES
    ${OPENCV_WORLD_FLAGS_PROPERTY} "@${CMAKE_CURRENT_BINARY_DIR}/world_objects.rsp")
wester committed
130
endif()
wester committed
131 132

ocv_add_precompiled_headers(${the_module})