Skip to content

Commit

Permalink
Use ament in CMakeLists.txt
Browse files Browse the repository at this point in the history
Signed-off-by: Zachary Michaels <[email protected]>
  • Loading branch information
zmichaels11 committed Nov 11, 2019
1 parent eefc0ef commit e7f16cb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 66 deletions.
98 changes: 34 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

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)
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)
Expand All @@ -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()
4 changes: 2 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit e7f16cb

Please sign in to comment.