mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 11:44:53 +08:00
Cmake made major changes in the 2.x -> 3.0 switch, keeping the 2.x compatiblity just isn't worth it. Since serial anyway doesn't build on versions before xenial, use xenial's cmake at 3.5 as baseline. Gbp-Pq: Name 0001-cmake-Use-cmake-3.5-add-project-setup.patch
89 lines
2.2 KiB
CMake
89 lines
2.2 KiB
CMake
cmake_minimum_required(VERSION 3.5.0)
|
|
project(serial)
|
|
|
|
# Find catkin
|
|
find_package(catkin REQUIRED)
|
|
|
|
# General setup
|
|
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()
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
# If Linux, add rt and pthread
|
|
set(rt_LIBRARIES rt)
|
|
set(pthread_LIBRARIES pthread)
|
|
catkin_package(
|
|
LIBRARIES ${PROJECT_NAME}
|
|
INCLUDE_DIRS include
|
|
DEPENDS rt pthread
|
|
)
|
|
else()
|
|
# Otherwise normal call
|
|
catkin_package(
|
|
LIBRARIES ${PROJECT_NAME}
|
|
INCLUDE_DIRS include
|
|
)
|
|
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
|
|
add_library(${PROJECT_NAME} ${serial_SRCS})
|
|
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 ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
|
|
)
|
|
|
|
## Install headers
|
|
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
|
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
|
|
|
|
## Tests
|
|
if(CATKIN_ENABLE_TESTING)
|
|
add_subdirectory(tests)
|
|
endif()
|