clamav/cmake/FindTomsFastMath.cmake
Micah Snyder 9bdc28b052 CMake: Support external TomsFastMath library (libtfm)
Add support for compiling with external TomsFastMath library provided by
the system instead of compiling the vendored copy into libclamav.

The vendored source is still built directly into libclamav instead of as
a separate library the way libmspack is done.
The rationale is that:
A) it's more complicated to deal with possibly compiling as static or
dynamic, and also
B) libmspack and libunrar are compiled separately primarily because of
licensing concerns. TomsFastMath public domain, so that isn't a concern.

Resolves: https://bugzilla.clamav.net/show_bug.cgi?id=12562
2022-02-10 12:54:23 -07:00

85 lines
2.3 KiB
CMake

# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindTomsFastMath
-------
Finds the TomsFastMath library.
Imported Targets
^^^^^^^^^^^^^^^^
This module provides the following imported targets, if found:
``TomsFastMath::TomsFastMath``
The TomsFastMath library
Result Variables
^^^^^^^^^^^^^^^^
This will define the following variables:
``TomsFastMath_FOUND``
True if the system has the TomsFastMath library.
``TomsFastMath_VERSION``
The version of the TomsFastMath library which was found.
``TomsFastMath_INCLUDE_DIRS``
Include directories needed to use TomsFastMath.
``TomsFastMath_LIBRARIES``
Libraries needed to link to TomsFastMath.
Cache Variables
^^^^^^^^^^^^^^^
The following cache variables may also be set:
``TomsFastMath_INCLUDE_DIR``
The directory containing ``tfm.h``.
``TomsFastMath_LIBRARY``
The path to the TomsFastMath library.
#]=======================================================================]
find_package(PkgConfig QUIET)
pkg_check_modules(PC_TomsFastMath QUIET toms)
find_path(TomsFastMath_INCLUDE_DIR
NAMES tfm.h
PATHS ${PC_TomsFastMath_INCLUDE_DIRS}
)
find_library(TomsFastMath_LIBRARY
NAMES tfm
PATHS ${PC_TomsFastMath_LIBRARY_DIRS}
)
set(TomsFastMath_VERSION ${PC_TomsFastMath_VERSION})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TomsFastMath
FOUND_VAR TomsFastMath_FOUND
REQUIRED_VARS
TomsFastMath_LIBRARY
TomsFastMath_INCLUDE_DIR
VERSION_VAR TomsFastMath_VERSION
)
if(TomsFastMath_FOUND)
set(TomsFastMath_LIBRARIES ${TomsFastMath_LIBRARY})
set(TomsFastMath_INCLUDE_DIRS ${TomsFastMath_INCLUDE_DIR})
set(TomsFastMath_DEFINITIONS ${PC_TomsFastMath_CFLAGS_OTHER})
endif()
if(TomsFastMath_FOUND AND NOT TARGET TomsFastMath::TomsFastMath)
add_library(TomsFastMath::TomsFastMath UNKNOWN IMPORTED)
set_target_properties(TomsFastMath::TomsFastMath PROPERTIES
IMPORTED_LOCATION "${TomsFastMath_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_TomsFastMath_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${TomsFastMath_INCLUDE_DIR}"
)
endif()
mark_as_advanced(
TomsFastMath_INCLUDE_DIR
TomsFastMath_LIBRARY
)