1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-23 04:04:54 +08:00
serial/CMakeLists.txt

104 lines
2.4 KiB
CMake
Raw Normal View History

2019-11-07 14:24:06 -08:00
cmake_minimum_required(VERSION 3.5)
project(serial)
2019-11-07 14:24:06 -08:00
# Add support for C++11
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
find_package(ament_cmake REQUIRED)
set(INCLUDE_DIRS include ${ament_cmake_INCLUDE_DIRS})
include_directories(${INCLUDE_DIRS})
set(LIBRARY_DIRS ${ament_cmake_LIBRARY_DIRS})
link_directories(${LIBRARY_DIRS})
set(LIBS ${ament_cmake_LIBRARIES})
# Add support for C++11
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
find_package(ament_cmake REQUIRED)
set(INCLUDE_DIRS include ${ament_cmake_INCLUDE_DIRS})
set(LIBRARY_DIRS ${ament_cmake_LIBRARY_DIRS})
set(LIBS ${ament_cmake_LIBRARIES})
# Find catkin
if(APPLE)
2019-11-07 14:24:06 -08:00
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
endif()
if(UNIX AND NOT APPLE)
2019-11-07 14:24:06 -08:00
# If Linux, add rt and pthread
set(rt_LIBRARIES rt)
set(pthread_LIBRARIES pthread)
2012-12-03 14:51:10 -08:00
else()
2019-11-07 14:24:06 -08:00
# Otherwise normal call
2012-12-03 14:51:10 -08:00
endif()
## Sources
2019-11-07 14:24:06 -08:00
set(serial_SRCS src/serial.cc include/serial/serial.h include/serial/v8stdint.h)
if(APPLE)
2019-11-07 14:24:06 -08:00
# If OSX
list(APPEND serial_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
elseif(UNIX)
2019-11-07 14:24:06 -08:00
# If unix
list(APPEND serial_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
2014-08-16 22:08:56 +02:00
else()
2019-11-07 14:24:06 -08:00
# 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
2012-12-03 14:51:10 -08:00
add_library(${PROJECT_NAME} ${serial_SRCS})
if(APPLE)
2019-11-07 14:24:06 -08:00
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
2019-11-07 14:24:06 -08:00
target_link_libraries(${PROJECT_NAME} rt pthread)
2014-08-16 22:08:56 +02:00
else()
2019-11-07 14:24:06 -08:00
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
## Install executable
2019-11-07 14:24:06 -08:00
install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)
2013-01-09 10:53:58 -08:00
## Install headers
install(FILES include/serial/serial.h include/serial/v8stdint.h
2019-11-07 14:24:06 -08:00
DESTINATION include/serial)
2013-01-09 10:53:58 -08:00
## Tests
2019-11-07 14:24:06 -08:00
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
2019-11-07 14:24:06 -08:00
ament_export_dependencies(ament_cmake)
ament_export_include_directories(${INCLUDE_DIRS})
ament_export_libraries(${PROJECT_NAME} ${LIBS})
ament_package()
ament_export_dependencies(ament_cmake)
ament_export_include_directories(${INCLUDE_DIRS})
ament_export_libraries(${PROJECT_NAME} ${LIBS})
ament_package()