-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
146 lines (117 loc) · 3.93 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
cmake_minimum_required(VERSION 3.0.2)
project(slambox_sdk
VERSION 0.2.0
LANGUAGES CXX
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
option(test "Build unit tests." OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
set(INSTALL_STATIC "Install static library" ON)
set(INSTALL_SHARED "Install shared library" ON)
set (CPACK_PACKAGE_NAME ${PROJECT_NAME})
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "SLAMBOX SDK")
set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
include (CPack)
## Compile as C++17, supported in ROS Kinetic and newer
add_compile_options(-std=c++17 -O3)
find_package(ZLIB REQUIRED)
find_package(Threads REQUIRED)
include_directories(
include
)
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
set(${PROJECT_NAME}_LIBRARIES
ZLIB::ZLIB
Threads::Threads
serial)
add_library(${PROJECT_NAME}_static STATIC "")
set_target_properties(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}_static PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_sources(${PROJECT_NAME}_static PUBLIC
${SOURCES}
)
target_link_libraries(${PROJECT_NAME}_static
PRIVATE
${${PROJECT_NAME}_LIBRARIES}
)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
)
install(DIRECTORY include/
DESTINATION include ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION lib/cmake/${PROJECT_NAME}
)
if (INSTALL_STATIC)
install(TARGETS ${PROJECT_NAME}_static
EXPORT ${PROJECT_NAME}Config
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
endif()
if (INSTALL_SHARED)
add_library(${PROJECT_NAME}_shared SHARED "")
set_target_properties(${PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}_shared PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_sources(${PROJECT_NAME}_shared PUBLIC
${SOURCES}
)
target_link_libraries(${PROJECT_NAME}_shared
PRIVATE
${${PROJECT_NAME}_LIBRARIES}
)
install(TARGETS ${PROJECT_NAME}_shared
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
endif()
# Examples
if (BUILD_EXAMPLES)
add_subdirectory(examples/serial_communication)
add_subdirectory(examples/udp_communication)
add_subdirectory(examples/config_cli)
endif()
# Unit test
if (test)
set(TEST_NAME_BASE test-${PROJECT_NAME})
find_package(glog 0.6.0 REQUIRED)
enable_testing()
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
# Auto adding unit test files starting with test_*.cpp
FILE(GLOB UNITTEST_LIST CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tests/test_*.cpp")
FOREACH(unittest_path ${UNITTEST_LIST})
get_filename_component(unittest_name ${unittest_path} NAME_WLE)
string(REPLACE "test_" "" unittest_name ${unittest_name})
set(TEST_NAME ${TEST_NAME_BASE}-${unittest_name})
message("Build Unit Test for ${unittest_path} with name of ${TEST_NAME}")
add_executable(${TEST_NAME} ${unittest_path} ${SOURCES})
target_link_libraries(${TEST_NAME}
gtest
gtest_main
glog::glog
${PROJECT_NAME}_static
)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
ENDFOREACH()
endif()