1 set(the_description "All the selected OpenCV modules in a single binary") 2 set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE) 3 set(BUILD_opencv_world_INIT OFF) 4 5 if(IOS OR NOT BUILD_SHARED_LIBS) 6 set(OPENCV_MODULE_TYPE STATIC) 7 set(OPENCV_WORLD_FLAGS_PROPERTY STATIC_LIBRARY_FLAGS) 8 else() 9 set(OPENCV_WORLD_FLAGS_PROPERTY LINK_FLAGS) 10 endif() 11 12 function(include_one_module m) 13 include("${OPENCV_MODULE_${m}_LOCATION}/CMakeLists.txt") 14 endfunction() 15 16 if(NOT OPENCV_INITIAL_PASS) 17 project(opencv_world) 18 19 message(STATUS "Processing WORLD modules...") 20 foreach(m ${OPENCV_MODULES_BUILD}) 21 if(OPENCV_MODULE_${m}_IS_PART_OF_WORLD) 22 message(STATUS " module ${m}...") 23 set(CMAKE_CURRENT_SOURCE_DIR ${OPENCV_MODULE_${m}_LOCATION}) 24 #add_subdirectory("${OPENCV_MODULE_${m}_LOCATION}" ${CMAKE_CURRENT_BINARY_DIR}/${m}) 25 include_one_module(${m}) 26 endif() 27 endforeach() 28 message(STATUS "Processing WORLD modules... DONE") 29 set(CMAKE_CURRENT_SOURCE_DIR OPENCV_MODULE_${opencv_world}_LOCATION) 30 endif() 31 32 ocv_add_module(world opencv_core) 33 34 set(headers_list "HEADERS") 35 set(sources_list "SOURCES") 36 set(link_deps "") 37 foreach(m ${OPENCV_MODULE_${the_module}_DEPS}) 38 set(headers_list "${headers_list};${OPENCV_MODULE_${m}_HEADERS}") 39 set(sources_list "${sources_list};${OPENCV_MODULE_${m}_SOURCES}") 40 set(link_deps "${link_deps};${OPENCV_MODULE_${m}_LINK_DEPS}") 41 endforeach() 42 43 ocv_glob_module_sources(${headers_list} ${sources_list}) 44 45 ocv_module_include_directories() 46 47 #message(STATUS "${OPENCV_MODULE_${the_module}_HEADERS}") 48 #message(STATUS "${OPENCV_MODULE_${the_module}_SOURCES}") 49 ocv_create_module(${link_deps}) 50 51 if(BUILD_opencv_imgcodecs AND OPENCV_MODULE_opencv_imgcodecs_IS_PART_OF_WORLD) 52 ocv_imgcodecs_configure_target() 53 endif() 54 if(BUILD_opencv_videoio AND OPENCV_MODULE_opencv_videoio_IS_PART_OF_WORLD) 55 ocv_videoio_configure_target() 56 endif() 57 if(BUILD_opencv_highgui AND OPENCV_MODULE_opencv_highgui_IS_PART_OF_WORLD) 58 ocv_highgui_configure_target() 59 endif() 60 61 if(IOS OR APPLE) 62 set(merge_libs "") 63 macro(ios_include_3party_libs) 64 foreach(l ${ARGN}) 65 add_dependencies(${the_module} ${l}) 66 list(APPEND merge_libs "$<TARGET_LINKER_FILE:${l}>") 67 endforeach() 68 endmacro() 69 70 if(WITH_PNG) 71 ios_include_3party_libs(zlib libpng) 72 endif() 73 74 if(WITH_JPEG) 75 ios_include_3party_libs(libjpeg) 76 endif() 77 78 add_custom_command(TARGET ${the_module} POST_BUILD 79 COMMAND /usr/bin/libtool -static -o ${CMAKE_CURRENT_BINARY_DIR}/${the_module}_fat.a $<TARGET_LINKER_FILE:${the_module}> ${merge_libs} 80 COMMAND mv ${CMAKE_CURRENT_BINARY_DIR}/${the_module}_fat.a $<TARGET_LINKER_FILE:${the_module}> 81 ) 82 endif() 83