Shortened CMake script for opencv_world. Fixed opencv_world link with non-Visual Studio generators on Windows.

This commit is contained in:
Andrey Kamaev 2012-05-13 09:34:33 +00:00
parent 6dde56faf4
commit 8d135e8ea1
4 changed files with 81 additions and 123 deletions

View File

@ -7,6 +7,7 @@
#
# OPENCV_MODULE_${the_module}_LOCATION
# OPENCV_MODULE_${the_module}_DESCRIPTION
# OPENCV_MODULE_${the_module}_CLASS - PUBLIC|INTERNAL|BINDINGS
# OPENCV_MODULE_${the_module}_HEADERS
# OPENCV_MODULE_${the_module}_SOURCES
# OPENCV_MODULE_${the_module}_DEPS - final flattened set of module dependencies
@ -18,6 +19,8 @@
# To control the setup of the module you could also set:
# the_description - text to be used as current module description
# OPENCV_MODULE_TYPE - STATIC|SHARED - set to force override global settings for current module
# OPENCV_MODULE_IS_PART_OF_WORLD - ON|OFF (default ON) - should the module be added to the opencv_world?
# BUILD_${the_module}_INIT - ON|OFF (default ON) - initial value for BUILD_${the_module}
# The verbose template for OpenCV module:
#
@ -38,10 +41,12 @@
# clean flags for modules enabled on previous cmake run
# this is necessary to correctly handle modules removal
foreach(mod ${OPENCV_MODULES_BUILD})
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
@ -84,7 +89,7 @@ endmacro()
# 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 NOLINK opencv_flann OPTIONAL opencv_gpu)
# 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}")
@ -106,30 +111,32 @@ macro(ocv_add_module _name)
endif()
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")
unset(OPENCV_MODULE_${the_module}_REQ_DEPS CACHE)
unset(OPENCV_MODULE_${the_module}_OPT_DEPS CACHE)
#create option to enable/disable this module
if(the_module STREQUAL "opencv_world")
set(build_the_module OFF)
else()
set(build_the_module ON)
if(NOT DEFINED BUILD_${the_module}_INIT)
set(BUILD_${the_module}_INIT ON)
endif()
option(BUILD_${the_module} "Include ${the_module} module into the OpenCV build" ${build_the_module})
unset(build_the_module)
option(BUILD_${the_module} "Include ${the_module} module into the OpenCV build" ${BUILD_${the_module}_INIT})
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()
@ -436,9 +443,12 @@ endmacro()
# creates new target, configures standard dependencies, compilers flags, install rules
# Usage:
# ocv_create_module(<extra link dependencies>)
# ocv_create_module(SKIP_LINK)
macro(ocv_create_module)
add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES})
if(NOT "${ARGN}" STREQUAL "SKIP_LINK")
target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
endif()
add_dependencies(opencv_modules ${the_module})
if(ENABLE_SOLUTION_FOLDERS)

View File

@ -301,7 +301,3 @@ endif()
ocv_add_accuracy_tests()
ocv_add_perf_tests()
set(HIGHGUI_LIBRARIES ${HIGHGUI_LIBRARIES} PARENT_SCOPE)
set(GRFMT_LIBS ${GRFMT_LIBS} PARENT_SCOPE)

View File

@ -1,3 +1,5 @@
set(the_description "The ts module")
if(IOS)
ocv_module_disable(ts)
endif()
@ -6,7 +8,8 @@ if(MINGW)
set(OPENCV_MODULE_TYPE STATIC)
endif()
set(the_description "The ts module")
set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
ocv_add_module(ts opencv_core)
ocv_glob_module_sources()
ocv_module_include_directories()

View File

@ -1,102 +1,65 @@
project(opencv_world)
string(REPLACE "/INCREMENTAL:NO" "/INCREMENTAL:YES" CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
string(REPLACE "/INCREMENTAL:NO" "/INCREMENTAL:YES" CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE}")
string(REPLACE "/INCREMENTAL:NO" "/INCREMENTAL:YES" CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
set(the_description "All the selected OpenCV modules in a single binary")
set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
set(BUILD_opencv_world_INIT OFF)
set(module_list )
ocv_add_module(world opencv_core)
ocv_add_module(world opencv_core OPTIONAL opencv_flann opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_photo opencv_objdetect opencv_legacy opencv_nonfree)
set(the_module opencv_world)
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}}")
endforeach()
endif()
ocv_glob_module_sources()
ocv_module_include_directories()
ocv_create_module(SKIP_LINK)
add_library(${the_module} ${OPENCV_MODULE_TYPE} ${OPENCV_MODULE_${the_module}_HEADERS} ${OPENCV_MODULE_${the_module}_SOURCES})
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_module} PROPERTIES FOLDER "modules")
endif()
set_target_properties(${the_module} PROPERTIES
OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}"
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
INSTALL_NAME_DIR lib
)
# For dynamic link numbering convenions
if(NOT ANDROID)
# Android SDK build scripts can include only .so files into final .apk
# As result we should not set version properties for Android
set_target_properties(${the_module} PROPERTIES
VERSION ${OPENCV_VERSION}
SOVERSION ${OPENCV_SOVERSION}
)
endif()
if(BUILD_SHARED_LIBS)
if(MSVC)
set_target_properties(${the_module} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
else()
add_definitions(-DCVAPI_EXPORTS)
endif()
endif()
if(MSVC)
if(CMAKE_CROSSCOMPILING)
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:secchk")
endif()
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libc /DEBUG")
endif()
set(objpath0 "${OpenCV_BINARY_DIR}/modules/<MODULE_NAME>")
#TODO: try to use try_compile to find real object file extension/location
if(CMAKE_GENERATOR MATCHES "^Visual.*$")
set(have_cfg 1)
set(objpath0 "${objpath0}/opencv_<MODULE_NAME>.dir/<CONFIGURATION>/<SRC_NAME_WE>.obj")
set(objpath0 "<MODULE_NAME>.dir/<CONFIGURATION>/<SRC_NAME_WE>.obj")
elseif (CMAKE_GENERATOR MATCHES Xcode)
set(have_cfg 1)
set(objpath0 "${objpath0}/OpenCV.build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/opencv_<MODULE_NAME>.build/Objects-normal/$(CURRENT_ARCH)/<SRC_NAME_WE>.o")
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 "${objpath0}/CMakeFiles/opencv_<MODULE_NAME>.dir/src/<SRC_NAME>.o")
set(objpath0 "CMakeFiles/<MODULE_NAME>.dir/<RELATIVE_SRC_NAME>.o")
if(MINGW OR MSVC)
set(objpath0 "${objpath0}bj")
endif()
endif()
set(objlist)
foreach(m ${OPENCV_MODULES_BUILD})
if(m STREQUAL ${the_module})
elseif(m STREQUAL "opencv_python")
elseif(m STREQUAL "opencv_ts")
else()
set(objlist "")
foreach(m ${OPENCV_MODULE_${the_module}_DEPS})
# build order dependencies
add_dependencies(${the_module} ${m})
string(REGEX REPLACE "^opencv_" "" bare_m "${m}")
string(REGEX REPLACE "<MODULE_NAME>" "${bare_m}" objpath1 "${objpath0}")
if(m STREQUAL "opencv_highgui")
target_link_libraries(${the_module} ${HIGHGUI_LIBRARIES} ${GRFMT_LIBS})
# 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()
foreach(d ${OPENCV_MODULE_${m}_DEPS_EXT})
target_link_libraries(${the_module} ${d})
endforeach()
set(modobjlist)
string(REGEX REPLACE "<MODULE_NAME>" "${m}" objpath1 "${${m}_BINARY_DIR}/${objpath0}")
foreach(src ${OPENCV_MODULE_${m}_SOURCES})
get_filename_component(srcname ${src} NAME)
if(srcname MATCHES ".*\\.[cm].*")
if(IS_ABSOLUTE "${src}")
file(RELATIVE_PATH srcname "${OPENCV_MODULE_${m}_LOCATION}" "${src}")
else()
set(srcname "${src}")
endif()
string(REPLACE ".." "__" srcname "${srcname}")
if(srcname MATCHES "\\.(cpp|mm|c|cxx|cc)$")
get_filename_component(srcname_we ${srcname} NAME_WE)
string(REGEX REPLACE <SRC_NAME_WE> "${srcname_we}" objpath2 "${objpath1}")
string(REGEX REPLACE <SRC_NAME> "${srcname}" objpath3 "${objpath2}")
set(modobjlist "${modobjlist} \"${objpath3}\"")
string(REGEX REPLACE <RELATIVE_SRC_NAME> "${srcname}" objpath3 "${objpath2}")
file(RELATIVE_PATH objpath4 "${CMAKE_CURRENT_BINARY_DIR}" "${objpath3}")
list(APPEND objlist "\"${objpath4}\"")
endif()
endforeach()
set(objlist "${objlist} ${modobjlist}")
endif()
endforeach()
string(REPLACE ";" " " objlist "${objlist}")
if(have_cfg)
string(REGEX REPLACE "<CONFIGURATION>" "Debug" objlist_dbg "${objlist}")
string(REGEX REPLACE "<CONFIGURATION>" "Release" objlist_rls "${objlist}")
@ -104,24 +67,10 @@ if(have_cfg)
LINK_FLAGS_DEBUG ${objlist_dbg}
LINK_FLAGS_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
LINK_FLAGS ${objlist})
endif()
install(TARGETS ${the_module}
RUNTIME DESTINATION bin COMPONENT main
LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main
)
# only "public" headers need to be installed
if(OPENCV_MODULE_${the_module}_HEADERS AND OPENCV_MODULES_PUBLIC MATCHES "(^|;)${the_module}(;|$)")
foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS})
string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}")
if(hdr2 MATCHES "^(opencv2/.*)/[^/]+.h(..)?$")
install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_PREFIX}/${CMAKE_MATCH_1}" COMPONENT main)
endif()
endforeach()
LINK_FLAGS @world_objects.rsp)
endif()
ocv_add_precompiled_headers(${the_module})