-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
155 lines (131 loc) · 5.33 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
148
149
150
151
152
153
154
155
cmake_minimum_required(VERSION 3.15)
project(sick-lms5xx VERSION 0.1.0 LANGUAGES C CXX)
set(PROJECT_NAME_UPPER SickLMS5xx)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard")
message(STATUS "CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
find_package(Eigen3 3.3.4 REQUIRED)
set(SRCS
${CMAKE_CURRENT_SOURCE_DIR}/src/parsing.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/network.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/util.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sopas.cpp
)
set(HDRS
${CMAKE_CURRENT_SOURCE_DIR}/include/sick-lms5xx/parsing.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/sick-lms5xx/network.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/sick-lms5xx/util.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/sick-lms5xx/sopas.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/sick-lms5xx/config.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/sick-lms5xx/types.hpp)
set(LIBS Eigen3::Eigen)
if(UNIX AND NOT APPLE)
find_package(Threads REQUIRED)
list(APPEND LIBS Threads::Threads)
endif()
option(WITH_PCL "Enable PCL support" ON)
if(WITH_PCL)
find_package(PCL 1.10 REQUIRED COMPONENTS common io)
list(APPEND SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/pcl.cpp)
list(APPEND HDRS ${CMAKE_CURRENT_SOURCE_DIR}/include/sick-lms5xx/pcl.hpp)
list(APPEND LIBS ${PCL_LIBRARIES})
endif()
option(BUILD_EXAMPLE "Build example code" ON)
if(BUILD_EXAMPLE)
add_executable(example ${CMAKE_CURRENT_SOURCE_DIR}/src/example.cpp)
target_include_directories(example PRIVATE SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_sources(example PRIVATE ${SRCS})
target_link_libraries(example PRIVATE ${LIBS})
target_link_directories(example PRIVATE ${PCL_LIBRARY_DIRS})
if (WITH_PCL)
target_include_directories(example PRIVATE ${PCL_INCLUDE_DIRS})
target_compile_definitions(example PRIVATE ${PCL_DEFINITIONS})
target_compile_definitions(example PRIVATE WITH_PCL)
endif()
endif()
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
if (BUILD_SHARED_LIBS)
add_library(${PROJECT_NAME} SHARED ${SRCS})
else()
add_library(${PROJECT_NAME} STATIC ${SRCS})
endif()
add_library(${PROJECT_NAME_UPPER}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}
SYSTEM
PUBLIC
$<INSTALL_INTERFACE:include/>
)
target_include_directories(${PROJECT_NAME}
PRIVATE
# build tree includes need to be added only during build, not install
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${EIGEN3_INCLUDE_DIRS}
)
if (WITH_PCL)
target_include_directories(${PROJECT_NAME} PUBLIC ${PCL_INCLUDE_DIRS})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PCL_DEFINITIONS} WITH_PCL)
target_link_directories(${PROJECT_NAME} PUBLIC ${PCL_LIBRARY_DIRS})
endif()
# make eigen, pcl an threads transitive dependencies of dependent projects
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBS})
include(GNUInstallDirs)
# install cmake config script to lib/cmake/SickLMS5xx/...
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME_UPPER})
# configure install of the library and associate it with an export name
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# use uppercased name for the library's export name (whatever that is)
# This means you use this in dependent projects like this:
# `target_link_libraries(mytarget PUBLIC SickLMS5xx::SickLMS5xx)`
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME ${PROJECT_NAME_UPPER})
# install the header files
install(FILES ${HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sick-lms5xx)
# install the export file for the exported targets. Prepend SickLMS5xx:: to the target
install(EXPORT ${PROJECT_NAME}-targets
FILE
${PROJECT_NAME_UPPER}Targets.cmake
NAMESPACE
${PROJECT_NAME_UPPER}::
DESTINATION
${INSTALL_CONFIGDIR}
)
# make the version selection script
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_UPPER}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
set(INCLUDE_INSTALL_DIR include/)
set(LIBRARY_INSTALL_DIR lib/)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME_UPPER}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_UPPER}Config.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR
)
# install the cmake config and config version scripts
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_UPPER}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_UPPER}ConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
# export the export so this project can be used with add_subdirectory()
export(EXPORT ${PROJECT_NAME}-targets FILE
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME_UPPER}Targets.cmake NAMESPACE
${PROJECT_NAME_UPPER}::)
# add an uninstall target
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake)
endif()
# `make package` creates a simple binary release with include/ and lib/
include(CPack)