1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 11:44:53 +08:00
serial/CMakeLists.txt

89 lines
2.0 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.8)
project(serial)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_gtest REQUIRED)
if(APPLE)
2018-11-12 12:01:58 -06:00
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)
2012-12-03 14:51:10 -08:00
endif()
## Sources
set(serial_SRCS
src/serial.cc
2012-12-03 15:31:41 -08:00
include/serial/serial.h
include/serial/v8stdint.h
)
if(APPLE)
2018-11-12 12:01:58 -06: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)
# If unix
2012-12-03 15:31:41 -08:00
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()
# If windows
2012-12-03 15:31:41 -08:00
list(APPEND serial_SRCS src/impl/win.cc)
2014-08-16 22:08:56 +02:00
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})
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(APPLE)
2018-11-12 12:01:58 -06:00
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
2018-11-12 12:01:58 -06:00
target_link_libraries(${PROJECT_NAME} rt pthread)
2014-08-16 22:08:56 +02:00
else()
2018-11-12 12:01:58 -06:00
target_link_libraries(${PROJECT_NAME} setupapi)
endif()
## Include headers
include_directories(include)
## Install library
2013-01-09 10:53:58 -08:00
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
2013-01-09 10:53:58 -08:00
## Install headers
install(DIRECTORY include/serial
DESTINATION include
)
## Example executable
add_executable(serial_example examples/serial_example.cc)
ament_target_dependencies(serial_example)
target_link_libraries(serial_example ${PROJECT_NAME})
install(TARGETS serial_example
RUNTIME DESTINATION lib/${PROJECT_NAME}
)
2013-01-09 10:53:58 -08:00
## Tests
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
# Package
ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_package()