1
0
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:
Zachary Michaels 2019-11-11 09:48:05 -08:00
parent eefc0ef616
commit e7f16cb77c
2 changed files with 36 additions and 66 deletions

View File

@ -1,68 +1,50 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
project(serial) project(serial)
# Add support for C++11 # Default to C99
if(NOT CMAKE_CXX_STANDARD) if(NOT CMAKE_C_STANDARD)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_C_STANDARD 99)
endif() 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 # Add support for C++11
if(NOT CMAKE_CXX_STANDARD) if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 14)
endif() 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) 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) if(APPLE)
find_library(IOKIT_LIBRARY IOKit) find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation) find_library(FOUNDATION_LIBRARY Foundation)
endif() endif()
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
# If Linux, add rt and pthread set(RT_LIBRARIES rt)
set(rt_LIBRARIES rt) set(PTHREAD_LIBRARIES pthread)
set(pthread_LIBRARIES pthread)
else()
# Otherwise normal call
endif() endif()
## Sources set(SERIAL_SRCS
set(serial_SRCS src/serial.cc include/serial/serial.h include/serial/v8stdint.h) src/serial.cc)
if(APPLE) if(APPLE)
# If OSX list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_osx.cc)
list(APPEND serial_SRCS src/impl/unix.cc) list(APPEND SERIAL_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
elseif(UNIX) elseif(UNIX)
# If unix list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_linux.cc)
list(APPEND serial_SRCS src/impl/unix.cc) list(APPEND SERIAL_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
else() else()
# If windows list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_win.cc)
list(APPEND serial_SRCS src/impl/win.cc) list(APPEND SERIAL_SRCS src/impl/win.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
endif() endif()
## Add serial library add_library(${PROJECT_NAME} SHARED
add_library(${PROJECT_NAME} ${serial_SRCS}) ${SERIAL_SRCS})
if(APPLE) if(APPLE)
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX) elseif(UNIX)
@ -71,33 +53,21 @@ else()
target_link_libraries(${PROJECT_NAME} setupapi) target_link_libraries(${PROJECT_NAME} setupapi)
endif() endif()
## Uncomment for example target_include_directories(${PROJECT_NAME}
add_executable(serial_example examples/serial_example.cc) PUBLIC
add_dependencies(serial_example ${PROJECT_NAME}) $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
target_link_libraries(serial_example ${PROJECT_NAME}) $<INSTALL_INTERFACE:include>)
## Include headers install(
DIRECTORY include/
DESTINATION include)
## Install executable ament_export_include_directories(include)
install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib) ament_export_libraries(${PROJECT_NAME})
## Install headers
install(FILES include/serial/serial.h include/serial/v8stdint.h
DESTINATION include/serial)
## Tests
if(BUILD_TESTING) if(BUILD_TESTING)
add_subdirectory(tests) find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif() 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() ament_package()

View File

@ -21,11 +21,11 @@
<buildtool_depend>ament_cmake</buildtool_depend> <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> <test_depend>boost</test_depend>
<export> <export>
<build_type>ament_cmake</build_type> <build_type>ament_cmake</build_type>
</export> </export>
<buildtool_depend>ament_cmake</buildtool_depend>
</package> </package>