1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-11-14 13:54:57 +00:00
gnss-sdr/cmake/Modules/FindGLOG.cmake

161 lines
4.4 KiB
CMake
Raw Normal View History

# GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
2018-12-12 00:37:37 +00:00
# This file is part of GNSS-SDR.
#
# SPDX-FileCopyrightText: 2011-2020 C. Fernandez-Prades cfernandez(at)cttc.es
# SPDX-License-Identifier: BSD-3-Clause
2018-12-12 00:37:37 +00:00
# - Try to find the Google Glog library
#
# This module defines the following variables
#
# GLOG_FOUND - Was Glog found
# GLOG_INCLUDE_DIRS - the Glog include directories
# GLOG_LIBRARIES - Link to this
#
# This module accepts the following variables
#
# GLOG_ROOT - Can be set to Glog install path or Windows build path
#
2019-02-03 18:24:44 +00:00
# Provides the following imported target:
# Glog::glog
#
2018-12-12 00:37:37 +00:00
if(NOT COMMAND feature_summary)
include(FeatureSummary)
endif()
if(NOT GNSSSDR_LIB_PATHS)
include(GnsssdrLibPaths)
endif()
2020-11-01 13:35:15 +00:00
if(NOT PKG_CONFIG_FOUND)
include(FindPkgConfig)
endif()
2018-12-12 00:37:37 +00:00
if(NOT DEFINED GLOG_ROOT)
set(GLOG_ROOT /usr /usr/local)
endif()
if(MSVC)
set(LIB_PATHS ${GLOG_ROOT} ${GLOG_ROOT}/Release)
else()
set(LIB_PATHS ${GLOG_ROOT} ${GLOG_ROOT}/lib)
endif()
pkg_check_modules(PC_GLOG libglog)
2018-12-12 00:37:37 +00:00
macro(_FIND_GLOG_LIBRARIES _var)
find_library(${_var}
NAMES ${ARGN}
2019-09-30 12:58:34 +00:00
HINTS ${PC_GLOG_LIBDIR}
2018-12-12 00:37:37 +00:00
PATHS ${LIB_PATHS}
${GNSSSDR_LIB_PATHS}
2018-12-12 00:37:37 +00:00
${GLOG_ROOT}/lib
$ENV{GLOG_ROOT}/lib
${GLOG_ROOT}/lib64
$ENV{GLOG_ROOT}/lib64
PATH_SUFFIXES lib
)
mark_as_advanced(${_var})
endmacro()
macro(_GLOG_APPEND_LIBRARIES _list _release)
set(_debug ${_release}_DEBUG)
if(${_debug})
set(${_list} ${${_list}} optimized ${${_release}} debug ${${_debug}})
else()
set(${_list} ${${_list}} ${${_release}})
endif()
endmacro()
if(MSVC)
find_path(GLOG_INCLUDE_DIR NAMES raw_logging.h
2019-09-30 12:58:34 +00:00
HINTS
${PC_GLOG_INCLUDEDIR}
2018-12-12 00:37:37 +00:00
PATHS
${GLOG_ROOT}/src/windows
${GLOG_ROOT}/src/windows/glog
)
else()
# Linux/OS X builds
find_path(GLOG_INCLUDE_DIR NAMES raw_logging.h
2019-09-30 12:58:34 +00:00
HINTS
${PC_GLOG_INCLUDEDIR}
2018-12-12 00:37:37 +00:00
PATHS
/usr/include/glog
2019-09-30 12:58:34 +00:00
/usr/local/include/glog
2018-12-12 00:37:37 +00:00
/opt/local/include/glog # default location in Macports
/opt/homebrew/opt/glog/include/glog
2019-09-30 12:58:34 +00:00
${GLOG_ROOT}/include/glog
2018-12-12 00:37:37 +00:00
)
endif()
# Find the libraries
if(MSVC)
_find_glog_libraries(GLOG_LIBRARIES libglog.lib)
else()
# Linux/OS X builds
if(UNIX)
_find_glog_libraries(GLOG_LIBRARIES libglog.so)
endif()
if(APPLE)
_find_glog_libraries(GLOG_LIBRARIES glog)
2018-12-12 00:37:37 +00:00
endif()
endif()
# handle the QUIETLY and REQUIRED arguments and set GLOG_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLOG DEFAULT_MSG GLOG_LIBRARIES)
if(GLOG_FOUND)
message(STATUS "glog library found at ${GLOG_LIBRARIES}")
if(PC_GLOG_VERSION)
set(GLOG_VERSION ${PC_GLOG_VERSION})
endif()
endif()
2018-12-12 00:37:37 +00:00
if(MSVC)
string(REGEX REPLACE "/glog$" "" VAR_WITHOUT ${GLOG_INCLUDE_DIR})
string(REGEX REPLACE "/windows$" "" VAR_WITHOUT ${VAR_WITHOUT})
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIRS} "${VAR_WITHOUT}")
string(REGEX REPLACE "/libglog.lib" "" GLOG_LIBRARIES_DIR ${GLOG_LIBRARIES})
else()
# Linux/OS X builds
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})
string(REGEX REPLACE "/libglog.so" "" GLOG_LIBRARIES_DIR ${GLOG_LIBRARIES})
endif()
if(GLOG_FOUND AND GLOG_VERSION)
set_package_properties(GLOG PROPERTIES
DESCRIPTION "C++ implementation of the Google logging module (found: v${GLOG_VERSION})"
)
else()
set_package_properties(GLOG PROPERTIES
DESCRIPTION "C++ implementation of the Google logging module"
)
endif()
set_package_properties(GLOG PROPERTIES
URL "https://github.com/google/glog"
)
string(REGEX MATCH libglog.a GLOG_IS_STATIC ${GLOG_LIBRARIES})
2019-02-03 18:24:44 +00:00
if(GLOG_FOUND AND NOT TARGET Glog::glog)
if(GLOG_IS_STATIC)
add_library(Glog::glog STATIC IMPORTED)
else()
add_library(Glog::glog SHARED IMPORTED)
endif()
2019-02-03 18:24:44 +00:00
set_target_properties(Glog::glog PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${GLOG_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${GLOG_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${GLOG_LIBRARIES}"
)
2018-12-12 00:37:37 +00:00
endif()
2024-02-25 07:20:56 +00:00
# Fix for glog 0.7.0
if(EXISTS ${GLOG_INCLUDE_DIRS}/export.h)
2024-02-27 12:45:38 +00:00
set_target_properties(Glog::glog PROPERTIES INTERFACE_COMPILE_DEFINITIONS "GLOG_USE_GLOG_EXPORT")
2024-02-25 07:20:56 +00:00
endif()