FindShark.cmake 4.54 KB
Newer Older
1
#
Julien Michel's avatar
Julien Michel committed
2
# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#
# This file is part of Orfeo Toolbox
#
#     https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
# - Find Shark
# Find the Shark includes and library
#
#   SHARK_FOUND       - True if Shark found.
#   SHARK_INCLUDE_DIR - where to find Core/shark.h
#   SHARK_LIBRARIES   - List of libraries required for shark.
#

set(SHARK_SEARCH_PATH)

set(SHARK_CONFIG_FILE)

if(Shark_DIR)
  get_filename_component(SHARK_SEARCH_PATH "${Shark_DIR}" PATH)
  get_filename_component(SHARK_SEARCH_PATH "${SHARK_SEARCH_PATH}" PATH)
  get_filename_component(SHARK_SEARCH_PATH "${SHARK_SEARCH_PATH}" PATH)

  if(EXISTS "${Shark_DIR}/SharkConfig.cmake")
    set(SHARK_CONFIG_FILE ${Shark_DIR}/SharkConfig.cmake)
  endif()

endif() #if(Shark_DIR)

44 45
find_path( SHARK_INCLUDE_DIR
  NAMES shark/Core/Shark.h
46
  PATHS "${SHARK_SEARCH_PATH}"
47
  PATH_SUFFIXES include include/shark shark
48
  )
49 50

find_library( SHARK_LIBRARY
51
  NAMES shark shark_debug
52 53 54 55
  PATHS "${SHARK_SEARCH_PATH}"
  PATH_SUFFIXES lib
  )

56 57
mark_as_advanced( SHARK_INCLUDE_DIR  SHARK_LIBRARY )

58 59 60
find_package( Boost 1.48.0 REQUIRED QUIET
  COMPONENTS serialization
  )
61 62 63 64
if(NOT Boost_FOUND)
  message(FATAL_ERROR "Please make sure Boost 1.48.0 is installed on your system")
endif()

65 66 67 68 69 70 71 72 73 74 75 76 77
if(NOT SHARK_LIBRARY)
  message(FATAL_ERROR "Cannot find SHARK_LIBRARY. set it with cmake -DSHARK_LIBRARY=")
  return()
endif()

if(NOT SHARK_INCLUDE_DIR)
  message(FATAL_ERROR "Cannot find SHARK_INCLUDE_DIR. Set it with cmake -DSHARK_INCLUDE_DIR=")
  return()
endif()

get_filename_component(SHARK_INSTALLDIR ${SHARK_LIBRARY} PATH)
get_filename_component(SHARK_INSTALLDIR ${SHARK_INSTALLDIR} PATH)

78
if(NOT SHARK_CONFIG_FILE)
79 80 81
  find_file(SHARK_CONFIG_FILE SharkConfig.cmake
    PATHS ${SHARK_INSTALLDIR}
    PATH_SUFFIXES lib/cmake/Shark share/Shark cmake/Shark)
82
endif()
83

84 85 86 87 88 89 90 91 92 93 94 95 96 97
if(SHARK_CONFIG_FILE)
  file(STRINGS "${SHARK_CONFIG_FILE}" SHARK_CONFIG_FILE_CONTENTS)
  string(REGEX REPLACE
      ".*set.*\\(SHARK_VERSION_MAJOR..([0-9]+)\"\\).*" "\\1"
       SHARK_VERSION_MAJOR "${SHARK_CONFIG_FILE_CONTENTS}")
  string(REGEX REPLACE
      ".*set.*\\(SHARK_VERSION_MINOR..([0-9]+)\"\\).*" "\\1"
       SHARK_VERSION_MINOR "${SHARK_CONFIG_FILE_CONTENTS}")
  string(REGEX REPLACE
      ".*set.*\\(SHARK_VERSION_PATCH..([0-9]+)\"\\).*" "\\1"
       SHARK_VERSION_PATCH "${SHARK_CONFIG_FILE_CONTENTS}")       

  set(SHARK_VERSION_STRING 
  "${SHARK_VERSION_MAJOR}.${SHARK_VERSION_MINOR}.${SHARK_VERSION_PATCH}")
98 99
endif()

100 101 102 103 104
# reset required flags
set(SHARK_REQUIRED_C_FLAGS "")
set(SHARK_REQUIRED_CXX_FLAGS "")
set(SHARK_REQUIRED_LINK_FLAGS "")

105
# Check if Shark was built with OpenMP, CBLAS, DYNLIB, ...
106
file(STRINGS "${SHARK_INCLUDE_DIR}/shark/Core/Shark.h" SHARK_H_CONTENTS)
107

108 109
if(SHARK_H_CONTENTS MATCHES "#define.SHARK_USE_OPENMP")
  set(SHARK_USE_OPENMP 1)
110 111 112 113 114 115 116 117
  find_package(OpenMP QUIET)
  if(OPENMP_FOUND)
    set(SHARK_REQUIRED_C_FLAGS "${SHARK_REQUIRED_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(SHARK_REQUIRED_CXX_FLAGS "${SHARK_REQUIRED_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    if(OpenMP_EXE_LINKER_FLAGS)
      set(SHARK_REQUIRED_LINK_FLAGS "${SHARK_REQUIRED_LINK_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
    endif()
  endif()
118 119 120 121 122 123 124 125 126 127 128 129 130 131
else()
  set(SHARK_USE_OPENMP 0)
endif()

if(SHARK_H_CONTENTS MATCHES "#define.SHARK_USE_CBLAS")
  set(SHARK_USE_CBLAS 1)
else()
  set(SHARK_USE_CBLAS 0)
endif()

if(SHARK_H_CONTENTS MATCHES "#define.SHARK_USE_DYNLIB")
  set(SHARK_USE_DYNLIB 1)
else()
  set(SHARK_USE_DYNLIB 0)
132
endif()
133

134 135
if(SHARK_USE_CBLAS AND SHARK_USE_DYNLIB)
  set(REQUIRED_CBLAS_LIB CBLAS_LIBRARY)
136
  find_library(CBLAS_LIBRARY NAMES cblas blas PATH_SUFFIXES blas)
137 138 139 140
else()
  set(REQUIRED_CBLAS_LIB)
endif()

141 142
INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Shark
143
  REQUIRED_VARS SHARK_LIBRARY SHARK_INCLUDE_DIR ${REQUIRED_CBLAS_LIB}
144 145
  VERSION_VAR SHARK_VERSION_STRING)

146 147 148
if(SHARK_FOUND)
  set(SHARK_INCLUDE_DIRS ${SHARK_INCLUDE_DIR} ${Boost_INCLUDE_DIR} )
  set(SHARK_LIBRARIES ${SHARK_LIBRARY} ${Boost_LIBRARIES} )
149 150 151
  if(REQUIRED_CBLAS_LIB)
    set(SHARK_LIBRARIES ${SHARK_LIBRARIES} ${CBLAS_LIBRARY})
  endif()
152
endif()