Add support for building against system libraries of libserialport and Argtable3

This commit is contained in:
Schdro 2023-04-09 14:24:52 +02:00
parent 0b363c620a
commit d4df989c61
3 changed files with 62 additions and 38 deletions

View File

@ -4,6 +4,7 @@ project(blisp C)
set(CMAKE_C_STANDARD 23)
option(BLISP_BUILD_CLI "Build CLI Tool" OFF)
option(BLISP_USE_SYSTEM_LIBRARIES "Use system-installed libraries" "${CMAKE_USE_SYSTEM_LIBRARIES}")
add_library(libblisp_obj OBJECT
lib/blisp.c
@ -32,6 +33,13 @@ set_target_properties(libblisp_static PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "static"
OUTPUT_NAME "blisp")
if(BLISP_USE_SYSTEM_LIBRARIES)
find_package(PkgConfig)
pkg_search_module(LIBSERIALPORT REQUIRED libserialport)
target_link_libraries(libblisp PUBLIC ${LIBSERIALPORT_LIBRARIES})
target_link_libraries(libblisp_static PUBLIC ${LIBSERIALPORT_LIBRARIES})
target_include_directories(libblisp_obj PUBLIC ${LIBSERIALPORT_INCLUDE_DIRS})
else()
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
target_sources(libblisp_obj PRIVATE
${CMAKE_SOURCE_DIR}/vendor/libserialport/serialport.c
@ -73,6 +81,7 @@ elseif(APPLE)
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/vendor/libserialport)
write_file(${CMAKE_SOURCE_DIR}/vendor/libserialport/config.h "// bypass errors.")
endif()
endif()
if(BLISP_BUILD_CLI)
add_subdirectory(tools/blisp)

View File

@ -52,6 +52,16 @@ mkdir build && cd build
cmake -DBLISP_BUILD_CLI=ON ..
cmake --build .
```
For building against preinstalled system libraries of the used vendor
libraries (system maintainers), additionally define
`BLISP_USE_SYSTEM_LIBRARIES`, e.g. using following commands:
```bash
mkdir build && cd build
cmake -DBLISP_USE_SYSTEM_LIBRARIES=ON -DBLISP_BUILD_CLI=ON ..
cmake --build .
```
#### Need more build details? [See here](https://github.com/pine64/blisp/wiki/Update-Pinecil-V2#build-blisp-flasher-from-code).
## Usage

View File

@ -1,7 +1,12 @@
set(ARGTABLE3_ENABLE_TESTS OFF CACHE BOOL "Enable unit tests")
set(ARGTABLE3_ENABLE_EXAMPLES OFF CACHE BOOL "Enable examples")
#set(ARGTABLE3_REPLACE_GETOPT OFF CACHE BOOL "Replace getopt in the system C library")
if(BLISP_USE_SYSTEM_LIBRARIES)
find_package(Argtable3)
else()
add_subdirectory(${CMAKE_SOURCE_DIR}/vendor/argtable3 ${CMAKE_CURRENT_BINARY_DIR}/argtable3)
endif()
add_executable(blisp src/main.c src/cmd/write.c src/util.c src/common.c src/cmd/iot.c)