CMakeLists.txt 3.5 KB
Newer Older
1
set(the_description "All the selected OpenCV modules in a single binary")
2 3
set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
set(BUILD_opencv_world_INIT OFF)
4
set(OPENCV_MODULE_TYPE SHARED)
5

6
ocv_add_module(world opencv_core)
7 8

if(MSVC)
9 10 11 12
  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}}")
  endforeach()
13 14
endif()

15 16 17
ocv_glob_module_sources()
ocv_module_include_directories()
ocv_create_module(SKIP_LINK)
18

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

34 35 36 37 38 39 40 41 42 43 44
set(objlist "")
foreach(m ${OPENCV_MODULE_${the_module}_DEPS})
  # 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})
  endif()

  string(REGEX REPLACE "<MODULE_NAME>" "${m}" objpath1 "${${m}_BINARY_DIR}/${objpath0}")
45 46 47 48 49 50 51 52
  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()
53
      else()
54
        if(IS_ABSOLUTE "${srcname}")
55 56 57 58 59 60
          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()
61 62 63 64 65 66 67
        endif()
        string(REPLACE ".." "__" srcname "${srcname}")
        get_filename_component(srcname_we ${srcname} NAME_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)
68
        file(RELATIVE_PATH objpath4 "${CMAKE_CURRENT_BINARY_DIR}" "${objpath3}")
69 70
      else()
        set(objpath4 ${objpath3})
71
      endif()
72
      list(APPEND objlist "\"${objpath4}\"")
73
    endif()
74
  endforeach()
75 76
endforeach()

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

79
if(have_cfg)
80 81 82 83 84
  string(REGEX REPLACE "<CONFIGURATION>" "Debug" objlist_dbg "${objlist}")
  string(REGEX REPLACE "<CONFIGURATION>" "Release" objlist_rls "${objlist}")
  set_target_properties(${the_module} PROPERTIES
    LINK_FLAGS_DEBUG ${objlist_dbg}
    LINK_FLAGS_RELEASE ${objlist_rls})
85
else()
86 87 88
  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
89
    LINK_FLAGS "@${CMAKE_CURRENT_BINARY_DIR}/world_objects.rsp")
90 91 92
endif()

ocv_add_precompiled_headers(${the_module})