-
Notifications
You must be signed in to change notification settings - Fork 57
/
CMakeLists.txt
213 lines (163 loc) · 6.81 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
cmake_minimum_required(VERSION 2.8)
### Compiler config ###
# Use g++-4.9 if there is also an older g++ version on the system
if("${CMAKE_CXX_COMPILER}" STREQUAL "" OR "${CMAKE_CXX_COMPILER}" STREQUAL "gcc" OR "${CMAKE_CXX_COMPILER}" STREQUAL "g++")
find_program(NEWER_GNU_CXX_COMPILER g++-4.9)
if (NOT "${NEWER_GNU_CXX_COMPILER}" STREQUAL "")
set(CMAKE_CXX_COMPILER ${NEWER_GNU_CXX_COMPILER})
message("Using ${CMAKE_CXX_COMPILER} as compiler.")
endif()
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "")
if("${CMAKE_CXX_COMPILER}" MATCHES ".*g[+][+].*")
set(CMAKE_CXX_COMPILER_ID "GNU")
endif()
endif()
if("${CMAKE_CXX_COMPILER_VERSION}" STREQUAL "")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version COMMAND head -1 COMMAND awk "{ print $NF }" OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(FATAL_ERROR "Setting CMAKE_CXX_COMPILER_ID not implemented.")
endif()
endif()
# GCC ist not supported until 4.9
# Clang ist not supported until 3.6
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
message(FATAL_ERROR "GCC version must be at least 4.9. Earlier versions miss std::regex support.")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
message(FATAL_ERROR "Clang version must be at least 3.6! Earlier versions don't support debug information for auto.")
endif()
else()
message(FATAL_ERROR "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.")
endif()
# Compiler flags
# TOD0: -std=c++14 will be obsolete when reverting to minimum CMake version 3.2 and
# using set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 14) again.
project(kacanopen C CXX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra") # -Werror
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") # -Werror
### settings ###
include(CMakeSettings.txt)
## Driver begin ##
if (DEFINED CAN_DRIVER_NAME)
message(WARNING "CAN_DRIVER_NAME is deprecated. Use DRIVER instead. Overwriting DRIVER with CAN_DRIVER_NAME (${CAN_DRIVER_NAME}) now...")
set(DRIVER "${CAN_DRIVER_NAME}")
endif()
foreach(BUILD_DRIVER ${BUILD_DRIVERS})
# TODO: Replace with CMake 3.3 command IN_LIST
list(FIND SUPPORTED_DRIVERS "${BUILD_DRIVER}" supported)
if (${supported} EQUAL -1)
message(FATAL_ERROR "Driver ${BUILD_DRIVER} does not exist, but you've specified it in BUILD_DRIVERS.")
endif()
endforeach()
list(FIND SUPPORTED_DRIVERS "${DRIVER}" driver_supported)
if (${driver_supported} EQUAL -1)
message(FATAL_ERROR "Driver ${DRIVER} does not exist, but you've set it as DRIVER.")
endif()
set(DRIVER_LINK_NAME can_${DRIVER})
message(STATUS "Using CAN driver ${DRIVER_LINK_NAME}")
if(${BUILD_ALL_DRIVERS})
message(STATUS "Building all available drivers.")
endif()
## Driver end ##
if(${CMAKE_BUILD_TYPE} MATCHES "Release")
message(STATUS "You are in release mode.")
else()
if(${EXHAUSTIVE_DEBUGGING})
message(STATUS "Enabled exhaustive debugging.")
add_definitions("-DEXHAUSTIVE_DEBUGGING")
else()
message(STATUS "Enabled debugging.")
endif()
endif()
### constants ###
add_definitions("-DSDO_RESPONSE_TIMEOUT_MS=${SDO_RESPONSE_TIMEOUT_MS}")
message(STATUS "SDO response timeout is set to ${SDO_RESPONSE_TIMEOUT_MS}ms")
add_definitions("-DBUSNAME=\"${BUSNAME}\"")
message(STATUS "Busname is set to ${BUSNAME} (only used by examples)")
add_definitions("-DBAUDRATE=${BAUDRATE}")
message(STATUS "Baudrate is set to ${BAUDRATE} (only used by examples)")
add_definitions("-DCONSECUTIVE_SEND_PAUSE_MS=${CONSECUTIVE_SEND_PAUSE_MS}")
message(STATUS "Pause between two consecutively sent CAN frames is set to ${CONSECUTIVE_SEND_PAUSE_MS}ms")
### dependencies ###
find_package(Threads)
find_package(Boost 1.46.1 COMPONENTS system filesystem REQUIRED)
# Boost required for property_tree / ini_parser
if(NOT(Boost_FOUND))
message(FATAL_ERROR "Boost > 1.46.1 not found. Boost is required for ini_parser class. This is a header-only library. You can simply download the latest boost package from http://www.boost.org/, extract it into any directory and include it using the following catkin/CMake argument: -DBOOST_ROOT=\"/path/to/boost/\"")
endif()
message(STATUS "Found Boost headers in ${Boost_INCLUDE_DIRS}")
message(STATUS "Found Boost system library: ${Boost_SYSTEM_LIBRARY}")
message(STATUS "Found Boost filesystem library: ${Boost_FILESYSTEM_LIBRARY}")
message(STATUS "Found Threads library: ${CMAKE_THREAD_LIBS_INIT}")
### ROS ###
if (NOT(${NO_ROS}))
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
sensor_msgs
# message_generation
)
catkin_package(
INCLUDE_DIRS core/include master/include ros_bridge/include
LIBRARIES ${CAN_DRIVER} kacanopen_core kacanopen_master kacanopen_ros_bridge
CATKIN_DEPENDS message_runtime
)
endif()
### includes ###
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
if (NOT(${NO_ROS}))
include_directories(SYSTEM ${catkin_INCLUDE_DIRS})
endif()
include_directories(${CMAKE_CURRENT_LIST_DIR}/core/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/master/include)
include_directories(${CMAKE_CURRENT_LIST_DIR}/ros_bridge/include)
### Installation ###
# argument 1: targets
# argument 2: if true, install ${CMAKE_CURRENT_LIST_DIR}/include/
# call this from subproject's CMake files
macro(kacanopen_install)
message(STATUS "Configuring installation for target(s) ${ARGV0}")
if (${NO_ROS})
install(TARGETS ${ARGV0}
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
if (${ARGV1})
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
DESTINATION include/kacanopen
)
endif()
else()
install(TARGETS ${ARGV0}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION bin
)
if (${ARGV1})
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)
endif()
endif()
endmacro()
# Install EDS library
message(STATUS "Configuring installation for EDS library")
add_definitions("-DSHARE_SOURCE_PATH=\"${CMAKE_CURRENT_LIST_DIR}/master/share\"")
add_definitions("-DSHARE_INSTALLED_PATH=\"${CMAKE_INSTALL_PREFIX}/share/kacanopen\"")
message(STATUS "SHARE_SOURCE_PATH set to ${CMAKE_CURRENT_LIST_DIR}/share.")
message(STATUS "SHARE_INSTALLED_PATH set to ${CMAKE_INSTALL_PREFIX}/share/kacanopen.")
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/master/share/
DESTINATION share/kacanopen
)
### Source code ###
if (NOT(${NO_ROS}))
add_subdirectory(ros_bridge)
endif()
add_subdirectory(drivers_lgpl)
add_subdirectory(drivers)
add_subdirectory(core)
add_subdirectory(master)
add_subdirectory(examples)