mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 11:44:53 +08:00
Bump cmake to oldest version currently used by tier 1 or 2 supported ROS platform. https://www.ros.org/reps/rep-2000.html#humble-hawksbill-may-2022-may-2027 https://www.ros.org/reps/rep-0003.html#noetic-ninjemys-may-2020-may-2025 Signed-off-by: Alex Moriarty <alex.moriarty@picknik.ai>
96 lines
2.3 KiB
CMake
96 lines
2.3 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
|
|
# General setup
|
|
set(PROJ_SOVERSION 1)
|
|
project(serial
|
|
VERSION 1.2.1
|
|
DESCRIPTION "Cross-platform, Serial Port library written in C++"
|
|
HOMEPAGE_URL "http://wjwwood.io/serial/"
|
|
)
|
|
|
|
if(APPLE)
|
|
find_library(IOKIT_LIBRARY IOKit)
|
|
find_library(FOUNDATION_LIBRARY Foundation)
|
|
endif()
|
|
|
|
## Sources
|
|
set(serial_SRCS
|
|
src/serial.cc
|
|
include/serial/serial.h
|
|
include/serial/v8stdint.h
|
|
)
|
|
if(APPLE)
|
|
# If OSX
|
|
list(APPEND serial_SRCS src/impl/unix.cc)
|
|
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
|
|
elseif(UNIX)
|
|
# If unix
|
|
list(APPEND serial_SRCS src/impl/unix.cc)
|
|
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
|
|
else()
|
|
# If windows
|
|
list(APPEND serial_SRCS src/impl/win.cc)
|
|
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
|
|
endif()
|
|
|
|
## Add serial library
|
|
set(serial_HEADERS
|
|
include/serial/serial.h
|
|
include/serial/v8stdint.h
|
|
)
|
|
# Build, link and install main library
|
|
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
endif()
|
|
add_library(${PROJECT_NAME} ${serial_SRCS})
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
VERSION ${PROJECT_VERSION}
|
|
SOVERSION ${PROJ_SOVERSION}
|
|
PUBLIC_HEADER "${serial_HEADERS}"
|
|
)
|
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
|
|
|
if(APPLE)
|
|
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
|
elseif(UNIX)
|
|
target_link_libraries(${PROJECT_NAME} rt pthread)
|
|
else()
|
|
target_link_libraries(${PROJECT_NAME} setupapi)
|
|
endif()
|
|
|
|
## Uncomment for example
|
|
add_executable(serial_example examples/serial_example.cc)
|
|
add_dependencies(serial_example ${PROJECT_NAME})
|
|
target_link_libraries(serial_example ${PROJECT_NAME})
|
|
|
|
## Include headers
|
|
include_directories(include)
|
|
|
|
## Install executable
|
|
install(TARGETS ${PROJECT_NAME}
|
|
ARCHIVE DESTINATION lib
|
|
LIBRARY DESTINATION lib
|
|
RUNTIME DESTINATION bin
|
|
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}
|
|
)
|
|
|
|
## Install headers
|
|
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
|
DESTINATION include/serial)
|
|
|
|
## Install CMake config
|
|
install(FILES cmake/serialConfig.cmake
|
|
DESTINATION share/serial/cmake)
|
|
|
|
|
|
## Install package.xml
|
|
install(FILES package.xml
|
|
DESTINATION share/serial)
|
|
|
|
## Tests
|
|
include(CTest)
|
|
if(BUILD_TESTING)
|
|
add_subdirectory(tests)
|
|
endif()
|