mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-23 04:04:54 +08:00
Fix the build and cleanup CMakeLists
This commit is contained in:
parent
8900d469e5
commit
51741829c0
@ -3,58 +3,49 @@ project(serial)
|
|||||||
|
|
||||||
find_package(ament_cmake REQUIRED)
|
find_package(ament_cmake REQUIRED)
|
||||||
|
|
||||||
if(APPLE)
|
|
||||||
find_library(IOKIT_LIBRARY IOKit)
|
|
||||||
find_library(FOUNDATION_LIBRARY Foundation)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ament_export_include_directories(include)
|
ament_export_include_directories(include)
|
||||||
ament_export_libraries(${PROJECT_NAME})
|
ament_export_libraries(${PROJECT_NAME})
|
||||||
if(UNIX AND NOT APPLE)
|
|
||||||
# If Linux, add rt and pthread
|
|
||||||
set(rt_LIBRARIES rt)
|
|
||||||
set(pthread_LIBRARIES pthread)
|
|
||||||
ament_export_dependencies(rt pthread)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
## Sources
|
## Sources
|
||||||
set(serial_SRCS
|
## Add serial library
|
||||||
|
add_library(${PROJECT_NAME}
|
||||||
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 OSX
|
|
||||||
list(APPEND serial_SRCS src/impl/unix.cc)
|
|
||||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
|
|
||||||
elseif(UNIX)
|
|
||||||
# If unix
|
|
||||||
list(APPEND serial_SRCS src/impl/unix.cc)
|
|
||||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
|
|
||||||
else()
|
|
||||||
# If windows
|
|
||||||
list(APPEND serial_SRCS src/impl/win.cc)
|
|
||||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
## Add serial library
|
if(APPLE) # macOS
|
||||||
add_library(${PROJECT_NAME} ${serial_SRCS})
|
find_library(IOKIT_LIBRARY IOKit)
|
||||||
if(APPLE)
|
find_library(FOUNDATION_LIBRARY Foundation)
|
||||||
|
target_sources(${PROJECT_NAME} PRIVATE
|
||||||
|
src/impl/unix.cc
|
||||||
|
src/impl/list_ports/list_ports_osx.cc
|
||||||
|
)
|
||||||
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
||||||
elseif(UNIX)
|
elseif(UNIX) # .*nix
|
||||||
|
target_sources(${PROJECT_NAME} PRIVATE
|
||||||
|
src/impl/unix.cc
|
||||||
|
src/impl/list_ports/list_ports_linux.cc
|
||||||
|
)
|
||||||
target_link_libraries(${PROJECT_NAME} rt pthread)
|
target_link_libraries(${PROJECT_NAME} rt pthread)
|
||||||
else()
|
elseif(WIN32) # Windows
|
||||||
|
target_sources(${PROJECT_NAME} PRIVATE
|
||||||
|
src/impl/win.cc
|
||||||
|
src/impl/list_ports/list_ports_win.cc
|
||||||
|
)
|
||||||
target_link_libraries(${PROJECT_NAME} setupapi)
|
target_link_libraries(${PROJECT_NAME} setupapi)
|
||||||
ament_export_libraries(setupapi)
|
ament_export_libraries(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} PRIVATE include)
|
||||||
|
|
||||||
|
## Uncomment for example
|
||||||
|
# add_executable(serial_example examples/serial_example.cc)
|
||||||
|
# add_dependencies(serial_example ${PROJECT_NAME})
|
||||||
|
# target_link_libraries(serial_example ${PROJECT_NAME})
|
||||||
|
|
||||||
|
|
||||||
## Install executable
|
## Install executable
|
||||||
install(TARGETS ${PROJECT_NAME}
|
install(TARGETS ${PROJECT_NAME}
|
||||||
@ -68,8 +59,8 @@ install(FILES include/serial/serial.h include/serial/v8stdint.h
|
|||||||
)
|
)
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
if(BUILD_TESTING)
|
#if(BUILD_TESTING)
|
||||||
add_subdirectory(tests)
|
# add_subdirectory(tests)
|
||||||
endif()
|
#endif()
|
||||||
|
|
||||||
ament_package()
|
ament_package()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user