Permalink
Browse files

improved cmake stuff

  • Loading branch information...
strasdat committed Aug 29, 2012
1 parent aed3618 commit e95d7420ef7e20b337b847823d54f990064dfcba
Showing with 384 additions and 21 deletions.
  1. +7 −6 CMakeLists.txt
  2. +81 −0 CMakeModules/FindEigen3.cmake
  3. +160 −0 CMakeModules/FindOpenCV.cmake
  4. +117 −0 CMakeModules/FindSuiteSparse.cmake
  5. +19 −15 README
View
@@ -5,6 +5,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${PROJECT_SOURCE_DIR}/CMakeModules/")
+SET (OpenCV_DIR ${CMAKE_PREFIX_PATH}/share/OpenCV)
+
SET (CMAKE_VERBOSE_MAKEFILE ON)
IF(NOT CUDA_SUPPORT)
@@ -54,12 +56,11 @@ IF (CMAKE_COMPILER_IS_GNUCXX )
-Wno-unused-but-set-variable -Wno-unknown-pragmas")
ENDIF()
-
-
-SET (INCLUDE_DIRS "EXTERNAL/include/"
- "EXTERNAL/VisionTools"
- "/usr/include/eigen3"
- "/usr/include/suitesparse")
+FIND_PACKAGE(OpenCV REQUIRED)
+FIND_PACKAGE(SuiteSparse REQUIRED)
+FIND_PACKAGE(Eigen3 REQUIRED)
+LIST(APPEND INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR}
+ ${CSPARSE_INCLUDE_DIR})
LIST(APPEND CMAKE_LIBRARY_PATH EXTERNAL/VisionTools/svs_build/)
@@ -0,0 +1,81 @@
+# - Try to find Eigen3 lib
+#
+# This module supports requiring a minimum version, e.g. you can do
+# find_package(Eigen3 3.1.2)
+# to require version 3.1.2 or newer of Eigen3.
+#
+# Once done this will define
+#
+# EIGEN3_FOUND - system has eigen lib with correct version
+# EIGEN3_INCLUDE_DIR - the eigen include directory
+# EIGEN3_VERSION - eigen version
+
+# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
+# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
+# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
+# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
+
+if(NOT Eigen3_FIND_VERSION)
+ if(NOT Eigen3_FIND_VERSION_MAJOR)
+ set(Eigen3_FIND_VERSION_MAJOR 2)
+ endif(NOT Eigen3_FIND_VERSION_MAJOR)
+ if(NOT Eigen3_FIND_VERSION_MINOR)
+ set(Eigen3_FIND_VERSION_MINOR 91)
+ endif(NOT Eigen3_FIND_VERSION_MINOR)
+ if(NOT Eigen3_FIND_VERSION_PATCH)
+ set(Eigen3_FIND_VERSION_PATCH 0)
+ endif(NOT Eigen3_FIND_VERSION_PATCH)
+
+ set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
+endif(NOT Eigen3_FIND_VERSION)
+
+macro(_eigen3_check_version)
+ file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
+
+ string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
+ set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
+ string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
+ set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
+ string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
+ set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
+
+ set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
+ if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
+ set(EIGEN3_VERSION_OK FALSE)
+ else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
+ set(EIGEN3_VERSION_OK TRUE)
+ endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
+
+ if(NOT EIGEN3_VERSION_OK)
+
+ message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
+ "but at least version ${Eigen3_FIND_VERSION} is required")
+ endif(NOT EIGEN3_VERSION_OK)
+endmacro(_eigen3_check_version)
+
+if (EIGEN3_INCLUDE_DIR)
+
+ # in cache already
+ _eigen3_check_version()
+ set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
+
+else (EIGEN3_INCLUDE_DIR)
+
+ find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
+ PATHS
+ ${CMAKE_INSTALL_PREFIX}/include
+ ${KDE4_INCLUDE_DIR}
+ PATH_SUFFIXES eigen3 eigen
+ )
+
+ if(EIGEN3_INCLUDE_DIR)
+ _eigen3_check_version()
+ endif(EIGEN3_INCLUDE_DIR)
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
+
+ mark_as_advanced(EIGEN3_INCLUDE_DIR)
+
+endif(EIGEN3_INCLUDE_DIR)
+
@@ -0,0 +1,160 @@
+###########################################################
+# Find OpenCV Library
+# See http://sourceforge.net/projects/opencvlibrary/
+#----------------------------------------------------------
+#
+## 1: Setup:
+# The following variables are optionally searched for defaults
+# OpenCV_DIR: Base directory of OpenCv tree to use.
+#
+## 2: Variable
+# The following are set after configuration is done:
+#
+# OpenCV_FOUND
+# OpenCV_LIBS
+# OpenCV_INCLUDE_DIR
+# OpenCV_VERSION (OpenCV_VERSION_MAJOR, OpenCV_VERSION_MINOR, OpenCV_VERSION_PATCH)
+#
+#
+# Deprecated variable are used to maintain backward compatibility with
+# the script of Jan Woetzel (2006/09): www.mip.informatik.uni-kiel.de/~jw
+# OpenCV_INCLUDE_DIRS
+# OpenCV_LIBRARIES
+# OpenCV_LINK_DIRECTORIES
+#
+## 3: Version
+#
+# 2010/04/07 Benoit Rat, Correct a bug when OpenCVConfig.cmake is not found.
+# 2010/03/24 Benoit Rat, Add compatibility for when OpenCVConfig.cmake is not found.
+# 2010/03/22 Benoit Rat, Creation of the script.
+#
+#
+# tested with:
+# - OpenCV 2.1: MinGW, MSVC2008
+# - OpenCV 2.0: MinGW, MSVC2008, GCC4
+#
+#
+## 4: Licence:
+#
+# LGPL 2.1 : GNU Lesser General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU Lesser
+
+# General Public License version 2.1 as published by the Free Software
+# Foundation and appearing in the file LICENSE.LGPL included in the
+# packaging of this file. Please review the following information to
+# ensure the GNU Lesser General Public License version 2.1 requirements
+# will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+#
+#----------------------------------------------------------
+
+
+find_path(OpenCV_DIR "OpenCVConfig.cmake" DOC "Root directory of OpenCV")
+
+##====================================================
+## Find OpenCV libraries
+##----------------------------------------------------
+if(EXISTS "${OpenCV_DIR}")
+
+ #When its possible to use the Config script use it.
+ if(EXISTS "${OpenCV_DIR}/OpenCVConfig.cmake")
+
+ ## Include the standard CMake script
+ include("${OpenCV_DIR}/OpenCVConfig.cmake")
+
+ ## Search for a specific version
+ set(CVLIB_SUFFIX "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}")
+
+ #Otherwise it try to guess it.
+ else(EXISTS "${OpenCV_DIR}/OpenCVConfig.cmake")
+
+ set(OPENCV_LIB_COMPONENTS cxcore cv ml highgui cvaux)
+ find_path(OpenCV_INCLUDE_DIR "cv.h" PATHS "${OpenCV_DIR}" PATH_SUFFIXES "include" "include/opencv" DOC "")
+ if(EXISTS ${OpenCV_INCLUDE_DIR})
+ include_directories(${OpenCV_INCLUDE_DIR})
+ endif(EXISTS ${OpenCV_INCLUDE_DIR})
+
+ #Find OpenCV version by looking at cvver.h
+ file(STRINGS ${OpenCV_INCLUDE_DIR}/cvver.h OpenCV_VERSIONS_TMP REGEX "^#define CV_[A-Z]+_VERSION[ \t]+[0-9]+$")
+ string(REGEX REPLACE ".*#define CV_MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" OpenCV_VERSION_MAJOR ${OpenCV_VERSIONS_TMP})
+ string(REGEX REPLACE ".*#define CV_MINOR_VERSION[ \t]+([0-9]+).*" "\\1" OpenCV_VERSION_MINOR ${OpenCV_VERSIONS_TMP})
+ string(REGEX REPLACE ".*#define CV_SUBMINOR_VERSION[ \t]+([0-9]+).*" "\\1" OpenCV_VERSION_PATCH ${OpenCV_VERSIONS_TMP})
+ set(OpenCV_VERSION ${OpenCV_VERSION_MAJOR}.${OpenCV_VERSION_MINOR}.${OpenCV_VERSION_PATCH} CACHE STRING "" FORCE)
+ set(CVLIB_SUFFIX "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}")
+
+ endif(EXISTS "${OpenCV_DIR}/OpenCVConfig.cmake")
+
+
+
+
+ ## Initiate the variable before the loop
+ set(GLOBAL OpenCV_LIBS "")
+ set(OpenCV_FOUND_TMP true)
+
+ ## Loop over each components
+ foreach(__CVLIB ${OPENCV_LIB_COMPONENTS})
+
+ find_library(OpenCV_${__CVLIB}_LIBRARY_DEBUG NAMES "${__CVLIB}${CVLIB_SUFFIX}d" "lib${__CVLIB}${CVLIB_SUFFIX}d" PATHS "${OpenCV_DIR}/lib" NO_DEFAULT_PATH)
+ find_library(OpenCV_${__CVLIB}_LIBRARY_RELEASE NAMES "${__CVLIB}${CVLIB_SUFFIX}" "lib${__CVLIB}${CVLIB_SUFFIX}" PATHS "${OpenCV_DIR}/lib" NO_DEFAULT_PATH)
+
+ #Remove the cache value
+ set(OpenCV_${__CVLIB}_LIBRARY "" CACHE STRING "" FORCE)
+
+ #both debug/release
+ if(OpenCV_${__CVLIB}_LIBRARY_DEBUG AND OpenCV_${__CVLIB}_LIBRARY_RELEASE)
+ set(OpenCV_${__CVLIB}_LIBRARY debug ${OpenCV_${__CVLIB}_LIBRARY_DEBUG} optimized ${OpenCV_${__CVLIB}_LIBRARY_RELEASE} CACHE STRING "" FORCE)
+ #only debug
+ elseif(OpenCV_${__CVLIB}_LIBRARY_DEBUG)
+ set(OpenCV_${__CVLIB}_LIBRARY ${OpenCV_${__CVLIB}_LIBRARY_DEBUG} CACHE STRING "" FORCE)
+ #only release
+ elseif(OpenCV_${__CVLIB}_LIBRARY_RELEASE)
+ set(OpenCV_${__CVLIB}_LIBRARY ${OpenCV_${__CVLIB}_LIBRARY_RELEASE} CACHE STRING "" FORCE)
+ #no library found
+ else()
+ set(OpenCV_FOUND_TMP false)
+ endif()
+
+ #Add to the general list
+ if(OpenCV_${__CVLIB}_LIBRARY)
+ set(OpenCV_LIBS ${OpenCV_LIBS} ${OpenCV_${__CVLIB}_LIBRARY})
+ endif(OpenCV_${__CVLIB}_LIBRARY)
+
+ endforeach(__CVLIB)
+
+
+ set(OpenCV_FOUND ${OpenCV_FOUND_TMP} CACHE BOOL "" FORCE)
+
+
+else(EXISTS "${OpenCV_DIR}")
+ set(ERR_MSG "Please specify OpenCV directory using OpenCV_DIR env. variable")
+endif(EXISTS "${OpenCV_DIR}")
+##====================================================
+
+
+##====================================================
+## Print message
+##----------------------------------------------------
+if(NOT OpenCV_FOUND)
+ # make FIND_PACKAGE friendly
+ if(NOT OpenCV_FIND_QUIETLY)
+ if(OpenCV_FIND_REQUIRED)
+ message(FATAL_ERROR "OpenCV required but some headers or libs not found. ${ERR_MSG}")
+ else(OpenCV_FIND_REQUIRED)
+ message(STATUS "WARNING: OpenCV was not found. ${ERR_MSG}")
+ endif(OpenCV_FIND_REQUIRED)
+ endif(NOT OpenCV_FIND_QUIETLY)
+endif(NOT OpenCV_FOUND)
+##====================================================
+
+
+##====================================================
+## Backward compatibility
+##----------------------------------------------------
+if(OpenCV_FOUND)
+ option(OpenCV_BACKWARD_COMPA "Add some variable to make this script compatible with the other version of FindOpenCV.cmake" false)
+ if(OpenCV_BACKWARD_COMPA)
+ find_path(OpenCV_INCLUDE_DIRS "cv.h" PATHS "${OpenCV_DIR}" PATH_SUFFIXES "include" "include/opencv" DOC "Include directory")
+ find_path(OpenCV_INCLUDE_DIR "cv.h" PATHS "${OpenCV_DIR}" PATH_SUFFIXES "include" "include/opencv" DOC "Include directory")
+ set(OpenCV_LIBRARIES "${OpenCV_LIBS}" CACHE STRING "" FORCE)
+ endif(OpenCV_BACKWARD_COMPA)
+endif(OpenCV_FOUND)
+##====================================================
@@ -0,0 +1,117 @@
+FIND_PATH(CHOLMOD_INCLUDE_DIR NAMES cholmod.h amd.h camd.h
+ PATHS
+ ${SUITE_SPARSE_ROOT}/include
+ /usr/include/suitesparse
+ /usr/include/ufsparse
+ /opt/local/include/ufsparse
+ /usr/local/include/ufsparse
+ /sw/include/ufsparse
+ )
+
+FIND_LIBRARY(CHOLMOD_LIBRARY NAMES cholmod
+ PATHS
+ ${SUITE_SPARSE_ROOT}/lib
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+ /sw/lib
+ )
+
+FIND_LIBRARY(AMD_LIBRARY NAMES SHARED NAMES amd
+ PATHS
+ ${SUITE_SPARSE_ROOT}/lib
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+ /sw/lib
+ )
+
+FIND_LIBRARY(CAMD_LIBRARY NAMES camd
+ PATHS
+ ${SUITE_SPARSE_ROOT}/lib
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+ /sw/lib
+ )
+
+# Different platforms seemingly require linking against different sets of libraries
+IF(CYGWIN)
+ FIND_PACKAGE(PkgConfig)
+ FIND_LIBRARY(COLAMD_LIBRARY NAMES colamd
+ PATHS
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+ /sw/lib
+ )
+ PKG_CHECK_MODULES(LAPACK lapack)
+
+ SET(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARY} ${AMD_LIBRARY} ${CAMD_LIBRARY} ${COLAMD_LIBRARY} ${CCOLAMD_LIBRARY} ${LAPACK_LIBRARIES})
+
+# MacPorts build of the SparseSuite requires linking against extra libraries
+
+ELSEIF(APPLE)
+
+ FIND_LIBRARY(COLAMD_LIBRARY NAMES colamd
+ PATHS
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+ /sw/lib
+ )
+
+ FIND_LIBRARY(CCOLAMD_LIBRARY NAMES ccolamd
+ PATHS
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+ /sw/lib
+ )
+
+ FIND_LIBRARY(METIS_LIBRARY NAMES metis
+ PATHS
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+ /sw/lib
+ )
+
+ SET(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARY} ${AMD_LIBRARY} ${CAMD_LIBRARY} ${COLAMD_LIBRARY} ${CCOLAMD_LIBRARY} ${METIS_LIBRARY} "-framework Accelerate")
+ELSE(APPLE)
+ SET(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARY} ${AMD_LIBRARY})
+ENDIF(CYGWIN)
+
+IF(CHOLMOD_INCLUDE_DIR AND CHOLMOD_LIBRARIES)
+ SET(CHOLMOD_FOUND TRUE)
+ELSE(CHOLMOD_INCLUDE_DIR AND CHOLMOD_LIBRARIES)
+ SET(CHOLMOD_FOUND FALSE)
+ENDIF(CHOLMOD_INCLUDE_DIR AND CHOLMOD_LIBRARIES)
+
+# Look for csparse; note the difference in the directory specifications!
+FIND_PATH(CSPARSE_INCLUDE_DIR NAMES cs.h
+ PATHS
+ /usr/include/suitesparse
+ /usr/include
+ /opt/local/include
+ /usr/local/include
+ /sw/include
+ /usr/include/ufsparse
+ /opt/local/include/ufsparse
+ /usr/local/include/ufsparse
+ /sw/include/ufsparse
+ )
+
+FIND_LIBRARY(CSPARSE_LIBRARY NAMES cxsparse
+ PATHS
+ /usr/lib
+ /usr/local/lib
+ /opt/local/lib
+ /sw/lib
+ )
+
+IF(CSPARSE_INCLUDE_DIR AND CSPARSE_LIBRARY)
+ SET(CSPARSE_FOUND TRUE)
+ELSE(CSPARSE_INCLUDE_DIR AND CSPARSE_LIBRARY)
+ SET(CSPARSE_FOUND FALSE)
+ENDIF(CSPARSE_INCLUDE_DIR AND CSPARSE_LIBRARY)
Oops, something went wrong.

0 comments on commit e95d742

Please sign in to comment.