From 73f7b82b2bc6937de93f3ebf790c1af7bb6b4e98 Mon Sep 17 00:00:00 2001 From: necusjz Date: Mon, 16 Jul 2018 17:55:05 +0800 Subject: [PATCH] add some cmake modules --- cmake_modules/FindBLAS.cmake | 419 ++++++++++++++++++++++++++++ cmake_modules/FindCSparse.cmake | 26 ++ cmake_modules/FindCholmod.cmake | 89 ++++++ cmake_modules/FindG2O.cmake | 113 ++++++++ cmake_modules/FindLAPACK.cmake | 273 ++++++++++++++++++ cmake_modules/FindQGLViewer.cmake | 45 +++ cmake_modules/FindSuiteSparse.cmake | 127 +++++++++ cmake_modules/octomap-config.cmake | 34 +++ 8 files changed, 1126 insertions(+) create mode 100644 cmake_modules/FindBLAS.cmake create mode 100644 cmake_modules/FindCSparse.cmake create mode 100644 cmake_modules/FindCholmod.cmake create mode 100644 cmake_modules/FindG2O.cmake create mode 100644 cmake_modules/FindLAPACK.cmake create mode 100644 cmake_modules/FindQGLViewer.cmake create mode 100644 cmake_modules/FindSuiteSparse.cmake create mode 100644 cmake_modules/octomap-config.cmake diff --git a/cmake_modules/FindBLAS.cmake b/cmake_modules/FindBLAS.cmake new file mode 100644 index 0000000..68c4e07 --- /dev/null +++ b/cmake_modules/FindBLAS.cmake @@ -0,0 +1,419 @@ +# Find BLAS library +# +# This module finds an installed library that implements the BLAS +# linear-algebra interface (see http://www.netlib.org/blas/). +# The list of libraries searched for is mainly taken +# from the autoconf macro file, acx_blas.m4 (distributed at +# http://ac-archive.sourceforge.net/ac-archive/acx_blas.html). +# +# This module sets the following variables: +# BLAS_FOUND - set to true if a library implementing the BLAS interface +# is found +# BLAS_INCLUDE_DIR - Directories containing the BLAS header files +# BLAS_DEFINITIONS - Compilation options to use BLAS +# BLAS_LINKER_FLAGS - Linker flags to use BLAS (excluding -l +# and -L). +# BLAS_LIBRARIES_DIR - Directories containing the BLAS libraries. +# May be null if BLAS_LIBRARIES contains libraries name using full path. +# BLAS_LIBRARIES - List of libraries to link against BLAS interface. +# May be null if the compiler supports auto-link (e.g. VC++). +# BLAS_USE_FILE - The name of the cmake module to include to compile +# applications or libraries using BLAS. +# +# This module was modified by CGAL team: +# - find libraries for a C++ compiler, instead of Fortran +# - added BLAS_INCLUDE_DIR, BLAS_DEFINITIONS and BLAS_LIBRARIES_DIR +# - removed BLAS95_LIBRARIES + +include(CheckFunctionExists) + + +# This macro checks for the existence of the combination of fortran libraries +# given by _list. If the combination is found, this macro checks (using the +# check_function_exists macro) whether can link against that library +# combination using the name of a routine given by _name using the linker +# flags given by _flags. If the combination of libraries is found and passes +# the link test, LIBRARIES is set to the list of complete library paths that +# have been found and DEFINITIONS to the required definitions. +# Otherwise, LIBRARIES is set to FALSE. +# N.B. _prefix is the prefix applied to the names of all cached variables that +# are generated internally and marked advanced by this macro. +macro(check_fortran_libraries DEFINITIONS LIBRARIES _prefix _name _flags _list _path) + #message("DEBUG: check_fortran_libraries(${_list} in ${_path})") + + # Check for the existence of the libraries given by _list + set(_libraries_found TRUE) + set(_libraries_work FALSE) + set(${DEFINITIONS} "") + set(${LIBRARIES} "") + set(_combined_name) + foreach(_library ${_list}) + set(_combined_name ${_combined_name}_${_library}) + + if(_libraries_found) + # search first in ${_path} + find_library(${_prefix}_${_library}_LIBRARY + NAMES ${_library} + PATHS ${_path} NO_DEFAULT_PATH + ) + # if not found, search in environment variables and system + if ( WIN32 ) + find_library(${_prefix}_${_library}_LIBRARY + NAMES ${_library} + PATHS ENV LIB + ) + elseif ( APPLE ) + find_library(${_prefix}_${_library}_LIBRARY + NAMES ${_library} + PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH + ) + else () + find_library(${_prefix}_${_library}_LIBRARY + NAMES ${_library} + PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH + ) + endif() + mark_as_advanced(${_prefix}_${_library}_LIBRARY) + set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) + set(_libraries_found ${${_prefix}_${_library}_LIBRARY}) + endif(_libraries_found) + endforeach(_library ${_list}) + if(_libraries_found) + set(_libraries_found ${${LIBRARIES}}) + endif() + + # Test this combination of libraries with the Fortran/f2c interface. + # We test the Fortran interface first as it is well standardized. + if(_libraries_found AND NOT _libraries_work) + set(${DEFINITIONS} "-D${_prefix}_USE_F2C") + set(${LIBRARIES} ${_libraries_found}) + # Some C++ linkers require the f2c library to link with Fortran libraries. + # I do not know which ones, thus I just add the f2c library if it is available. + find_package( F2C QUIET ) + if ( F2C_FOUND ) + set(${DEFINITIONS} ${${DEFINITIONS}} ${F2C_DEFINITIONS}) + set(${LIBRARIES} ${${LIBRARIES}} ${F2C_LIBRARIES}) + endif() + set(CMAKE_REQUIRED_DEFINITIONS ${${DEFINITIONS}}) + set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}}) + #message("DEBUG: CMAKE_REQUIRED_DEFINITIONS = ${CMAKE_REQUIRED_DEFINITIONS}") + #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}") + # Check if function exists with f2c calling convention (ie a trailing underscore) + check_function_exists(${_name}_ ${_prefix}_${_name}_${_combined_name}_f2c_WORKS) + set(CMAKE_REQUIRED_DEFINITIONS} "") + set(CMAKE_REQUIRED_LIBRARIES "") + mark_as_advanced(${_prefix}_${_name}_${_combined_name}_f2c_WORKS) + set(_libraries_work ${${_prefix}_${_name}_${_combined_name}_f2c_WORKS}) + endif(_libraries_found AND NOT _libraries_work) + + # If not found, test this combination of libraries with a C interface. + # A few implementations (ie ACML) provide a C interface. Unfortunately, there is no standard. + if(_libraries_found AND NOT _libraries_work) + set(${DEFINITIONS} "") + set(${LIBRARIES} ${_libraries_found}) + set(CMAKE_REQUIRED_DEFINITIONS "") + set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}}) + #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}") + check_function_exists(${_name} ${_prefix}_${_name}${_combined_name}_WORKS) + set(CMAKE_REQUIRED_LIBRARIES "") + mark_as_advanced(${_prefix}_${_name}${_combined_name}_WORKS) + set(_libraries_work ${${_prefix}_${_name}${_combined_name}_WORKS}) + endif(_libraries_found AND NOT _libraries_work) + + # on failure + if(NOT _libraries_work) + set(${DEFINITIONS} "") + set(${LIBRARIES} FALSE) + endif() + #message("DEBUG: ${DEFINITIONS} = ${${DEFINITIONS}}") + #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}") +endmacro(check_fortran_libraries) + + +# +# main +# + +# Is it already configured? +if (BLAS_LIBRARIES_DIR OR BLAS_LIBRARIES) + + set(BLAS_FOUND TRUE) + +else() + + # reset variables + set( BLAS_INCLUDE_DIR "" ) + set( BLAS_DEFINITIONS "" ) + set( BLAS_LINKER_FLAGS "" ) + set( BLAS_LIBRARIES "" ) + set( BLAS_LIBRARIES_DIR "" ) + + # + # If Unix, search for BLAS function in possible libraries + # + + # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/) + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "cblas;f77blas;atlas" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + # BLAS in PhiPACK libraries? (requires generic BLAS lib, too) + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "sgemm;dgemm;blas" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + # BLAS in Alpha CXML library? + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "cxml" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + # BLAS in Alpha DXML library? (now called CXML, see above) + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "dxml" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + # BLAS in Sun Performance library? + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "-xlic_lib=sunperf" + "sunperf;sunmath" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + if(BLAS_LIBRARIES) + # Extra linker flag + set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf") + endif() + endif() + + # BLAS in SCSL library? (SGI/Cray Scientific Library) + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "scsl" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + # BLAS in SGIMATH library? + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "complib.sgimath" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + # BLAS in IBM ESSL library? (requires generic BLAS lib, too) + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "essl;blas" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + #BLAS in intel mkl 10 library? (em64t 64bit) + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide;pthread" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + ### windows version of intel mkl 10? + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + SGEMM + "" + "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + #older versions of intel mkl libs + + # BLAS in intel mkl library? (shared) + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "mkl;guide;pthread" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + #BLAS in intel mkl library? (static, 32bit) + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "mkl_ia32;guide;pthread" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + #BLAS in intel mkl library? (static, em64t 64bit) + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "mkl_em64t;guide;pthread" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + #BLAS in acml library? + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "acml" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + # Apple BLAS library? + if(NOT BLAS_LIBRARIES) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "Accelerate" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + if ( NOT BLAS_LIBRARIES ) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "vecLib" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif ( NOT BLAS_LIBRARIES ) + + # Generic BLAS library? + # This configuration *must* be the last try as this library is notably slow. + if ( NOT BLAS_LIBRARIES ) + check_fortran_libraries( + BLAS_DEFINITIONS + BLAS_LIBRARIES + BLAS + sgemm + "" + "blas" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR" + ) + endif() + + if(BLAS_LIBRARIES_DIR OR BLAS_LIBRARIES) + set(BLAS_FOUND TRUE) + else() + set(BLAS_FOUND FALSE) + endif() + + if(NOT BLAS_FIND_QUIETLY) + if(BLAS_FOUND) + message(STATUS "A library with BLAS API found.") + else(BLAS_FOUND) + if(BLAS_FIND_REQUIRED) + message(FATAL_ERROR "A required library with BLAS API not found. Please specify library location.") + else() + message(STATUS "A library with BLAS API not found. Please specify library location.") + endif() + endif(BLAS_FOUND) + endif(NOT BLAS_FIND_QUIETLY) + + # Add variables to cache + set( BLAS_INCLUDE_DIR "${BLAS_INCLUDE_DIR}" + CACHE PATH "Directories containing the BLAS header files" FORCE ) + set( BLAS_DEFINITIONS "${BLAS_DEFINITIONS}" + CACHE STRING "Compilation options to use BLAS" FORCE ) + set( BLAS_LINKER_FLAGS "${BLAS_LINKER_FLAGS}" + CACHE STRING "Linker flags to use BLAS" FORCE ) + set( BLAS_LIBRARIES "${BLAS_LIBRARIES}" + CACHE FILEPATH "BLAS libraries name" FORCE ) + set( BLAS_LIBRARIES_DIR "${BLAS_LIBRARIES_DIR}" + CACHE PATH "Directories containing the BLAS libraries" FORCE ) + + #message("DEBUG: BLAS_INCLUDE_DIR = ${BLAS_INCLUDE_DIR}") + #message("DEBUG: BLAS_DEFINITIONS = ${BLAS_DEFINITIONS}") + #message("DEBUG: BLAS_LINKER_FLAGS = ${BLAS_LINKER_FLAGS}") + #message("DEBUG: BLAS_LIBRARIES = ${BLAS_LIBRARIES}") + #message("DEBUG: BLAS_LIBRARIES_DIR = ${BLAS_LIBRARIES_DIR}") + #message("DEBUG: BLAS_FOUND = ${BLAS_FOUND}") + +endif(BLAS_LIBRARIES_DIR OR BLAS_LIBRARIES) diff --git a/cmake_modules/FindCSparse.cmake b/cmake_modules/FindCSparse.cmake new file mode 100644 index 0000000..bd70366 --- /dev/null +++ b/cmake_modules/FindCSparse.cmake @@ -0,0 +1,26 @@ +# 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 + /usr/local/include/EXTERNAL/csparse + ) + +FIND_LIBRARY(CSPARSE_LIBRARY NAMES cxsparse + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CSPARSE DEFAULT_MSG + CSPARSE_INCLUDE_DIR CSPARSE_LIBRARY) diff --git a/cmake_modules/FindCholmod.cmake b/cmake_modules/FindCholmod.cmake new file mode 100644 index 0000000..3f77ba0 --- /dev/null +++ b/cmake_modules/FindCholmod.cmake @@ -0,0 +1,89 @@ +# Cholmod lib usually requires linking to a blas and lapack library. +# It is up to the user of this module to find a BLAS and link to it. + +if (CHOLMOD_INCLUDE_DIR AND CHOLMOD_LIBRARIES) + set(CHOLMOD_FIND_QUIETLY TRUE) +endif (CHOLMOD_INCLUDE_DIR AND CHOLMOD_LIBRARIES) + +find_path(CHOLMOD_INCLUDE_DIR + NAMES + cholmod.h + PATHS + $ENV{CHOLMODDIR} + ${INCLUDE_INSTALL_DIR} + PATH_SUFFIXES + suitesparse + ufsparse +) + +find_library(CHOLMOD_LIBRARY cholmod PATHS $ENV{CHOLMODDIR} ${LIB_INSTALL_DIR}) +set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARY}) + +if(CHOLMOD_LIBRARIES) + + get_filename_component(CHOLMOD_LIBDIR ${CHOLMOD_LIBRARIES} PATH) + + find_library(AMD_LIBRARY amd PATHS ${CHOLMOD_LIBDIR} $ENV{CHOLMODDIR} ${LIB_INSTALL_DIR}) + if (AMD_LIBRARY) + set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARIES} ${AMD_LIBRARY}) + else () + set(CHOLMOD_LIBRARIES FALSE) + endif () + +endif(CHOLMOD_LIBRARIES) + +if(CHOLMOD_LIBRARIES) + + find_library(COLAMD_LIBRARY colamd PATHS ${CHOLMOD_LIBDIR} $ENV{CHOLMODDIR} ${LIB_INSTALL_DIR}) + if (COLAMD_LIBRARY) + set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARIES} ${COLAMD_LIBRARY}) + else () + set(CHOLMOD_LIBRARIES FALSE) + endif () + +endif(CHOLMOD_LIBRARIES) + +if(CHOLMOD_LIBRARIES) + + find_library(CAMD_LIBRARY camd PATHS ${CHOLMOD_LIBDIR} $ENV{CHOLMODDIR} ${LIB_INSTALL_DIR}) + if (CAMD_LIBRARY) + set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARIES} ${CAMD_LIBRARY}) + else () + set(CHOLMOD_LIBRARIES FALSE) + endif () + +endif(CHOLMOD_LIBRARIES) + +if(CHOLMOD_LIBRARIES) + + find_library(CCOLAMD_LIBRARY ccolamd PATHS ${CHOLMOD_LIBDIR} $ENV{CHOLMODDIR} ${LIB_INSTALL_DIR}) + if (CCOLAMD_LIBRARY) + set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARIES} ${CCOLAMD_LIBRARY}) + else () + set(CHOLMOD_LIBRARIES FALSE) + endif () + +endif(CHOLMOD_LIBRARIES) + +if(CHOLMOD_LIBRARIES) + + find_library(CHOLMOD_METIS_LIBRARY metis PATHS ${CHOLMOD_LIBDIR} $ENV{CHOLMODDIR} ${LIB_INSTALL_DIR}) + if (CHOLMOD_METIS_LIBRARY) + set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARIES} ${CHOLMOD_METIS_LIBRARY}) + endif () + +endif(CHOLMOD_LIBRARIES) + +if(CHOLMOD_LIBRARIES) + find_library(SUITESPARSECONFIG_LIBRARY NAMES suitesparseconfig + PATHS ${CHOLMOD_LIBDIR} $ENV{CHOLMODDIR} ${LIB_INSTALL_DIR}) + if (SUITESPARSECONFIG_LIBRARY) + set(CHOLMOD_LIBRARIES ${CHOLMOD_LIBRARIES} ${SUITESPARSECONFIG_LIBRARY}) + endif () +endif(CHOLMOD_LIBRARIES) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CHOLMOD DEFAULT_MSG + CHOLMOD_INCLUDE_DIR CHOLMOD_LIBRARIES) + +mark_as_advanced(CHOLMOD_LIBRARIES) diff --git a/cmake_modules/FindG2O.cmake b/cmake_modules/FindG2O.cmake new file mode 100644 index 0000000..655600f --- /dev/null +++ b/cmake_modules/FindG2O.cmake @@ -0,0 +1,113 @@ +# Find the header files + +FIND_PATH(G2O_INCLUDE_DIR g2o/core/base_vertex.h + ${G2O_ROOT}/include + $ENV{G2O_ROOT}/include + $ENV{G2O_ROOT} + /usr/local/include + /usr/include + /opt/local/include + /sw/local/include + /sw/include + NO_DEFAULT_PATH + ) + +# Macro to unify finding both the debug and release versions of the +# libraries; this is adapted from the OpenSceneGraph FIND_LIBRARY +# macro. + +MACRO(FIND_G2O_LIBRARY MYLIBRARY MYLIBRARYNAME) + + FIND_LIBRARY("${MYLIBRARY}_DEBUG" + NAMES "g2o_${MYLIBRARYNAME}_d" + PATHS + ${G2O_ROOT}/lib/Debug + ${G2O_ROOT}/lib + $ENV{G2O_ROOT}/lib/Debug + $ENV{G2O_ROOT}/lib + NO_DEFAULT_PATH + ) + + FIND_LIBRARY("${MYLIBRARY}_DEBUG" + NAMES "g2o_${MYLIBRARYNAME}_d" + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/lib + /usr/local/lib64 + /usr/lib + /usr/lib64 + /opt/local/lib + /sw/local/lib + /sw/lib + ) + + FIND_LIBRARY(${MYLIBRARY} + NAMES "g2o_${MYLIBRARYNAME}" + PATHS + ${G2O_ROOT}/lib/Release + ${G2O_ROOT}/lib + $ENV{G2O_ROOT}/lib/Release + $ENV{G2O_ROOT}/lib + NO_DEFAULT_PATH + ) + + FIND_LIBRARY(${MYLIBRARY} + NAMES "g2o_${MYLIBRARYNAME}" + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/lib + /usr/local/lib64 + /usr/lib + /usr/lib64 + /opt/local/lib + /sw/local/lib + /sw/lib + ) + + IF(NOT ${MYLIBRARY}_DEBUG) + IF(MYLIBRARY) + SET(${MYLIBRARY}_DEBUG ${MYLIBRARY}) + ENDIF(MYLIBRARY) + ENDIF( NOT ${MYLIBRARY}_DEBUG) + +ENDMACRO(FIND_G2O_LIBRARY LIBRARY LIBRARYNAME) + +# Find the core elements +FIND_G2O_LIBRARY(G2O_STUFF_LIBRARY stuff) +FIND_G2O_LIBRARY(G2O_CORE_LIBRARY core) + +# Find the CLI library +FIND_G2O_LIBRARY(G2O_CLI_LIBRARY cli) + +# Find the pluggable solvers +FIND_G2O_LIBRARY(G2O_SOLVER_CHOLMOD solver_cholmod) +FIND_G2O_LIBRARY(G2O_SOLVER_CSPARSE solver_csparse) +FIND_G2O_LIBRARY(G2O_SOLVER_CSPARSE_EXTENSION csparse_extension) +FIND_G2O_LIBRARY(G2O_SOLVER_DENSE solver_dense) +FIND_G2O_LIBRARY(G2O_SOLVER_PCG solver_pcg) +FIND_G2O_LIBRARY(G2O_SOLVER_SLAM2D_LINEAR solver_slam2d_linear) +FIND_G2O_LIBRARY(G2O_SOLVER_STRUCTURE_ONLY solver_structure_only) +FIND_G2O_LIBRARY(G2O_SOLVER_EIGEN solver_eigen) + +# Find the predefined types +FIND_G2O_LIBRARY(G2O_TYPES_DATA types_data) +FIND_G2O_LIBRARY(G2O_TYPES_ICP types_icp) +FIND_G2O_LIBRARY(G2O_TYPES_SBA types_sba) +FIND_G2O_LIBRARY(G2O_TYPES_SCLAM2D types_sclam2d) +FIND_G2O_LIBRARY(G2O_TYPES_SIM3 types_sim3) +FIND_G2O_LIBRARY(G2O_TYPES_SLAM2D types_slam2d) +FIND_G2O_LIBRARY(G2O_TYPES_SLAM3D types_slam3d) + +# G2O solvers declared found if we found at least one solver +SET(G2O_SOLVERS_FOUND "NO") +IF(G2O_SOLVER_CHOLMOD OR G2O_SOLVER_CSPARSE OR G2O_SOLVER_DENSE OR G2O_SOLVER_PCG OR G2O_SOLVER_SLAM2D_LINEAR OR G2O_SOLVER_STRUCTURE_ONLY OR G2O_SOLVER_EIGEN) + SET(G2O_SOLVERS_FOUND "YES") +ENDIF(G2O_SOLVER_CHOLMOD OR G2O_SOLVER_CSPARSE OR G2O_SOLVER_DENSE OR G2O_SOLVER_PCG OR G2O_SOLVER_SLAM2D_LINEAR OR G2O_SOLVER_STRUCTURE_ONLY OR G2O_SOLVER_EIGEN) + +# G2O itself declared found if we found the core libraries and at least one solver +SET(G2O_FOUND "NO") +IF(G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND) + SET(G2O_FOUND "YES") +ENDIF(G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND) diff --git a/cmake_modules/FindLAPACK.cmake b/cmake_modules/FindLAPACK.cmake new file mode 100644 index 0000000..2fcae21 --- /dev/null +++ b/cmake_modules/FindLAPACK.cmake @@ -0,0 +1,273 @@ +# Find LAPACK library +# +# This module finds an installed library that implements the LAPACK +# linear-algebra interface (see http://www.netlib.org/lapack/). +# The approach follows mostly that taken for the autoconf macro file, acx_lapack.m4 +# (distributed at http://ac-archive.sourceforge.net/ac-archive/acx_lapack.html). +# +# This module sets the following variables: +# LAPACK_FOUND - set to true if a library implementing the LAPACK interface +# is found +# LAPACK_INCLUDE_DIR - Directories containing the LAPACK header files +# LAPACK_DEFINITIONS - Compilation options to use LAPACK +# LAPACK_LINKER_FLAGS - Linker flags to use LAPACK (excluding -l +# and -L). +# LAPACK_LIBRARIES_DIR - Directories containing the LAPACK libraries. +# May be null if LAPACK_LIBRARIES contains libraries name using full path. +# LAPACK_LIBRARIES - List of libraries to link against LAPACK interface. +# May be null if the compiler supports auto-link (e.g. VC++). +# LAPACK_USE_FILE - The name of the cmake module to include to compile +# applications or libraries using LAPACK. +# +# This module was modified by CGAL team: +# - find libraries for a C++ compiler, instead of Fortran +# - added LAPACK_INCLUDE_DIR, LAPACK_DEFINITIONS and LAPACK_LIBRARIES_DIR +# - removed LAPACK95_LIBRARIES + + +include(CheckFunctionExists) + +# This macro checks for the existence of the combination of fortran libraries +# given by _list. If the combination is found, this macro checks (using the +# check_function_exists macro) whether can link against that library +# combination using the name of a routine given by _name using the linker +# flags given by _flags. If the combination of libraries is found and passes +# the link test, LIBRARIES is set to the list of complete library paths that +# have been found and DEFINITIONS to the required definitions. +# Otherwise, LIBRARIES is set to FALSE. +# N.B. _prefix is the prefix applied to the names of all cached variables that +# are generated internally and marked advanced by this macro. +macro(check_lapack_libraries DEFINITIONS LIBRARIES _prefix _name _flags _list _blas _path) + #message("DEBUG: check_lapack_libraries(${_list} in ${_path} with ${_blas})") + + # Check for the existence of the libraries given by _list + set(_libraries_found TRUE) + set(_libraries_work FALSE) + set(${DEFINITIONS} "") + set(${LIBRARIES} "") + set(_combined_name) + foreach(_library ${_list}) + set(_combined_name ${_combined_name}_${_library}) + + if(_libraries_found) + # search first in ${_path} + find_library(${_prefix}_${_library}_LIBRARY + NAMES ${_library} + PATHS ${_path} NO_DEFAULT_PATH + ) + # if not found, search in environment variables and system + if ( WIN32 ) + find_library(${_prefix}_${_library}_LIBRARY + NAMES ${_library} + PATHS ENV LIB + ) + elseif ( APPLE ) + find_library(${_prefix}_${_library}_LIBRARY + NAMES ${_library} + PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH + ) + else () + find_library(${_prefix}_${_library}_LIBRARY + NAMES ${_library} + PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH + ) + endif() + mark_as_advanced(${_prefix}_${_library}_LIBRARY) + set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) + set(_libraries_found ${${_prefix}_${_library}_LIBRARY}) + endif(_libraries_found) + endforeach(_library ${_list}) + if(_libraries_found) + set(_libraries_found ${${LIBRARIES}}) + endif() + + # Test this combination of libraries with the Fortran/f2c interface. + # We test the Fortran interface first as it is well standardized. + if(_libraries_found AND NOT _libraries_work) + set(${DEFINITIONS} "-D${_prefix}_USE_F2C") + set(${LIBRARIES} ${_libraries_found}) + # Some C++ linkers require the f2c library to link with Fortran libraries. + # I do not know which ones, thus I just add the f2c library if it is available. + find_package( F2C QUIET ) + if ( F2C_FOUND ) + set(${DEFINITIONS} ${${DEFINITIONS}} ${F2C_DEFINITIONS}) + set(${LIBRARIES} ${${LIBRARIES}} ${F2C_LIBRARIES}) + endif() + set(CMAKE_REQUIRED_DEFINITIONS ${${DEFINITIONS}}) + set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas}) + #message("DEBUG: CMAKE_REQUIRED_DEFINITIONS = ${CMAKE_REQUIRED_DEFINITIONS}") + #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}") + # Check if function exists with f2c calling convention (ie a trailing underscore) + check_function_exists(${_name}_ ${_prefix}_${_name}_${_combined_name}_f2c_WORKS) + set(CMAKE_REQUIRED_DEFINITIONS} "") + set(CMAKE_REQUIRED_LIBRARIES "") + mark_as_advanced(${_prefix}_${_name}_${_combined_name}_f2c_WORKS) + set(_libraries_work ${${_prefix}_${_name}_${_combined_name}_f2c_WORKS}) + endif(_libraries_found AND NOT _libraries_work) + + # If not found, test this combination of libraries with a C interface. + # A few implementations (ie ACML) provide a C interface. Unfortunately, there is no standard. + if(_libraries_found AND NOT _libraries_work) + set(${DEFINITIONS} "") + set(${LIBRARIES} ${_libraries_found}) + set(CMAKE_REQUIRED_DEFINITIONS "") + set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas}) + #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}") + check_function_exists(${_name} ${_prefix}_${_name}${_combined_name}_WORKS) + set(CMAKE_REQUIRED_LIBRARIES "") + mark_as_advanced(${_prefix}_${_name}${_combined_name}_WORKS) + set(_libraries_work ${${_prefix}_${_name}${_combined_name}_WORKS}) + endif(_libraries_found AND NOT _libraries_work) + + # on failure + if(NOT _libraries_work) + set(${DEFINITIONS} "") + set(${LIBRARIES} FALSE) + endif() + #message("DEBUG: ${DEFINITIONS} = ${${DEFINITIONS}}") + #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}") +endmacro(check_lapack_libraries) + + +# +# main +# + +# LAPACK requires BLAS +if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) + find_package(BLAS) +else() + find_package(BLAS REQUIRED) +endif() + +if (NOT BLAS_FOUND) + + message(STATUS "LAPACK requires BLAS.") + set(LAPACK_FOUND FALSE) + +# Is it already configured? +elseif (LAPACK_LIBRARIES_DIR OR LAPACK_LIBRARIES) + + set(LAPACK_FOUND TRUE) + +else() + + # reset variables + set( LAPACK_INCLUDE_DIR "" ) + set( LAPACK_DEFINITIONS "" ) + set( LAPACK_LINKER_FLAGS "" ) # unused (yet) + set( LAPACK_LIBRARIES "" ) + set( LAPACK_LIBRARIES_DIR "" ) + + # + # If Unix, search for LAPACK function in possible libraries + # + + #intel mkl lapack? + if(NOT LAPACK_LIBRARIES) + check_lapack_libraries( + LAPACK_DEFINITIONS + LAPACK_LIBRARIES + LAPACK + cheev + "" + "mkl_lapack" + "${BLAS_LIBRARIES}" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR" + ) + endif() + + #acml lapack? + if(NOT LAPACK_LIBRARIES) + check_lapack_libraries( + LAPACK_DEFINITIONS + LAPACK_LIBRARIES + LAPACK + cheev + "" + "acml" + "${BLAS_LIBRARIES}" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR" + ) + endif() + + # Apple LAPACK library? + if(NOT LAPACK_LIBRARIES) + check_lapack_libraries( + LAPACK_DEFINITIONS + LAPACK_LIBRARIES + LAPACK + cheev + "" + "Accelerate" + "${BLAS_LIBRARIES}" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR" + ) + endif() + + if ( NOT LAPACK_LIBRARIES ) + check_lapack_libraries( + LAPACK_DEFINITIONS + LAPACK_LIBRARIES + LAPACK + cheev + "" + "vecLib" + "${BLAS_LIBRARIES}" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR" + ) + endif ( NOT LAPACK_LIBRARIES ) + + # Generic LAPACK library? + # This configuration *must* be the last try as this library is notably slow. + if ( NOT LAPACK_LIBRARIES ) + check_lapack_libraries( + LAPACK_DEFINITIONS + LAPACK_LIBRARIES + LAPACK + cheev + "" + "lapack" + "${BLAS_LIBRARIES}" + "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR" + ) + endif() + + if(LAPACK_LIBRARIES_DIR OR LAPACK_LIBRARIES) + set(LAPACK_FOUND TRUE) + else() + set(LAPACK_FOUND FALSE) + endif() + + if(NOT LAPACK_FIND_QUIETLY) + if(LAPACK_FOUND) + message(STATUS "A library with LAPACK API found.") + else(LAPACK_FOUND) + if(LAPACK_FIND_REQUIRED) + message(FATAL_ERROR "A required library with LAPACK API not found. Please specify library location.") + else() + message(STATUS "A library with LAPACK API not found. Please specify library location.") + endif() + endif(LAPACK_FOUND) + endif(NOT LAPACK_FIND_QUIETLY) + + # Add variables to cache + set( LAPACK_INCLUDE_DIR "${LAPACK_INCLUDE_DIR}" + CACHE PATH "Directories containing the LAPACK header files" FORCE ) + set( LAPACK_DEFINITIONS "${LAPACK_DEFINITIONS}" + CACHE STRING "Compilation options to use LAPACK" FORCE ) + set( LAPACK_LINKER_FLAGS "${LAPACK_LINKER_FLAGS}" + CACHE STRING "Linker flags to use LAPACK" FORCE ) + set( LAPACK_LIBRARIES "${LAPACK_LIBRARIES}" + CACHE FILEPATH "LAPACK libraries name" FORCE ) + set( LAPACK_LIBRARIES_DIR "${LAPACK_LIBRARIES_DIR}" + CACHE PATH "Directories containing the LAPACK libraries" FORCE ) + + #message("DEBUG: LAPACK_INCLUDE_DIR = ${LAPACK_INCLUDE_DIR}") + #message("DEBUG: LAPACK_DEFINITIONS = ${LAPACK_DEFINITIONS}") + #message("DEBUG: LAPACK_LINKER_FLAGS = ${LAPACK_LINKER_FLAGS}") + #message("DEBUG: LAPACK_LIBRARIES = ${LAPACK_LIBRARIES}") + #message("DEBUG: LAPACK_LIBRARIES_DIR = ${LAPACK_LIBRARIES_DIR}") + #message("DEBUG: LAPACK_FOUND = ${LAPACK_FOUND}") + +endif(NOT BLAS_FOUND) diff --git a/cmake_modules/FindQGLViewer.cmake b/cmake_modules/FindQGLViewer.cmake new file mode 100644 index 0000000..92ccddf --- /dev/null +++ b/cmake_modules/FindQGLViewer.cmake @@ -0,0 +1,45 @@ +# Need to find both Qt4 and QGLViewer if the QQL support is to be built +FIND_PACKAGE(Qt4 COMPONENTS QtCore QtXml QtOpenGL QtGui) + +FIND_PATH(QGLVIEWER_INCLUDE_DIR qglviewer.h + /usr/include/QGLViewer + /opt/local/include/QGLViewer + /usr/local/include/QGLViewer + /sw/include/QGLViewer + ENV QGLVIEWERROOT + ) + +find_library(QGLVIEWER_LIBRARY_RELEASE + NAMES qglviewer-qt4 qglviewer QGLViewer QGLViewer2 + PATHS /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ENV QGLVIEWERROOT + ENV LD_LIBRARY_PATH + ENV LIBRARY_PATH + PATH_SUFFIXES QGLViewer QGLViewer/release +) +find_library(QGLVIEWER_LIBRARY_DEBUG + NAMES dqglviewer dQGLViewer dQGLViewer2 QGLViewerd2 + PATHS /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ENV QGLVIEWERROOT + ENV LD_LIBRARY_PATH + ENV LIBRARY_PATH + PATH_SUFFIXES QGLViewer QGLViewer/release +) + +if(QGLVIEWER_LIBRARY_RELEASE) + if(QGLVIEWER_LIBRARY_DEBUG) + set(QGLVIEWER_LIBRARY optimized ${QGLVIEWER_LIBRARY_RELEASE} debug ${QGLVIEWER_LIBRARY_DEBUG}) + else() + set(QGLVIEWER_LIBRARY ${QGLVIEWER_LIBRARY_RELEASE}) + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(QGLVIEWER DEFAULT_MSG + QGLVIEWER_INCLUDE_DIR QGLVIEWER_LIBRARY) diff --git a/cmake_modules/FindSuiteSparse.cmake b/cmake_modules/FindSuiteSparse.cmake new file mode 100644 index 0000000..94b7614 --- /dev/null +++ b/cmake_modules/FindSuiteSparse.cmake @@ -0,0 +1,127 @@ +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 + ) + +FIND_LIBRARY(SUITESPARSECONFIG_LIBRARY NAMES suitesparseconfig + 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) diff --git a/cmake_modules/octomap-config.cmake b/cmake_modules/octomap-config.cmake new file mode 100644 index 0000000..a335154 --- /dev/null +++ b/cmake_modules/octomap-config.cmake @@ -0,0 +1,34 @@ +# =================================================================================== +# The OctoMap CMake configuration file +# +# ** File generated automatically, do not modify ** +# +# Usage from an external project: +# In your CMakeLists.txt, add these lines: +# +# FIND_PACKAGE(octomap REQUIRED ) +# INCLUDE_DIRECTORIES(${OCTOMAP_INCLUDE_DIRS}) +# TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${OCTOMAP_LIBRARIES}) +# +# +# This file will define the following variables: +# - OCTOMAP_LIBRARIES : The list of libraries to links against. +# - OCTOMAP_LIBRARY_DIRS : The directory where lib files are. Calling +# LINK_DIRECTORIES with this path is NOT needed. +# - OCTOMAP_INCLUDE_DIRS : The OctoMap include directories. +# +# Based on the example CMake Tutorial +# http://www.vtk.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file +# and OpenCVConfig.cmake.in from OpenCV +# =================================================================================== + + +set(OCTOMAP_INCLUDE_DIRS "/home/zero/Documents/code/octomap/octomap/include") +set(OCTOMAP_LIBRARY_DIRS "/home/zero/Documents/code/octomap/lib") + + +# Set library names as absolute paths: +set(OCTOMAP_LIBRARIES + "/home/zero/Documents/code/octomap/lib/liboctomap.so" + "/home/zero/Documents/code/octomap/lib/liboctomath.so" +)