mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-23 04:04:54 +08:00
Use ament in CMakeLists.txt
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
This commit is contained in:
parent
eefc0ef616
commit
e7f16cb77c
@ -1,68 +1,50 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(serial)
|
||||
|
||||
# Add support for C++11
|
||||
if(NOT CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
# Default to C99
|
||||
if(NOT CMAKE_C_STANDARD)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
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)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
|
||||
endif()
|
||||
|
||||
# find dependencies
|
||||
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)
|
||||
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)
|
||||
else()
|
||||
# Otherwise normal call
|
||||
set(RT_LIBRARIES rt)
|
||||
set(PTHREAD_LIBRARIES pthread)
|
||||
endif()
|
||||
|
||||
## Sources
|
||||
set(serial_SRCS src/serial.cc include/serial/serial.h include/serial/v8stdint.h)
|
||||
set(SERIAL_SRCS
|
||||
src/serial.cc)
|
||||
|
||||
if(APPLE)
|
||||
# If OSX
|
||||
list(APPEND serial_SRCS src/impl/unix.cc)
|
||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_osx.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/unix.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)
|
||||
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_linux.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/unix.cc)
|
||||
else()
|
||||
# If windows
|
||||
list(APPEND serial_SRCS src/impl/win.cc)
|
||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_win.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/win.cc)
|
||||
endif()
|
||||
|
||||
## Add serial library
|
||||
add_library(${PROJECT_NAME} ${serial_SRCS})
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
${SERIAL_SRCS})
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
||||
elseif(UNIX)
|
||||
@ -71,33 +53,21 @@ 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})
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
## Include headers
|
||||
install(
|
||||
DIRECTORY include/
|
||||
DESTINATION include)
|
||||
|
||||
## Install executable
|
||||
install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)
|
||||
ament_export_include_directories(include)
|
||||
ament_export_libraries(${PROJECT_NAME})
|
||||
|
||||
## Install headers
|
||||
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
||||
DESTINATION include/serial)
|
||||
|
||||
## Tests
|
||||
if(BUILD_TESTING)
|
||||
add_subdirectory(tests)
|
||||
find_package(ament_lint_auto REQUIRED)
|
||||
ament_lint_auto_find_test_dependencies()
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
@ -21,11 +21,11 @@
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<test_depend>ament_lint_auto</test_depend>
|
||||
<test_depend>ament_lint_common</test_depend>
|
||||
<test_depend>boost</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
</package>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user