2023-06-16 20:14:00 -03:00
|
|
|
cmake_minimum_required(VERSION 3.16)
|
2020-09-22 13:08:46 +02:00
|
|
|
|
|
|
|
|
# General setup
|
|
|
|
|
project(serial
|
|
|
|
|
VERSION 1.2.1
|
2023-06-16 20:44:37 -03:00
|
|
|
LANGUAGES CXX
|
2020-09-22 13:08:46 +02:00
|
|
|
DESCRIPTION "Cross-platform, Serial Port library written in C++"
|
|
|
|
|
HOMEPAGE_URL "http://wjwwood.io/serial/"
|
|
|
|
|
)
|
2012-10-23 23:47:11 -07:00
|
|
|
|
2014-04-25 02:50:40 +01:00
|
|
|
if(APPLE)
|
2018-11-12 12:01:58 -06:00
|
|
|
find_library(IOKIT_LIBRARY IOKit)
|
|
|
|
|
find_library(FOUNDATION_LIBRARY Foundation)
|
2014-04-25 02:50:40 +01:00
|
|
|
endif()
|
|
|
|
|
|
2012-10-23 23:47:11 -07:00
|
|
|
## Sources
|
|
|
|
|
set(serial_SRCS
|
|
|
|
|
src/serial.cc
|
2012-12-03 15:31:41 -08:00
|
|
|
include/serial/serial.h
|
|
|
|
|
include/serial/v8stdint.h
|
2012-10-23 23:47:11 -07:00
|
|
|
)
|
2014-04-25 02:50:40 +01:00
|
|
|
if(APPLE)
|
2018-11-12 12:01:58 -06:00
|
|
|
# If OSX
|
|
|
|
|
list(APPEND serial_SRCS src/impl/unix.cc)
|
|
|
|
|
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
|
2014-04-25 02:50:40 +01:00
|
|
|
elseif(UNIX)
|
2012-10-23 23:47:11 -07:00
|
|
|
# If unix
|
2012-12-03 15:31:41 -08:00
|
|
|
list(APPEND serial_SRCS src/impl/unix.cc)
|
2014-02-22 20:02:32 +00:00
|
|
|
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
|
2014-08-16 22:08:56 +02:00
|
|
|
else()
|
2012-10-23 23:47:11 -07:00
|
|
|
# If windows
|
2012-12-03 15:31:41 -08:00
|
|
|
list(APPEND serial_SRCS src/impl/win.cc)
|
2014-08-16 22:08:56 +02:00
|
|
|
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
|
2012-10-23 23:47:11 -07:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
## Add serial library
|
2020-09-22 13:28:04 +02:00
|
|
|
set(serial_HEADERS
|
|
|
|
|
include/serial/serial.h
|
|
|
|
|
include/serial/v8stdint.h
|
|
|
|
|
)
|
|
|
|
|
# Build, link and install main library
|
2023-06-15 11:47:17 -03:00
|
|
|
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
|
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
endif()
|
2012-12-03 14:51:10 -08:00
|
|
|
add_library(${PROJECT_NAME} ${serial_SRCS})
|
2023-06-14 11:18:01 -03:00
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
2020-09-22 13:28:04 +02:00
|
|
|
VERSION ${PROJECT_VERSION}
|
2023-06-16 20:39:22 -03:00
|
|
|
SOVERSION 1
|
2020-09-22 13:28:04 +02:00
|
|
|
PUBLIC_HEADER "${serial_HEADERS}"
|
|
|
|
|
)
|
2023-06-15 11:47:17 -03:00
|
|
|
|
2020-09-22 13:28:04 +02:00
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC include)
|
2023-06-14 11:18:01 -03:00
|
|
|
|
2014-04-25 02:50:40 +01:00
|
|
|
if(APPLE)
|
2018-11-12 12:01:58 -06:00
|
|
|
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
|
2014-04-25 02:50:40 +01:00
|
|
|
elseif(UNIX)
|
2018-11-12 12:01:58 -06:00
|
|
|
target_link_libraries(${PROJECT_NAME} rt pthread)
|
2014-08-16 22:08:56 +02:00
|
|
|
else()
|
2018-11-12 12:01:58 -06:00
|
|
|
target_link_libraries(${PROJECT_NAME} setupapi)
|
2012-10-24 01:32:23 -07:00
|
|
|
endif()
|
2012-10-23 23:47:11 -07:00
|
|
|
|
|
|
|
|
## 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
|
2013-01-09 10:53:58 -08:00
|
|
|
install(TARGETS ${PROJECT_NAME}
|
2019-07-03 13:24:15 -07:00
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
|
RUNTIME DESTINATION bin
|
2020-09-22 13:28:04 +02:00
|
|
|
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}
|
2012-10-23 23:47:11 -07:00
|
|
|
)
|
|
|
|
|
|
2013-01-09 10:53:58 -08:00
|
|
|
## Install headers
|
|
|
|
|
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
2019-07-03 13:24:15 -07:00
|
|
|
DESTINATION include/serial)
|
|
|
|
|
|
|
|
|
|
## Install CMake config
|
|
|
|
|
install(FILES cmake/serialConfig.cmake
|
|
|
|
|
DESTINATION share/serial/cmake)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Install package.xml
|
|
|
|
|
install(FILES package.xml
|
|
|
|
|
DESTINATION share/serial)
|
2013-01-09 10:53:58 -08:00
|
|
|
|
2012-10-23 23:47:11 -07:00
|
|
|
## Tests
|
2019-07-03 13:24:15 -07:00
|
|
|
include(CTest)
|
|
|
|
|
if(BUILD_TESTING)
|
2013-11-18 20:50:21 -05:00
|
|
|
add_subdirectory(tests)
|
2013-07-31 16:47:19 -07:00
|
|
|
endif()
|