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
|
||||
*.coverage
|
||||
|
||||
@ -1,37 +1,15 @@
|
||||
cmake_minimum_required(VERSION 2.8.3)
|
||||
project(serial)
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
project(serial LANGUAGES CXX)
|
||||
|
||||
# Find catkin
|
||||
find_package(catkin REQUIRED)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
if(APPLE)
|
||||
find_library(IOKIT_LIBRARY IOKit)
|
||||
find_library(FOUNDATION_LIBRARY Foundation)
|
||||
endif()
|
||||
add_library(${PROJECT_NAME} STATIC)
|
||||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
# If Linux, add rt and pthread
|
||||
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
|
||||
)
|
||||
set(serial_SRCS "")
|
||||
set(serial_LIBS "")
|
||||
if(APPLE)
|
||||
# If OSX
|
||||
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)
|
||||
endif()
|
||||
|
||||
## Add serial library
|
||||
add_library(${PROJECT_NAME} ${serial_SRCS})
|
||||
if(APPLE)
|
||||
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
||||
list(APPEND serial_LIBS ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
||||
elseif(UNIX)
|
||||
target_link_libraries(${PROJECT_NAME} rt pthread)
|
||||
list(APPEND serial_LIBS rt pthread)
|
||||
else()
|
||||
target_link_libraries(${PROJECT_NAME} setupapi)
|
||||
list(APPEND serial_LIBS 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})
|
||||
|
||||
## 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}
|
||||
target_sources(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
src/serial.cc
|
||||
PUBLIC
|
||||
include/serial/serial.h
|
||||
)
|
||||
|
||||
## Install headers
|
||||
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
||||
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
|
||||
## Tests
|
||||
if(CATKIN_ENABLE_TESTING)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
PRIVATE
|
||||
${serial_LIBS}
|
||||
)
|
||||
|
||||
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