-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
146 lines (132 loc) · 3.95 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.10 FATAL_ERROR)
project(vl53l1x-linux
LANGUAGES CXX C
VERSION 0.2.3
DESCRIPTION "A VL53L1X sensor interfacing library for GNU/Linux"
)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
###
# Project options
###
option(BUILD_EXAMPLES "Whether to build examples library" ON)
# Set C++17, with GNU extensions
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
###
# Project targets
###
add_library(${PROJECT_NAME} SHARED
src/VL53L1X.cpp
src/VL53L1X_default_config.cpp
)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
src
)
add_library(${PROJECT_NAME}_static STATIC
src/VL53L1X.cpp
src/VL53L1X_default_config.cpp
)
target_include_directories(${PROJECT_NAME}_static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
src
)
# Link against sbc-linux-interfaces
find_package(ament_cmake QUIET)
find_package(sbc-linux-interfaces QUIET)
if(ament_cmake_FOUND AND sbc-linux-interfaces_FOUND)
message(STATUS "Ament found, linking against ament package")
ament_target_dependencies(${PROJECT_NAME} sbc-linux-interfaces)
else()
message(STATUS "Ament not found, linking against submodule")
add_subdirectory(libs/sbc-linux-interfaces)
endif()
target_link_libraries(${PROJECT_NAME} sbc-linux-interfaces)
target_link_libraries(${PROJECT_NAME}_static sbc-linux-interfaces)
# Set the library object version
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
)
set_target_properties(${PROJECT_NAME}_static PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
OUTPUT_NAME ${PROJECT_NAME}
)
# Workaround for older GCCs
if (CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (NOT GCC_VERSION VERSION_GREATER 8.0)
message(STATUS "g++ <= 8 detected, adding explicit link to stdc++fs")
target_link_libraries(${PROJECT_NAME} stdc++fs)
target_link_libraries(${PROJECT_NAME}_static stdc++fs)
endif()
endif()
###
# Install targets
###
# Install the main target (the library itself)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(TARGETS ${PROJECT_NAME}_static
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# Install the headers and package.xml
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES ${PROJECT_SOURCE_DIR}/package.xml
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
)
# Install the CMake targets
install(
EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
)
# Prepare and install the package version file
write_basic_package_version_file(
"${PROJECT_NAME}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
)
# Prepare and install the package config file
set(INCLUDE_INSTALL_DIRS ${CMAKE_INSTALL_INCLUDEDIR})
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
PATH_VARS INCLUDE_INSTALL_DIRS
)
install(
FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
)
###
# (Optionally) include examples
###
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()