2012-10-23 23:47:11 -07:00
|
|
|
cmake_minimum_required(VERSION 2.8.3)
|
|
|
|
|
project(serial)
|
|
|
|
|
|
2021-07-28 14:26:38 -05:00
|
|
|
#Catkin is not required at all in modern cmake, dependencies are handled fine through target_link_libraries.
|
|
|
|
|
#We set the default to be on to not break anyone's builds.
|
|
|
|
|
option(SERIAL_ENABLE_CATKIN "Enable using the Catkin make extension to cmake (ie for ROS)" ON)
|
|
|
|
|
if(${SERIAL_ENABLE_CATKIN})
|
|
|
|
|
# Find catkin
|
|
|
|
|
find_package(catkin REQUIRED)
|
|
|
|
|
endif()
|
2012-10-23 23:47:11 -07:00
|
|
|
|
2014-04-25 02:50:40 +01:00
|
|
|
if(APPLE)
|
2018-11-12 12:01:58 -06:00
|
|
|
find_library(IOKIT_LIBRARY IOKit)
|
|
|
|
|
find_library(FOUNDATION_LIBRARY Foundation)
|
2014-04-25 02:50:40 +01:00
|
|
|
endif()
|
|
|
|
|
|
2012-10-23 23:47:11 -07:00
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
|
# If Linux, add rt and pthread
|
2018-01-18 20:25:29 -05:00
|
|
|
set(rt_LIBRARIES rt)
|
|
|
|
|
set(pthread_LIBRARIES pthread)
|
2021-07-28 14:26:38 -05:00
|
|
|
if(${SERIAL_ENABLE_CATKIN})
|
|
|
|
|
catkin_package(
|
|
|
|
|
LIBRARIES ${PROJECT_NAME}
|
|
|
|
|
INCLUDE_DIRS include
|
|
|
|
|
DEPENDS rt pthread
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2012-12-03 14:51:10 -08:00
|
|
|
else()
|
2012-10-23 23:47:11 -07:00
|
|
|
# Otherwise normal call
|
2021-07-28 14:26:38 -05:00
|
|
|
if(${SERIAL_ENABLE_CATKIN})
|
|
|
|
|
catkin_package(
|
|
|
|
|
LIBRARIES ${PROJECT_NAME}
|
|
|
|
|
INCLUDE_DIRS include
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2012-12-03 14:51:10 -08:00
|
|
|
endif()
|
2012-10-23 23:47:11 -07:00
|
|
|
|
|
|
|
|
## Sources
|
|
|
|
|
set(serial_SRCS
|
|
|
|
|
src/serial.cc
|
2012-12-03 15:31:41 -08:00
|
|
|
include/serial/serial.h
|
|
|
|
|
include/serial/v8stdint.h
|
2012-10-23 23:47:11 -07:00
|
|
|
)
|
2014-04-25 02:50:40 +01:00
|
|
|
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)
|
2014-04-25 02:50:40 +01:00
|
|
|
elseif(UNIX)
|
2012-10-23 23:47:11 -07:00
|
|
|
# If unix
|
2012-12-03 15:31:41 -08:00
|
|
|
list(APPEND serial_SRCS src/impl/unix.cc)
|
2014-02-22 20:02:32 +00:00
|
|
|
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
|
2014-08-16 22:08:56 +02:00
|
|
|
else()
|
2012-10-23 23:47:11 -07:00
|
|
|
# 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)
|
2012-10-23 23:47:11 -07:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
## Add serial library
|
2012-12-03 14:51:10 -08:00
|
|
|
add_library(${PROJECT_NAME} ${serial_SRCS})
|
2014-04-25 02:50:40 +01:00
|
|
|
if(APPLE)
|
2018-11-12 12:01:58 -06:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
2014-04-25 02:50:40 +01:00
|
|
|
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)
|
2012-10-24 01:32:23 -07:00
|
|
|
endif()
|
2012-10-23 23:47:11 -07:00
|
|
|
|
2022-12-14 12:05:23 -05:00
|
|
|
option(SERIAL_ENABLE_EXAMPLE "Enable example" ON)
|
|
|
|
|
if(${SERIAL_ENABLE_EXAMPLE})
|
|
|
|
|
add_executable(serial_example examples/serial_example.cc)
|
|
|
|
|
add_dependencies(serial_example ${PROJECT_NAME})
|
|
|
|
|
target_link_libraries(serial_example ${PROJECT_NAME})
|
|
|
|
|
endif()
|
2012-10-23 23:47:11 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-28 14:26:38 -05:00
|
|
|
if(${SERIAL_ENABLE_CATKIN})
|
|
|
|
|
## Include headers
|
|
|
|
|
include_directories(include)
|
|
|
|
|
## Install executable
|
|
|
|
|
install(TARGETS ${PROJECT_NAME}
|
|
|
|
|
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
|
|
|
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
|
|
|
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
|
|
|
|
|
)
|
2013-01-09 10:53:58 -08:00
|
|
|
|
2021-07-28 14:26:38 -05:00
|
|
|
## Install headers
|
|
|
|
|
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
|
|
|
|
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
|
|
|
|
|
## Tests
|
|
|
|
|
if(CATKIN_ENABLE_TESTING)
|
|
|
|
|
add_subdirectory(tests)
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
# while some of this uses stuff from newer CMake versions, the code before already ignored 2.8 compat,
|
|
|
|
|
# so we ignore it here as well.
|
|
|
|
|
# see this: https://www.youtube.com/watch?v=m0DwB4OvDXk and associated slides hosted on github to learn more.
|
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
|
|
|
|
$<INSTALL_INTERFACE:include>
|
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
|
|
|
|
# Install targets
|
|
|
|
|
install(TARGETS ${PROJECT_NAME}
|
|
|
|
|
EXPORT ${PROJECT_NAME}Targets
|
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
|
COMPONENT ${PROJECT_NAME}_RunTime
|
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
|
COMPONENT ${PROJECT_NAME}_RunTime
|
|
|
|
|
NAMELINK_COMPONENT ${PROJECT_NAME}_Development
|
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
|
COMPONENT ${PROJECT_NAME}_Development
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
# Install header files
|
|
|
|
|
install(FILES
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/serial/serial.h
|
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/serial/v8stdint.h
|
|
|
|
|
DESTINATION
|
|
|
|
|
${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
|
|
|
|
|
|
# Install cmake stuff so we can use our target
|
|
|
|
|
install(EXPORT ${PROJECT_NAME}Targets
|
|
|
|
|
FILE ${PROJECT_NAME}Targets.cmake
|
|
|
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
|
|
|
|
)
|
|
|
|
|
option(SERIAL_ENABLE_TESTING "Enable testing" OFF)
|
|
|
|
|
if(${SERIAL_ENABLE_TESTING})
|
|
|
|
|
add_subdirectory(tests)
|
|
|
|
|
endif()
|
2013-07-31 16:47:19 -07:00
|
|
|
endif()
|
2021-07-28 14:26:38 -05:00
|
|
|
|