1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-23 04:04:54 +08:00
serial/CMakeLists.txt
Ivan Kishchenko 5606a99ab3 protocol
2019-09-21 14:40:48 +07:00

82 lines
2.2 KiB
CMake

cmake_minimum_required(VERSION 3.2)
project(serial)
if (APPLE)
message("Apple build")
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(NO_OUTPUT_DIRS)
set (MAIN_LIBS ${CONAN_LIBS})
else()
message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()
else()
message("Unix build")
find_package(Boost COMPONENTS date_time filesystem system log thread)
if(Boost_FOUND)
set(MAIN_LIBS ${Boost_LIBRARIES} )
set(PLATFORM_SPECIFIC_LIBS pthread)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_LOG_DYN_LINK")
else()
message("Please install boot >= 1.67")
endif()
endif()
if(UNIX AND NOT APPLE)
# If Linux, add rt and pthread
set(rt_LIBRARIES rt)
set(pthread_LIBRARIES pthread)
endif()
## Sources
set(serial_SRCS
src/serial.cc
)
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
add_library(${PROJECT_NAME} ${serial_SRCS})
if(APPLE)
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
target_link_libraries(${PROJECT_NAME} rt pthread)
else()
target_link_libraries(${PROJECT_NAME} setupapi)
endif()
## Include headers
include_directories(include)
## Uncomment for example
add_executable(${PROJECT_NAME}-example examples/serial_example.cc)
add_dependencies(${PROJECT_NAME}-example ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}-example ${PROJECT_NAME})
## Tests
enable_testing()
add_subdirectory(tests)
## Install executable
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
## Install headers
install(FILES include/serial/serial.h include/serial/v8stdint.h DESTINATION include/serial)