mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
Merge a0ff363f02d05c418da3831a49973bf99a24c44f into 69e0372cf0d3796e84ce9a09aff1d74496f68720
This commit is contained in:
commit
1b63e7e097
143
CMakeLists.txt
143
CMakeLists.txt
@ -1,15 +1,25 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.3)
|
cmake_minimum_required(VERSION 2.8.3)
|
||||||
project(serial)
|
|
||||||
|
# Either this or bump cmake_minimum_required to 3.0+
|
||||||
|
# Allow us to use Version in project() call : https://cmake.org/cmake/help/v3.0/policy/CMP0048.html#policy:CMP0048
|
||||||
|
cmake_policy(SET CMP0048 NEW)
|
||||||
|
|
||||||
|
project(serial VERSION 1.2.1)
|
||||||
|
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
# Use Catkin
|
||||||
|
option(USE_CATKIN on)
|
||||||
|
# Build serial sample
|
||||||
|
option(BUILD_SAMPLE on)
|
||||||
|
|
||||||
|
|
||||||
# Find catkin
|
# Find catkin
|
||||||
find_package(catkin REQUIRED)
|
if(USE_CATKIN)
|
||||||
|
find_package(catkin REQUIRED)
|
||||||
|
|
||||||
if(APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
find_library(IOKIT_LIBRARY IOKit)
|
|
||||||
find_library(FOUNDATION_LIBRARY Foundation)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
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)
|
||||||
@ -18,24 +28,29 @@ if(UNIX AND NOT APPLE)
|
|||||||
INCLUDE_DIRS include
|
INCLUDE_DIRS include
|
||||||
DEPENDS rt pthread
|
DEPENDS rt pthread
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
# Otherwise normal call
|
# Otherwise normal call
|
||||||
catkin_package(
|
catkin_package(
|
||||||
LIBRARIES ${PROJECT_NAME}
|
LIBRARIES ${PROJECT_NAME}
|
||||||
INCLUDE_DIRS include
|
INCLUDE_DIRS include
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Sources
|
## Sources
|
||||||
set(serial_SRCS
|
set(serial_SRCS
|
||||||
src/serial.cc
|
src/serial.cc
|
||||||
include/serial/serial.h
|
include/serial/serial.h
|
||||||
include/serial/v8stdint.h
|
include/serial/v8stdint.h
|
||||||
)
|
)
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
# If OSX
|
# If OSX
|
||||||
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)
|
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
# If unix
|
# If unix
|
||||||
list(APPEND serial_SRCS src/impl/unix.cc)
|
list(APPEND serial_SRCS src/impl/unix.cc)
|
||||||
@ -48,34 +63,90 @@ endif()
|
|||||||
|
|
||||||
## Add serial library
|
## Add serial library
|
||||||
add_library(${PROJECT_NAME} ${serial_SRCS})
|
add_library(${PROJECT_NAME} ${serial_SRCS})
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
find_library(IOKIT_LIBRARY IOKit)
|
||||||
|
find_library(FOUNDATION_LIBRARY Foundation)
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
target_link_libraries(${PROJECT_NAME} rt pthread)
|
target_link_libraries(${PROJECT_NAME} rt pthread)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(${PROJECT_NAME} setupapi)
|
target_link_libraries(${PROJECT_NAME} setupapi)
|
||||||
endif()
|
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})
|
|
||||||
|
|
||||||
## Include headers
|
## Include headers
|
||||||
include_directories(include)
|
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/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}
|
|
||||||
)
|
|
||||||
|
|
||||||
## Install headers
|
## Example
|
||||||
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
if(BUILD_SAMPLE)
|
||||||
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
|
add_executable(serial_example examples/serial_example.cc)
|
||||||
|
add_dependencies(serial_example ${PROJECT_NAME})
|
||||||
|
target_link_libraries(serial_example ${PROJECT_NAME})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
## Export
|
||||||
|
|
||||||
|
# Set postfix names for exporting
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
|
RELEASE_POSTFIX ""
|
||||||
|
RELWITHDEBINFO_POSTFIX "-rd"
|
||||||
|
MINSIZEREL_POSTFIX "-mr"
|
||||||
|
DEBUG_POSTFIX "-d")
|
||||||
|
|
||||||
|
|
||||||
|
if(USE_CATKIN)
|
||||||
|
## Install headers
|
||||||
|
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
||||||
|
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
|
||||||
|
## Install executable
|
||||||
|
install(TARGETS ${PROJECT_NAME}
|
||||||
|
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||||
|
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||||
|
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
set(EXPORT_TARGET_NAME serialTargets)
|
||||||
|
|
||||||
|
install(EXPORT ${EXPORT_TARGET_NAME} DESTINATION cmake/)
|
||||||
|
# Include module with fuction 'write_basic_package_version_file' and 'configure_package_config_file'
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
|
set(OUTPUT_CMAKE_EXPORT_GENERATED_FILES ${CMAKE_BINARY_DIR}/CMakeExportConfig)
|
||||||
|
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
|
||||||
|
write_basic_package_version_file(${OUTPUT_CMAKE_EXPORT_GENERATED_FILES}/${PROJECT_NAME}Config-version.cmake
|
||||||
|
# <AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion>
|
||||||
|
# Careful : SameMinorVersion and ExactVersion were introduced in CMake 3.11
|
||||||
|
COMPATIBILITY SameMajorVersion
|
||||||
|
)
|
||||||
|
|
||||||
|
# Configure '<PROJECT-NAME>Config.cmake'
|
||||||
|
configure_package_config_file(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
|
||||||
|
"${OUTPUT_CMAKE_EXPORT_GENERATED_FILES}/${PROJECT_NAME}Config.cmake"
|
||||||
|
INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Install config file generated
|
||||||
|
install(DIRECTORY ${OUTPUT_CMAKE_EXPORT_GENERATED_FILES}/
|
||||||
|
DESTINATION cmake/)
|
||||||
|
|
||||||
|
|
||||||
|
## Install headers
|
||||||
|
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
||||||
|
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/serial)
|
||||||
|
|
||||||
|
## Install executable
|
||||||
|
install(TARGETS ${PROJECT_NAME} EXPORT ${EXPORT_TARGET_NAME}
|
||||||
|
INCLUDES DESTINATION $<INSTALL_INTERFACE:include/>
|
||||||
|
ARCHIVE DESTINATION "lib" COMPONENT ${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
if(CATKIN_ENABLE_TESTING)
|
if(CATKIN_ENABLE_TESTING)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
6
cmake/serialConfig.cmake.in
Normal file
6
cmake/serialConfig.cmake.in
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@EXPORT_TARGET_NAME@.cmake")
|
||||||
|
|
||||||
|
check_required_components("@PROJECT_NAME@")
|
||||||
Loading…
x
Reference in New Issue
Block a user