|
| 1 | +# SPDX-License-Identifier: MIT |
| 2 | + |
| 3 | +#[=======================================================================[.rst: |
| 4 | +FindLibserialport |
| 5 | +------- |
| 6 | +
|
| 7 | +Finds the sigrok serial port library (``libserialport``) |
| 8 | +
|
| 9 | +Imported Targets |
| 10 | +^^^^^^^^^^^^^^^^ |
| 11 | +
|
| 12 | +This module defines the following imported targets, if found: |
| 13 | +
|
| 14 | +``Libserialport::Libserialport`` |
| 15 | + The serialport library |
| 16 | +
|
| 17 | +Result Variables |
| 18 | +^^^^^^^^^^^^^^^^ |
| 19 | +
|
| 20 | +This module will define the following variables: |
| 21 | +
|
| 22 | +``Libserialport_FOUND`` |
| 23 | + True if the system has the serialport library. |
| 24 | +``Libserialport_VERSION`` |
| 25 | + The version of the serialport library which was found. |
| 26 | +``Libserialport_INCLUDE_DIRS`` |
| 27 | + Include directories needed to use ``libserialport``. |
| 28 | +``Libserialport_LIBRARIES`` |
| 29 | + Libraries needed to link to ``libserialport``. |
| 30 | +
|
| 31 | +Cache Variables |
| 32 | +^^^^^^^^^^^^^^^ |
| 33 | +
|
| 34 | +The following cache variables may also be set: |
| 35 | +
|
| 36 | +``Libserialport_INCLUDE_DIR`` |
| 37 | + The directory containing ``libserialport.h``. |
| 38 | +``Libserialport_LIBRARY`` |
| 39 | + The path to the ``libserialport`` library. |
| 40 | +
|
| 41 | +#]=======================================================================] |
| 42 | + |
| 43 | +find_package(PkgConfig) |
| 44 | +pkg_check_modules(PC_Libserialport QUIET libserialport) |
| 45 | + |
| 46 | +find_path(Libserialport_INCLUDE_DIR |
| 47 | + NAMES libserialport.h |
| 48 | + PATHS "${PC_Libserialport_INCLUDE_DIRS}" |
| 49 | +) |
| 50 | +find_library(Libserialport_LIBRARY |
| 51 | + NAMES serialport |
| 52 | + HINTS "${PC_Libserialport_LIBRARY_DIRS}" |
| 53 | +) |
| 54 | + |
| 55 | +set(Foo_VERSION ${PC_Foo_VERSION}) |
| 56 | + |
| 57 | +include(FindPackageHandleStandardArgs) |
| 58 | +find_package_handle_standard_args(Libserialport |
| 59 | + FOUND_VAR Libserialport_FOUND |
| 60 | + REQUIRED_VARS |
| 61 | + Libserialport_LIBRARY |
| 62 | + Libserialport_INCLUDE_DIR |
| 63 | + VERSION_VAR Libserialport_VERSION |
| 64 | +) |
| 65 | + |
| 66 | +if(Libserialport_FOUND) |
| 67 | + set(Libserialport_LIBRARIES ${Libserialport_LIBRARY}) |
| 68 | + set(Libserialport_INCLUDE_DIRS ${Libserialport_INCLUDE_DIR}) |
| 69 | + set(Libserialport_DEFINITIONS ${PC_Liberialport_CFLAGS_OTHER}) |
| 70 | +endif() |
| 71 | + |
| 72 | +if(Libserialport_FOUND AND NOT TARGET Libserialport::Libserialport) |
| 73 | + add_library(Libserialport::Libserialport UNKNOWN IMPORTED) |
| 74 | + set_target_properties(Libserialport::Libserialport PROPERTIES |
| 75 | + IMPORTED_LOCATION "${Libserialport_LIBRARY}" |
| 76 | + INTERFACE_COMPILE_OPTIONS "${PC_Libserialport_CFLAGS_OTHER}" |
| 77 | + INTERFACE_INCLUDE_DIRECTORIES "${Libserialport_INCLUDE_DIR}" |
| 78 | + ) |
| 79 | +endif() |
0 commit comments