|
| 1 | +# Taken from symengine |
| 2 | + |
| 3 | +# Macros for finding external libraries |
| 4 | +# |
| 5 | +# Example usage: |
| 6 | +# |
| 7 | +# include(LibFindMacros) |
| 8 | +# libfind_include(gmpxx.h gmp) |
| 9 | +# libfind_library(gmpxx gmp) |
| 10 | +# libfind_library(gmp gmp) |
| 11 | +# set(GMP_LIBRARIES ${GMPXX_LIBRARY} ${GMP_LIBRARY}) |
| 12 | +# set(GMP_INCLUDE_DIRS ${GMP_INCLUDE_DIR}) |
| 13 | +# include(FindPackageHandleStandardArgs) |
| 14 | +# find_package_handle_standard_args(GMP DEFAULT_MSG GMP_LIBRARIES |
| 15 | +# GMP_INCLUDE_DIRS) |
| 16 | +# mark_as_advanced(GMP_INCLUDE_DIR GMPXX_LIBRARY GMP_LIBRARY) |
| 17 | +# |
| 18 | +# The result of the Find*.cmake (e.g. FindGMP.cmake) module should be two |
| 19 | +# variables GMP_LIBRARIES and GMP_INCLUDE_DIRS, that the user then uses in the |
| 20 | +# following way: |
| 21 | +# |
| 22 | +# find_package(GMP REQUIRED) |
| 23 | +# include_directories(${GMP_INCLUDE_DIRS}) |
| 24 | +# set(LIBS ${LIBS} ${GMP_LIBRARIES}) |
| 25 | +# # LIBS is later used in target_link_libraries() |
| 26 | + |
| 27 | +function (libfind_library libname pkg) |
| 28 | + string(TOUPPER ${pkg} PKG) |
| 29 | + string(TOUPPER ${libname} LIBNAME) |
| 30 | + |
| 31 | + find_library(${LIBNAME}_LIBRARY |
| 32 | + NAMES |
| 33 | + ${libname} |
| 34 | + ) |
| 35 | + |
| 36 | + if (NOT TARGET ${libname}) |
| 37 | + add_library(${libname} UNKNOWN IMPORTED) |
| 38 | + set_property(TARGET ${libname} PROPERTY IMPORTED_LOCATION ${${LIBNAME}_LIBRARY}) |
| 39 | + endif() |
| 40 | +endfunction() |
| 41 | + |
| 42 | +function (libfind_include HEADER pkg) |
| 43 | + string(TOUPPER ${pkg} PKG) |
| 44 | + |
| 45 | + find_path(${PKG}_INCLUDE_DIR |
| 46 | + NAMES |
| 47 | + ${HEADER} |
| 48 | + ) |
| 49 | +endfunction() |
0 commit comments