2023-08-01 12:50:32 +00:00
|
|
|
cmake_minimum_required(VERSION 3.16)
|
2023-08-28 09:25:41 +00:00
|
|
|
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
|
2022-08-24 10:06:39 +00:00
|
|
|
project(blisp C)
|
2023-08-01 12:43:56 +00:00
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
2023-08-01 12:50:32 +00:00
|
|
|
set(CMAKE_C_STANDARD 11)
|
2022-08-24 10:06:39 +00:00
|
|
|
|
2022-09-24 09:58:47 +00:00
|
|
|
option(BLISP_BUILD_CLI "Build CLI Tool" OFF)
|
2023-05-14 16:07:55 +00:00
|
|
|
option(BLISP_USE_SYSTEM_LIBRARIES "Use system-installed libraries" "${CMAKE_USE_SYSTEM_LIBRARIES}")
|
2023-08-01 12:43:56 +00:00
|
|
|
option(COMPILE_TESTS "Compile the tests" OFF)
|
2022-09-24 09:58:47 +00:00
|
|
|
|
2022-09-25 08:58:59 +00:00
|
|
|
add_library(libblisp_obj OBJECT
|
2023-12-01 03:52:07 +00:00
|
|
|
lib/blisp.c lib/blisp_easy.c
|
2022-11-08 21:06:14 +00:00
|
|
|
lib/chip/blisp_chip_bl60x.c
|
2022-11-10 20:36:00 +00:00
|
|
|
lib/chip/blisp_chip_bl70x.c
|
|
|
|
lib/chip/blisp_chip_bl808.c)
|
2022-09-25 08:58:59 +00:00
|
|
|
|
|
|
|
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/include/)
|
|
|
|
|
|
|
|
set_property(TARGET libblisp_obj PROPERTY POSITION_INDEPENDENT_CODE 1)
|
2022-09-24 09:58:47 +00:00
|
|
|
|
2022-09-25 08:58:59 +00:00
|
|
|
add_library(libblisp SHARED $<TARGET_OBJECTS:libblisp_obj>)
|
|
|
|
add_library(libblisp_static STATIC $<TARGET_OBJECTS:libblisp_obj>)
|
2022-09-24 09:58:47 +00:00
|
|
|
|
2023-04-23 00:56:19 +00:00
|
|
|
set(BLISP_PUBLIC_HEADERS
|
|
|
|
include/blisp.h
|
|
|
|
include/blisp_easy.h
|
|
|
|
include/blisp_chip.h
|
|
|
|
include/blisp_struct.h
|
|
|
|
include/blisp_util.h)
|
2022-09-24 09:58:47 +00:00
|
|
|
|
|
|
|
set_target_properties(libblisp PROPERTIES
|
2023-04-23 00:56:19 +00:00
|
|
|
PUBLIC_HEADER "${BLISP_PUBLIC_HEADERS}"
|
2023-08-03 06:21:21 +00:00
|
|
|
VERSION 0.0.4
|
2022-09-24 09:58:47 +00:00
|
|
|
SOVERSION 1
|
2022-09-25 08:58:59 +00:00
|
|
|
LIBRARY_OUTPUT_DIRECTORY "shared"
|
|
|
|
OUTPUT_NAME "blisp")
|
|
|
|
|
|
|
|
set_target_properties(libblisp_static PROPERTIES
|
2023-04-23 00:56:19 +00:00
|
|
|
PUBLIC_HEADER "${BLISP_PUBLIC_HEADERS}"
|
2023-08-03 06:21:21 +00:00
|
|
|
VERSION 0.0.4
|
2023-01-12 10:47:01 +00:00
|
|
|
SOVERSION 1
|
2022-09-25 08:58:59 +00:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "static"
|
|
|
|
OUTPUT_NAME "blisp")
|
|
|
|
|
2023-05-14 16:07:55 +00:00
|
|
|
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
|
2022-09-25 08:58:59 +00:00
|
|
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/serialport.c
|
|
|
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/timing.c)
|
|
|
|
|
2023-05-14 16:07:55 +00:00
|
|
|
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/vendor/libserialport)
|
|
|
|
endif()
|
2022-11-07 14:22:06 +00:00
|
|
|
|
2023-05-14 16:07:55 +00:00
|
|
|
if(WIN32)
|
|
|
|
target_link_libraries(libblisp PRIVATE Setupapi.lib)
|
|
|
|
target_link_libraries(libblisp_static PRIVATE Setupapi.lib)
|
|
|
|
target_compile_definitions(libblisp_obj PRIVATE LIBSERIALPORT_MSBUILD)
|
|
|
|
target_sources(libblisp_obj PRIVATE
|
|
|
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/windows.c)
|
|
|
|
elseif(UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
|
|
|
target_sources(libblisp_obj PRIVATE
|
|
|
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/linux.c
|
|
|
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/linux_termios.c)
|
|
|
|
target_compile_definitions(libblisp_obj PRIVATE
|
|
|
|
LIBSERIALPORT_ATBUILD
|
|
|
|
HAVE_TERMIOS2_SPEED
|
|
|
|
HAVE_STRUCT_TERMIOS2
|
|
|
|
HAVE_DECL_BOTHER
|
|
|
|
"SP_API=__attribute__((visibility(\"default\")))"
|
|
|
|
"SP_PRIV=__attribute__((visibility(\"hidden\")))")
|
|
|
|
write_file(${CMAKE_SOURCE_DIR}/vendor/libserialport/config.h "// bypass errors.")
|
|
|
|
elseif(UNIX AND ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
|
|
|
|
target_include_directories(libblisp_obj PRIVATE /usr/local/include/)
|
|
|
|
target_link_libraries(libblisp PRIVATE -L/usr/local/lib usb serialport)
|
|
|
|
target_link_libraries(libblisp_static PRIVATE -L/usr/local/lib usb serialport)
|
|
|
|
elseif(APPLE)
|
|
|
|
target_sources(libblisp_obj PRIVATE
|
|
|
|
${CMAKE_SOURCE_DIR}/vendor/libserialport/macosx.c)
|
|
|
|
target_link_libraries(libblisp PRIVATE "-framework IOKit" "-framework CoreFoundation")
|
|
|
|
target_compile_definitions(libblisp_obj PRIVATE
|
|
|
|
LIBSERIALPORT_ATBUILD
|
|
|
|
"SP_PRIV=__attribute__((visibility(\"hidden\")))"
|
|
|
|
"SP_API=__attribute__((visibility(\"default\")))")
|
|
|
|
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/vendor/libserialport)
|
|
|
|
write_file(${CMAKE_SOURCE_DIR}/vendor/libserialport/config.h "// bypass errors.")
|
|
|
|
endif()
|
2022-09-25 08:58:59 +00:00
|
|
|
endif()
|
2022-09-24 09:58:47 +00:00
|
|
|
|
2023-08-08 01:18:43 +00:00
|
|
|
include(GNUInstallDirs)
|
2023-08-08 01:18:43 +00:00
|
|
|
install(TARGETS libblisp libblisp_static
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
2023-08-08 01:18:43 +00:00
|
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
2023-08-08 01:18:43 +00:00
|
|
|
)
|
2023-04-23 00:56:19 +00:00
|
|
|
|
2022-09-24 09:58:47 +00:00
|
|
|
if(BLISP_BUILD_CLI)
|
|
|
|
add_subdirectory(tools/blisp)
|
|
|
|
endif()
|
2023-08-01 12:43:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
if(COMPILE_TESTS)
|
|
|
|
add_subdirectory(tools/blisp/src/cmd/dfu/tests)
|
2023-08-08 01:18:43 +00:00
|
|
|
endif(COMPILE_TESTS)
|