1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 19:54:57 +08:00

Merge c7281603cb346a60d8cd06bc4b3dd7e73bef2408 into 69e0372cf0d3796e84ce9a09aff1d74496f68720

This commit is contained in:
Cazadorro 2023-08-14 12:08:40 -07:00 committed by GitHub
commit 3e0ed77826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,13 @@
cmake_minimum_required(VERSION 2.8.3) cmake_minimum_required(VERSION 2.8.3)
project(serial) project(serial)
# Find catkin #Catkin is not required at all in modern cmake, dependencies are handled fine through target_link_libraries.
find_package(catkin REQUIRED) #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()
if(APPLE) if(APPLE)
find_library(IOKIT_LIBRARY IOKit) find_library(IOKIT_LIBRARY IOKit)
@ -13,17 +18,21 @@ if(UNIX AND NOT APPLE)
# If Linux, add rt and pthread # If Linux, add rt and pthread
set(rt_LIBRARIES rt) set(rt_LIBRARIES rt)
set(pthread_LIBRARIES pthread) set(pthread_LIBRARIES pthread)
if(${SERIAL_ENABLE_CATKIN})
catkin_package( catkin_package(
LIBRARIES ${PROJECT_NAME} LIBRARIES ${PROJECT_NAME}
INCLUDE_DIRS include INCLUDE_DIRS include
DEPENDS rt pthread DEPENDS rt pthread
) )
endif()
else() else()
# Otherwise normal call # Otherwise normal call
if(${SERIAL_ENABLE_CATKIN})
catkin_package( catkin_package(
LIBRARIES ${PROJECT_NAME} LIBRARIES ${PROJECT_NAME}
INCLUDE_DIRS include INCLUDE_DIRS include
) )
endif()
endif() endif()
## Sources ## Sources
@ -56,26 +65,69 @@ else()
target_link_libraries(${PROJECT_NAME} setupapi) target_link_libraries(${PROJECT_NAME} setupapi)
endif() endif()
## Uncomment for example option(SERIAL_ENABLE_EXAMPLE "Enable example" ON)
add_executable(serial_example examples/serial_example.cc) if(${SERIAL_ENABLE_EXAMPLE})
add_dependencies(serial_example ${PROJECT_NAME}) add_executable(serial_example examples/serial_example.cc)
target_link_libraries(serial_example ${PROJECT_NAME}) add_dependencies(serial_example ${PROJECT_NAME})
target_link_libraries(serial_example ${PROJECT_NAME})
endif()
## Include headers
include_directories(include)
## Install executable
install(TARGETS ${PROJECT_NAME} if(${SERIAL_ENABLE_CATKIN})
## Include headers
include_directories(include)
## Install executable
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
) )
## Install headers ## Install headers
install(FILES include/serial/serial.h include/serial/v8stdint.h install(FILES include/serial/serial.h include/serial/v8stdint.h
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial) DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
## Tests
## Tests if(CATKIN_ENABLE_TESTING)
if(CATKIN_ENABLE_TESTING)
add_subdirectory(tests) 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()
endif() endif()