diff --git a/CMakeLists.txt b/CMakeLists.txt index 7111d92b..b98b02c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,36 +1,22 @@ 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() -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}) +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic -Werror) +endif() -# Find catkin +# find dependencies +find_package(ament_cmake REQUIRED) if(APPLE) find_library(IOKIT_LIBRARY IOKit) @@ -38,31 +24,27 @@ if(APPLE) 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 + $ + $) -## 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() diff --git a/package.xml b/package.xml index c1a16cee..4e1946c0 100644 --- a/package.xml +++ b/package.xml @@ -21,11 +21,11 @@ ament_cmake + ament_lint_auto + ament_lint_common boost ament_cmake - - ament_cmake