链接ExternalProject(libserialport)CMake

我正在尝试向我的项目添加一个外部库。

The library in question is libserialport which is built with autotool. I would not like to install the library but use it statically/locally.

该项目:

.
├── CMakeLists.txt
├── lib
│   ├── CMakeLists.txt
│   ...
└── test
    ├── CMakeLists.txt
    └── tst_list_ports.c

目前,我只想在测试中使用libserialport。

CMakeLists.txt (root)

cmake_minimum_required(VERSION 3.12)
project(testserialport LANGUAGES C)

add_definitions(-D_GNU_SOURCE)
set(CMAKE_C_EXTENSIONS TRUE)
add_compile_options(-Wall -Wextra -Werror -pedantic -Wno-unused-parameter)

add_subdirectory(lib)
add_subdirectory(test)

CMakeLists.txt (root/test)

file(GLOB tests_src "*.c")
foreach(test_path ${tests_src})
    get_filename_component(srcname ${test_path} NAME)
    get_filename_component(execname ${test_path} NAME_WE)
    message( "${execname} ${srcname}" )
    add_executable(${execname} ${srcname})
    target_include_directories(${execname} PUBLIC "${PROJECT_BINARY_DIR}")
endforeach()

CMakeLists.txt (root/lib)

include(ExternalProject)

set(lsp_SRC "${CMAKE_CURRENT_SOURCE_DIR}/libserialport")
set(lsp_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libserialport")

ExternalProject_Add(
  libserialport
  GIT_REPOSITORY "https://github.com/sigrokproject/libserialport.git"

  CONFIGURE_COMMAND ${lsp_SRC}/autogen.sh && ${lsp_SRC}/configure --prefix=${lsp_PREFIX}
  BUILD_COMMAND make
  BUILD_IN_SOURCE 1
)

我在构建过程中遇到的错误是:

root/test/tst_list_ports.c:1:10: fatal error:
    'libserialport.h' file not found
#include <libserialport.h>

我猜缺少一些链接libserialport的命令,但我无法使它正常工作。

任何想法?

注意: libserialport构建生成:

libserialport/.libs/
├── libserialport.0.dylib
├── libserialport.a
├── libserialport.dylib -> libserialport.0.dylib
├── libserialport.la -> ../libserialport.la
├── libserialport.lai
├── macosx.o
├── serialport.o
└── timing.o