mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 11:44:53 +08:00
109 lines
2.5 KiB
CMake
109 lines
2.5 KiB
CMake
cmake_minimum_required(VERSION 3.5)
|
|
project(serial)
|
|
|
|
## C++ compiler sets
|
|
|
|
# Default to C99
|
|
if(NOT CMAKE_C_STANDARD)
|
|
set(CMAKE_C_STANDARD 99)
|
|
endif()
|
|
|
|
# Default to C++14
|
|
if(NOT CMAKE_CXX_STANDARD)
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
endif()
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
add_compile_options(-Wall -Wextra -Wpedantic)
|
|
endif()
|
|
|
|
# Find catkin
|
|
find_package(ament_cmake REQUIRED)
|
|
|
|
if(APPLE)
|
|
find_library(IOKIT_LIBRARY IOKit)
|
|
find_library(FOUNDATION_LIBRARY Foundation)
|
|
endif()
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
find_library(pthread_LIBRARY pthread)
|
|
find_library(rt_LIBRARY rt)
|
|
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} SHARED ${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)
|
|
target_link_libraries(serial_example ${PROJECT_NAME})
|
|
|
|
|
|
## Include headers
|
|
target_include_directories(${PROJECT_NAME}
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:include>)
|
|
#include_directories(include)
|
|
|
|
## Install library
|
|
install(
|
|
TARGETS ${PROJECT_NAME}
|
|
EXPORT ${PROJECT_NAME}
|
|
ARCHIVE DESTINATION lib
|
|
LIBRARY DESTINATION lib
|
|
RUNTIME DESTINATION bin
|
|
INCLUDES DESTINATION include
|
|
)
|
|
|
|
## Install headers
|
|
#install(FILES include/serial/serial.h include/serial/v8stdint.h
|
|
# DESTINATION share/${PROJECT_NAME})
|
|
install(
|
|
DIRECTORY include/
|
|
DESTINATION include
|
|
)
|
|
|
|
# Install executable
|
|
install(TARGETS serial_example
|
|
RUNTIME DESTINATION lib/${PROJECT_NAME}
|
|
)
|
|
|
|
## Tests
|
|
if(BUILD_TESTING)
|
|
find_package(ament_lint_auto REQUIRED)
|
|
|
|
#add_subdirectory(tests)
|
|
|
|
ament_lint_auto_find_test_dependencies()
|
|
endif()
|
|
|
|
ament_export_targets(${PROJECT_NAME})
|
|
#ament_export_libraries(${PROJECT_NAME})
|
|
ament_package() |