mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
modern CMake
This commit is contained in:
parent
69e0372cf0
commit
cfa5929b8b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
*/out/**
|
||||||
.*
|
.*
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.coverage
|
*.coverage
|
||||||
|
|||||||
@ -1,37 +1,15 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.3)
|
cmake_minimum_required(VERSION 3.22)
|
||||||
project(serial)
|
project(serial LANGUAGES CXX)
|
||||||
|
|
||||||
# Find catkin
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
find_package(catkin REQUIRED)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
if(APPLE)
|
add_library(${PROJECT_NAME} STATIC)
|
||||||
find_library(IOKIT_LIBRARY IOKit)
|
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||||
find_library(FOUNDATION_LIBRARY Foundation)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(UNIX AND NOT APPLE)
|
set(serial_SRCS "")
|
||||||
# If Linux, add rt and pthread
|
set(serial_LIBS "")
|
||||||
set(rt_LIBRARIES rt)
|
|
||||||
set(pthread_LIBRARIES pthread)
|
|
||||||
catkin_package(
|
|
||||||
LIBRARIES ${PROJECT_NAME}
|
|
||||||
INCLUDE_DIRS include
|
|
||||||
DEPENDS rt pthread
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
# Otherwise normal call
|
|
||||||
catkin_package(
|
|
||||||
LIBRARIES ${PROJECT_NAME}
|
|
||||||
INCLUDE_DIRS include
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
## Sources
|
|
||||||
set(serial_SRCS
|
|
||||||
src/serial.cc
|
|
||||||
include/serial/serial.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)
|
||||||
@ -46,36 +24,38 @@ else()
|
|||||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
|
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
## Add serial library
|
|
||||||
add_library(${PROJECT_NAME} ${serial_SRCS})
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
list(APPEND serial_LIBS ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
target_link_libraries(${PROJECT_NAME} rt pthread)
|
list(APPEND serial_LIBS rt pthread)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(${PROJECT_NAME} setupapi)
|
list(APPEND serial_LIBS 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
|
target_sources(${PROJECT_NAME}
|
||||||
include_directories(include)
|
PRIVATE
|
||||||
|
src/serial.cc
|
||||||
## Install executable
|
PUBLIC
|
||||||
install(TARGETS ${PROJECT_NAME}
|
include/serial/serial.h
|
||||||
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
||||||
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
||||||
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
## Install headers
|
target_link_libraries(${PROJECT_NAME}
|
||||||
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
PUBLIC
|
||||||
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
|
|
||||||
|
|
||||||
## Tests
|
PRIVATE
|
||||||
if(CATKIN_ENABLE_TESTING)
|
${serial_LIBS}
|
||||||
add_subdirectory(tests)
|
)
|
||||||
endif()
|
|
||||||
|
target_include_directories(
|
||||||
|
${PROJECT_NAME}
|
||||||
|
|
||||||
|
PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
|
)
|
||||||
|
set_property(TARGET ${PROJECT_NAME} PROPERTY PUBLIC_HEADER include/serial/serial.h)
|
||||||
|
|
||||||
|
install(TARGETS ${PROJECT_NAME})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user