]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
First try to enable OpenCV compiled as static libs.
authorjlblanco <jlblanco@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Sat, 19 Dec 2009 22:32:17 +0000 (22:32 +0000)
committerjlblanco <jlblanco@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Sat, 19 Dec 2009 22:32:17 +0000 (22:32 +0000)
Select BUILD_SHARED_LIBS to OFF. The default is ON, for backwards compatibility.
It works under Linux+GCC: opencv builds and the samples/c/example_cmake example compiles as well.

git-svn-id: https://code.ros.org/svn/opencv/trunk@2461 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

12 files changed:
opencv/3rdparty/flann/CMakeLists.txt
opencv/CMakeLists.txt
opencv/OpenCVConfig.cmake.in
opencv/cvconfig.h.cmake
opencv/interfaces/ffopencv/CMakeLists.txt
opencv/interfaces/python/CMakeLists.txt
opencv/src/cv/CMakeLists.txt
opencv/src/cvaux/CMakeLists.txt
opencv/src/cxcore/CMakeLists.txt
opencv/src/highgui/CMakeLists.txt
opencv/src/ml/CMakeLists.txt
opencv/tests/cxts/CMakeLists.txt

index ecd50011c6d1847478910278a24d97db26b30b1a..8f65d00649b785c05b9bef0c974d08636a201542 100644 (file)
@@ -64,8 +64,9 @@ ADD_SUBDIRECTORY( tests )
 file(GLOB_RECURSE SOURCES *.cpp)
 #SET(SOURCES flann.cpp util/Random.cpp nn/Testing.cpp algorithms/NNIndex.cpp algorithms/dist.cpp util/Logger.cpp util/Saving.cpp)
 
-ADD_LIBRARY(flann SHARED ${SOURCES})
-ADD_LIBRARY(flann_s STATIC ${SOURCES})
+ADD_LIBRARY(flann ${SOURCES})
+#ADD_LIBRARY(flann SHARED ${SOURCES})   #JL: Why the two versions??
+#ADD_LIBRARY(flann_s STATIC ${SOURCES})
 
 IF(WIN32)
 INSTALL (
@@ -84,7 +85,7 @@ INSTALL (
 ENDIF(WIN32)
 
 INSTALL (
-    TARGETS flann flann_s
+    TARGETS flann  # flann_s
     RUNTIME DESTINATION bin
     LIBRARY DESTINATION lib
     ARCHIVE DESTINATION lib
index f2b0bae13c9e8c2ef4f1a0d22608d25e75f17982..69bbcc7c078dc2d1d8901c86d94c07867ac05c9a 100644 (file)
@@ -77,6 +77,17 @@ else()
     set(OPENCV_DEBUG_POSTFIX)\r
 endif()\r
 \r
+
+# ----------------------------------------------------------------------------\r
+# Build static or dynamic libs?
+# ----------------------------------------------------------------------------\r
+# Default: dynamic libraries:
+SET(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)")
+IF(BUILD_SHARED_LIBS)
+       SET(OPENCV_BUILD_SHARED_LIB 1) # For cvconfig.h, etc.
+ELSE(BUILD_SHARED_LIBS)
+       SET(OPENCV_BUILD_SHARED_LIB 0)
+ENDIF(BUILD_SHARED_LIBS)
 \r
 # ----------------------------------------------------------------------------\r
 #  Variables for cvconfig.h.cmake\r
@@ -131,7 +142,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
     set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR})\r
     message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION}")\r
 endif()\r
-\r
+
 # ----------------------------------------------------------------------------\r
 #       CHECK FOR SYSTEM LIBRARIES, OPTIONS, ETC..\r
 # ----------------------------------------------------------------------------\r
@@ -646,6 +657,15 @@ if(CMAKE_COMPILER_IS_GNUCXX)
 \r
     set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -DNDEBUG")\r
     set(EXTRA_C_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG")\r
+endif()
+
+# Extra link libs if the user selects building static libs:
+IF(NOT BUILD_SHARED_LIBS)
+       if(CMAKE_COMPILER_IS_GNUCXX)\r
+               set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++)
+       endif()\r
+
+       set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} flann zlib opencv_lapack)
 endif()\r
 \r
 \r
@@ -719,7 +739,7 @@ endif()
 \r
 # Set CMAKE_INCLUDE_DIRS_CONFIGCMAKE to the list of include directories:\r
 set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${CMAKE_CURRENT_SOURCE_DIR}/include\" \"${CMAKE_CURRENT_SOURCE_DIR}/include/opencv\"")\r
-\r
+
 set(CMAKE_LIB_DIRS_CONFIGCMAKE "${LIBRARY_OUTPUT_PATH}")\r
 \r
 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY)\r
@@ -884,6 +904,7 @@ add_subdirectory(3rdparty)
 message(STATUS "")\r
 message(STATUS "General configuration for opencv ${OPENCV_VERSION} =====================================")\r
 message(STATUS "")\r
+message(STATUS "    Built as dynamic libs?:    ${BUILD_SHARED_LIBS}")\r
 message(STATUS "    Compiler:                  ${CMAKE_COMPILER}")\r
 message(STATUS "    C++ flags (Release):       ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")\r
 message(STATUS "    C++ flags (Debug):         ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")\r
index a47e05fae20863c4092de23ab93f1e3d729965b9..2561ccafeff587deb641e9af1aa5a20f191fc690 100644 (file)
@@ -51,7 +51,25 @@ foreach(__CVLIB ${OPENCV_LIB_COMPONENTS})
                # Old CMake:\r
                SET(OpenCV_LIBS ${OpenCV_LIBS} ${__CVLIB}@OPENCV_DLLVERSION@)\r
        endif(CMAKE_MAJOR_VERSION GREATER 2  OR  CMAKE_MINOR_VERSION GREATER 4)\r
-endforeach(__CVLIB)\r
+endforeach(__CVLIB)
+
+# For OpenCV built as static libs, we need the user to link against 
+#  many more dependencies:
+IF (NOT @OPENCV_BUILD_SHARED_LIB@)
+       # Under static libs, the user of OpenCV needs access to the 3rdparty libs as well:
+       LINK_DIRECTORIES("@CMAKE_BINARY_DIR@/3rdparty/lib")
+\r
+       SET(OpenCV_LIBS 
+               @OPENCV_LINKER_LIBS@ 
+               @IPP_LIBS@
+               @JPEG_LIBRARIES@ 
+               @PNG_LIBRARIES@ 
+               @TIFF_LIBRARIES@ 
+               @JASPER_LIBRARIES@ 
+               @HIGHGUI_LIBRARIES@ 
+               ${OpenCV_LIBS}) # The standard libs BEFORE (OpenCV_LIBS) since these can have "debug","optimized".\r
+ENDIF(NOT @OPENCV_BUILD_SHARED_LIB@)
+
 \r
 # ======================================================\r
 #  Version variables: \r
index d544c07e077151c286262c7077652ab778b6f4c6..dc61c7480ec997889eea767d613b277030704941 100644 (file)
 /* Intel Integrated Performance Primitives */
 #cmakedefine  HAVE_IPP
 
+/* OpenCV compiled as static or dynamic libs */
+#cmakedefine  OPENCV_BUILD_SHARED_LIB
+
 /* Name of package */
 #define  PACKAGE "${PACKAGE}"
 
index a071cba13c31c70a940c9300344f2f0eaa018e46..48e865ad59ec83cacba574ee6b1cce0801dd1766 100644 (file)
@@ -6,7 +6,7 @@ include_directories("${CMAKE_SOURCE_DIR}/src/highgui")
 link_directories("${CMAKE_SOURCE_DIR}/3rdparty/lib")
 
 set(the_target opencv_ffmpeg)
-add_library(${the_target} SHARED ffopencv.cpp ffopencv.h)
+add_library(${the_target} ffopencv.cpp ffopencv.h)
 
 if (MSVC)
 add_dependencies(${the_target} cxcore)
index 813a2bd2597c3623371de081ec871ecb05fc2b21..79c72bb29d6c23c454e76c495f084475a1015915 100644 (file)
@@ -21,7 +21,7 @@ add_custom_command(
    )
 
 set(the_target "cvpy")
-add_library(${the_target} SHARED ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs} ${CMAKE_CURRENT_BINARY_DIR}/generated0.i)
+add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs} ${CMAKE_CURRENT_BINARY_DIR}/generated0.i)
 target_link_libraries(${the_target} ${PYTHON_LIBRARIES} cxcore cv cvaux highgui)
 set_target_properties(${the_target} PROPERTIES PREFIX "")
 set_target_properties(${the_target} PROPERTIES OUTPUT_NAME "cv")
index 3f8c0bec6eb87a9bd22109f5195717a2f6b6fd85..5db832f96469bc33821d984f87d86d8a5a737e90 100644 (file)
@@ -24,7 +24,7 @@ source_group("Include\\Internal" FILES ${lib_int_hdrs})
 \r
 set(the_target "cv")\r
 \r
-add_library(${the_target} SHARED ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs})\r
+add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs})\r
 \r
 if(PCHSupport_FOUND)\r
     set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/_cv.h)\r
index 56197e8bc89e2c72147babcd4f6325ed595be85c..03e1454210e96b4477686993ba938ba00579321c 100644 (file)
@@ -34,7 +34,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../include/opencv"
 # ----------------------------------------------------------------------------------
 set(the_target "cvaux")
 
-add_library(${the_target} SHARED ${lib_srcs} ${lib_hdrs})
+add_library(${the_target} ${lib_srcs} ${lib_hdrs})
 
 if(PCHSupport_FOUND)
     set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/_cvaux.h)
index 249caf2d0a44b8404cba3c91c7117fa2f6e355ab..95c0c2e3a7393f16da733126e4cae4be26352605 100644 (file)
@@ -24,7 +24,7 @@ source_group("Include\\Internal" FILES ${lib_int_hdrs})
 \r
 set(the_target "cxcore")\r
 \r
-add_library(${the_target} SHARED ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs})\r
+add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs})\r
 \r
 if(PCHSupport_FOUND)\r
     set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/_cxcore.h)\r
index 54a7ac3ae92876320a5fa6d8e6eba90c95ec5627..d09b5d1a80ba8cb575a39722df67d55828ae60a7 100644 (file)
@@ -148,7 +148,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../include/opencv"
                     "${CMAKE_CURRENT_SOURCE_DIR}"
                     "${CMAKE_CURRENT_BINARY_DIR}")
 
-add_library(${the_target} SHARED ${lib_srcs} ${highgui_hdrs} ${grfmt_hdrs} ${highgui_ext_hdrs})
+add_library(${the_target} ${lib_srcs} ${highgui_hdrs} ${grfmt_hdrs} ${highgui_ext_hdrs})
 
 if(PCHSupport_FOUND)
     set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/_highgui.h)
index 9053a35057bff74ace07423e39e6de23626b08e7..ef6279c908db52cd55a03ca16845379758e91c24 100644 (file)
@@ -18,7 +18,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../include/opencv"
 \r
 set(the_target "ml")\r
 \r
-add_library(${the_target} SHARED ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs})\r
+add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs})\r
 \r
 if(PCHSupport_FOUND)\r
     set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/_ml.h)\r
index 2a98d245245778cec2cac0f9f07975642cf256a8..eb4a296ba70682845aff8d34ccfef417c79721e1 100644 (file)
@@ -38,7 +38,7 @@ endif()
 # ----------------------------------------------------------------------------------
 set(the_target "cxts")
 
-add_library(${the_target} SHARED ${lib_srcs} ${lib_hdrs})
+add_library(${the_target} ${lib_srcs} ${lib_hdrs})
 
 # For dynamic link numbering convenions
 set_target_properties(${the_target} PROPERTIES