From 6259c9ac6a9f593962b9bb28d754395e32105db1 Mon Sep 17 00:00:00 2001 From: Ethan Rublee Date: Tue, 28 Jun 2011 16:02:09 +0000 Subject: [PATCH] First pass at name mangling based on version number, to support side by side installs of OpenCV2.3.0 OpenCV2.3.1 OpenCV2.4.x, etc... --- CMakeLists.txt | 42 +++++++++++++++++++++++++--------- OpenCVConfig-version.cmake.in | 14 ++++++++++++ OpenCVConfig.cmake.in | 40 +++++++++++++++++++++----------- OpenCVModule.cmake | 2 +- include/CMakeLists.txt | 7 +++--- modules/gpu/CMakeLists.txt | 6 ++--- modules/highgui/CMakeLists.txt | 2 +- 7 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 OpenCVConfig-version.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index b164d2723f..64d94874fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,11 @@ # - OCT-2008: Initial version # # ---------------------------------------------------------------------------- +cmake_minimum_required(VERSION 2.4) +project(OpenCV) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) - +set(OPENCV_INCLUDE_PREFIX include) # Add these standard paths to the search paths for FIND_LIBRARY # to find libraries from these locations first if(UNIX) @@ -49,10 +51,6 @@ if (WIN32 AND ${CMAKE_GENERATOR} MATCHES "(MinGW)|(MSYS)" AND NOT ANDROID) set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "") endif() - -project(OpenCV) -cmake_minimum_required(VERSION 2.4) - if(MSVC) set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE) endif() @@ -104,7 +102,7 @@ endif() # ---------------------------------------------------------------------------- # Current version number: # ---------------------------------------------------------------------------- -set(OPENCV_VERSION "2.3.0") +set(OPENCV_VERSION "2.3.1") string(REGEX MATCHALL "[0-9]+" OPENCV_VERSION_PARTS "${OPENCV_VERSION}") @@ -125,6 +123,14 @@ else() set(OPENCV_DEBUG_POSTFIX) endif() +#name mangling +if(UNIX) + option(OPENCV_MANGLED_INSTALL_PATHS "Enables mangled install paths, that help with side by side installs" False) + if(OPENCV_MANGLED_INSTALL_PATHS) + set(OPENCV_INCLUDE_PREFIX include/opencv-${OPENCV_VERSION}) + endif() +endif() + # ---------------------------------------------------------------------------- # Build static or dynamic libs? # Default: dynamic libraries @@ -1151,7 +1157,9 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig.cmake.in" "${CMAKE_BINA # -------------------------------------------------------------------------------------------- # Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install" # ------------------------------------------------------------------------------------------- -set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/include/opencv" "\${OpenCV_INSTALL_PATH}/include\"") +set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}/opencv" "\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}\"") + + set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "") if(ANDROID) set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/libs/\${ARMEABI_NDK_NAME}\"") @@ -1161,12 +1169,24 @@ else() set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"") endif() -exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/unix-install/\"" OUTPUT_VARIABLE RET_VAL) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY) if(UNIX) - # For a command "FIND_PACKAGE(FOO)", CMake will look at the directory /usr/share|lib/FOO/FOOConfig.cmake, so: + #http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference + # For a command "find_package( [major[.minor]] [EXACT] [REQUIRED|QUIET])" + # cmake will look in the following dir on unix: + # /(share|lib)/cmake/*/ (U) + # /(share|lib)/*/ (U) + # /(share|lib)/*/(cmake|CMake)/ (U) + if(OPENCV_MANGLED_INSTALL_PATHS) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION share/OpenCV-${OPENCV_VERSION}/) + else() install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION share/OpenCV/) + endif() + + endif() if(ANDROID) @@ -1246,8 +1266,8 @@ endif(ANDROID) set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix "\${prefix}") set(libdir "\${exec_prefix}/lib") -set(includedir "\${prefix}/include") -set(VERSION ${OPENCV_VERSION}) +set(includedir "\${prefix}/${OPENCV_INCLUDE_PREFIX}") +set(VERSION ${OPENCV_VERSION}) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/opencv.pc.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/opencv.pc" @ONLY IMMEDIATE) diff --git a/OpenCVConfig-version.cmake.in b/OpenCVConfig-version.cmake.in new file mode 100644 index 0000000000..d1d068ff3d --- /dev/null +++ b/OpenCVConfig-version.cmake.in @@ -0,0 +1,14 @@ +SET(OpenCV_VERSION @OPENCV_VERSION@) +SET(OpenCV_VERSION_MAJOR @OPENCV_VERSION_MAJOR@) +SET(OpenCV_VERSION_MINOR @OPENCV_VERSION_MINOR@) +SET(OpenCV_VERSION_PATCH @OPENCV_VERSION_PATCH@) +set(PACKAGE_VERSION OpenCV_VERSION) +if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL ${OpenCV_VERSION_MAJOR}) + set(PACKAGE_VERSION_COMPATIBLE True) # compatible with any version @OPENCV_VERSION_MAJOR@.x.x + if("${PACKAGE_FIND_VERSION_MINOR}" EQUAL ${OpenCV_VERSION_MINOR}) + set(PACKAGE_VERSION_COMPATIBLE True) # compatible with any version @OPENCV_VERSION_MAJOR@.@OPENCV_VERSION_MINOR@.x + if("${PACKAGE_FIND_VERSION_PATCH}" EQUAL ${OpenCV_VERSION_PATCH}) + set(PACKAGE_VERSION_EXACT True) # exact match for patch @OPENCV_VERSION_MAJOR@.@OPENCV_VERSION_MINOR@.@OPENCV_VERSION_PATCH@ + endif() + endif() +endif() diff --git a/OpenCVConfig.cmake.in b/OpenCVConfig.cmake.in index f79be016c0..d76556e2f8 100644 --- a/OpenCVConfig.cmake.in +++ b/OpenCVConfig.cmake.in @@ -61,28 +61,42 @@ SET(OpenCV_LIB_DIR @CMAKE_LIB_DIRS_CONFIGCMAKE@) LINK_DIRECTORIES(${OpenCV_LIB_DIR}) # ==================================================================== -# Link libraries: e.g. opencv_core220.so, opencv_imgproc220d.lib, etc... +# Link libraries: e.g. libopencv_core.so, opencv_imgproc220d.lib, etc... # ==================================================================== -#libraries order is very important because linker from Android NDK is one-pass linker SET(OpenCV_LIB_COMPONENTS opencv_contrib opencv_legacy opencv_objdetect opencv_calib3d opencv_features2d opencv_video opencv_highgui opencv_ml opencv_imgproc opencv_flann opencv_core ) - +#libraries order is very important because linker from Android NDK is one-pass linker if(NOT ANDROID) LIST(INSERT OpenCV_LIB_COMPONENTS 0 opencv_gpu) ELSEIF(NOT OpenCV_SHARED) LIST(APPEND OpenCV_LIB_COMPONENTS opencv_androidcamera) endif() +if(@OPENCV_MANGLED_INSTALL_PATHS@) + #be explicit about the library names. + set(OpenCV_LIB_COMPONENTS_ ) + foreach( CVLib ${OpenCV_LIB_COMPONENTS}) + list(APPEND OpenCV_LIB_COMPONENTS_ ${OpenCV_LIB_DIR}/lib${CVLib}.so.@OPENCV_VERSION@ ) + endforeach() + set(OpenCV_LIB_COMPONENTS ${OpenCV_LIB_COMPONENTS_}) +endif() + SET(OpenCV_LIBS "") -foreach(__CVLIB ${OpenCV_LIB_COMPONENTS}) - # CMake>=2.6 supports the notation "debug XXd optimized XX" - if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER 2.4) - # Modern CMake: - SET(OpenCV_LIBS ${OpenCV_LIBS} debug ${__CVLIB}@OPENCV_DLLVERSION@@OPENCV_DEBUG_POSTFIX@ optimized ${__CVLIB}@OPENCV_DLLVERSION@) - else() - # Old CMake: - SET(OpenCV_LIBS ${OpenCV_LIBS} ${__CVLIB}@OPENCV_DLLVERSION@) - endif() -endforeach() +if(WIN32) + foreach(__CVLIB ${OpenCV_LIB_COMPONENTS}) + # CMake>=2.6 supports the notation "debug XXd optimized XX" + if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER 2.4) + # Modern CMake: + SET(OpenCV_LIBS ${OpenCV_LIBS} debug ${__CVLIB}@OPENCV_DLLVERSION@@OPENCV_DEBUG_POSTFIX@ optimized ${__CVLIB}@OPENCV_DLLVERSION@) + else() + # Old CMake: + SET(OpenCV_LIBS ${OpenCV_LIBS} ${__CVLIB}@OPENCV_DLLVERSION@) + endif() + endforeach() +else() + foreach(__CVLIB ${OpenCV_LIB_COMPONENTS}) + SET(OpenCV_LIBS ${OpenCV_LIBS} ${__CVLIB}) + endforeach() +endif() # ============================================================== # Extra include directories, needed by OpenCV 2 new structure diff --git a/OpenCVModule.cmake b/OpenCVModule.cmake index 00382ea0f4..d69a350ab7 100644 --- a/OpenCVModule.cmake +++ b/OpenCVModule.cmake @@ -101,7 +101,7 @@ macro(define_opencv_module name) ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) install(FILES ${lib_hdrs} - DESTINATION include/opencv2/${name} + DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/${name} COMPONENT main) if(BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index f08afa4ae4..f95853f2b6 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,8 +1,9 @@ file(GLOB old_hdrs "opencv/*.h*") install(FILES ${old_hdrs} - DESTINATION include/opencv + DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv COMPONENT main) - install(FILES "opencv2/opencv.hpp" - DESTINATION include/opencv2 + DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2 COMPONENT main) + + diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index a8cc0febb7..170207a457 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -153,15 +153,15 @@ install(TARGETS ${the_target} ARCHIVE DESTINATION lib COMPONENT main) install(FILES ${lib_hdrs} - DESTINATION include/opencv2/${name} + DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/${name} COMPONENT main) install(FILES src/nvidia/NPP_staging/NPP_staging.hpp src/nvidia/core/NCV.hpp - DESTINATION include/opencv2/${name} + DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/${name} COMPONENT main) #install(FILES ${lib_device_hdrs} -# DESTINATION include/opencv2/${name}/device +# DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/${name}/device # COMPONENT main) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index c565cdf4d9..458a66178f 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -366,7 +366,7 @@ install(TARGETS ${the_target} ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) install(FILES ${highgui_ext_hdrs} - DESTINATION include/opencv2/highgui + DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2/highgui COMPONENT main)