forked from wjwwood/serial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
147 lines (127 loc) · 3.53 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
cmake_minimum_required(VERSION 3.5)
project(serial
LANGUAGES CXX
VERSION 2.0.0
)
set(TARGET_NAME ${PROJECT_NAME}Targets)
### C
set(CMAKE_C_STANDARD 11)
### CXX
set(CMAKE_CXX_STANDARD 14)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif(NOT CMAKE_BUILD_TYPE)
option(SERIAL_BUILD_TESTS "Build tests." OFF)
option(SERIAL_BUILD_EXAMPLES "Build examples." OFF)
if(APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
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} PRIVATE ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
target_link_libraries(${PROJECT_NAME} PRIVATE rt pthread)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE setupapi)
endif()
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties(${PROJECT_NAME}
PROPERTIES
VERSION ${PROJECT_VERSION}
)
set(INSTALL_CMAKEDIR share/cmake/${PROJECT_NAME})
install(
TARGETS
${PROJECT_NAME}
EXPORT ${TARGET_NAME}
LIBRARY
COMPONENT lib
ARCHIVE
COMPONENT lib
)
install(
DIRECTORY
"${CMAKE_SOURCE_DIR}/include/"
TYPE INCLUDE
PATTERN "impl" EXCLUDE
)
install(
EXPORT
${TARGET_NAME}
NAMESPACE
"${PROJECT_NAME}::"
DESTINATION
${INSTALL_CMAKEDIR}
COMPONENT
dev
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
${CMAKE_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALL_CMAKEDIR}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION
${INSTALL_CMAKEDIR}
)
## Uncomment for example
if(SERIAL_BUILD_EXAMPLES)
add_executable(serial_example examples/serial_example.cc)
add_dependencies(serial_example ${PROJECT_NAME})
target_link_libraries(serial_example ${PROJECT_NAME})
endif(SERIAL_BUILD_EXAMPLES)
## Tests
if(SERIAL_BUILD_TESTS)
if(UNIX)
find_package(GTest REQUIRED)
include(GoogleTest)
include(CTest)
find_program(MEMORYCHECK_COMMAND NAMES valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full")
add_executable(${PROJECT_NAME}-test tests/unix_serial_tests.cc)
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} GTest::GTest)
if(NOT APPLE)
target_link_libraries(${PROJECT_NAME}-test util)
endif()
gtest_discover_tests(${PROJECT_NAME}-test)
if(NOT APPLE)
add_executable(${PROJECT_NAME}-test-timer tests/unit/unix_timer_tests.cc)
target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME} GTest::GTest)
gtest_discover_tests(${PROJECT_NAME}-test-timer)
endif()
endif(UNIX)
endif(SERIAL_BUILD_TESTS)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(packing)