-
Notifications
You must be signed in to change notification settings - Fork 17
/
CMakeLists.txt
166 lines (136 loc) · 7.19 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
cmake_minimum_required(VERSION 3.8.0)
project(tensorflow_ros_cpp)
find_package(catkin REQUIRED)
# variables affecting the search for the tensorflow library
if("$ENV{ROS_PYTHON_VERSION}" STREQUAL "2")
set(TF_LIBRARY_VERSION 1 CACHE STRING "Whether to search for Tensorflow 1.x or 2.x")
else()
set(TF_LIBRARY_VERSION 2 CACHE STRING "Whether to search for Tensorflow 1.x or 2.x")
endif()
set(FORCE_TF_PIP_SEARCH OFF CACHE BOOL "Whether to search for pip-installed Tensorflow even on systems using C++11 ABI")
set(DISABLE_TF_PIP_SEARCH OFF CACHE BOOL "Whether to skip search for pip-installed Tensorflow")
set(FORCE_TF_BAZEL_SEARCH OFF CACHE BOOL "Whether to search for bazel-compiled Tensorflow even if tensorflow was already found")
set(DISABLE_TF_BAZEL_SEARCH OFF CACHE BOOL "Whether to skip search for bazel-compiled Tensorflow")
set(FORCE_TF_CATKIN_SEARCH OFF CACHE BOOL "Whether to search for tensorflow_catkin even if tensorflow was already found")
set(DISABLE_TF_CATKIN_SEARCH OFF CACHE BOOL "Whether to skip search for tensorflow_catkin")
# variables affecting pip search
set(TF_PYTHON_VERSION $ENV{ROS_PYTHON_VERSION} CACHE STRING "Python version to be used for searching for Tensorflow")
set(TF_PYTHON_LIBRARY "" CACHE STRING "Python development library of the interpreter used for the found tensorflow. Use only when find_package finds wrong version of PythonLibs, which might be the case if you want to use Tensorflow from Python3.")
set(TF_PIP_EXECUTABLE pip${TF_PYTHON_VERSION} CACHE STRING "Path to pip executable used for searching for tensorflow")
set(TF_PIP_DISABLE_SEARCH_FOR_GPU_VERSION OFF CACHE BOOL "If ON, tensorflow-gpu will be ignored during the search")
set(TF_PIP_PATH "" CACHE STRING "Manually defined path to (site|dist)-packages/tensorflow (should not be needed)")
# variables affecting bazel search
set(TF_BAZEL_LIBRARY "${CATKIN_DEVEL_PREFIX}/../libtensorflow_cc.so" CACHE STRING "Path to the bazel-compiled Tensorflow C++ library")
set(TF_BAZEL_SRC_DIR "${CATKIN_DEVEL_PREFIX}/../tensorflow-include-base" CACHE STRING "Path to the Tensorflow sources directory")
set(TF_BAZEL_USE_SYSTEM_PROTOBUF OFF CACHE BOOL "Whether to use system-installed protobuf includes or those distributed with Tensorflow")
message("-- tensorflow_ros_cpp is searching for TensorFlow ${TF_LIBRARY_VERSION}.x library")
message("-- tensorflow_ros_cpp is probing the system")
# check for a modern c++ compiler, since tensorflow needs support for the c++11 standard
include(CheckCXXCompilerFlag)
if("${TF_LIBRARY_VERSION}" STREQUAL "1")
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(NOT COMPILER_SUPPORTS_CXX11)
message(FATAL_ERROR "You must use a compiler that supports the c++11 standard, e.g. GCC 4.9.")
endif()
else()
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
if(NOT COMPILER_SUPPORTS_CXX14)
message(FATAL_ERROR "You must use a compiler that supports the c++14 standard, e.g. GCC 8.")
endif()
endif()
# detect if the system uses C++11 ABI
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/detect_cxx11_abi.sh ${CMAKE_CXX_COMPILER}
RESULT_VARIABLE DETECT_CXX11_ABI_RESULT
OUTPUT_QUIET
)
if("${DETECT_CXX11_ABI_RESULT}" STREQUAL "0")
set(SYSTEM_USES_CXX11_ABI 1 CACHE BOOL "Whether the system uses C++11 ABI")
message("-- - The system uses C++11 ABI.")
if("${TF_LIBRARY_VERSION}" STREQUAL "1")
message("-- -- The use of tensorflow from pip is possible, but problematic; consider compiling tensorflow yourself")
else()
message("-- -- You can use tensorflow from pip without problems.")
endif()
else()
set(SYSTEM_USES_CXX11_ABI 0 CACHE BOOL "Whether the system uses C++11 ABI")
message("-- - The system doesn't use C++11 ABI.")
if("${TF_LIBRARY_VERSION}" STREQUAL "1")
message("-- -- You can use tensorflow from pip without problems.")
else()
message("-- -- The use of tensorflow from pip is possible, but problematic; consider compiling tensorflow yourself")
endif()
endif()
# start the search
set(HAS_TENSORFLOW_GPU 0)
set(TENSORFLOW_FOUND 0)
set(TENSORFLOW_FOUND_BY "NOTFOUND")
set(tensorflow_ros_cpp_INCLUDE_DIRS "")
set(tensorflow_ros_cpp_LIBRARIES "")
set(tensorflow_ros_cpp_DEPENDS "")
set(tensorflow_ros_cpp_CATKIN_DEPENDS "")
set(tensorflow_ros_cpp_TARGETS "")
set(tensorflow_ros_cpp_USES_CXX11_ABI ${SYSTEM_USES_CXX11_ABI})
# 1. PIP
if(((NOT ${SYSTEM_USES_CXX11_ABI} AND "${TF_LIBRARY_VERSION}" STREQUAL "1") OR (${SYSTEM_USES_CXX11_ABI} AND "${TF_LIBRARY_VERSION}" STREQUAL "2") OR ${FORCE_TF_PIP_SEARCH}) AND NOT ${DISABLE_TF_PIP_SEARCH})
message("-- - Trying to find Tensorflow installed by pip")
include(cmake/detect_tf_pip.cmake)
else()
if(${DISABLE_TF_PIP_SEARCH})
message("-- - Not searching for Tensorflow installed by pip, it is disabled.")
elseif("${TF_LIBRARY_VERSION}" STREQUAL "1")
message("-- - Not searching for Tensorflow installed by pip since the system uses C++11 ABI. Set FORCE_TF_PIP_SEARCH to force the search.")
else()
message("-- - Not searching for Tensorflow installed by pip since the system does not use C++11 ABI. Set FORCE_TF_PIP_SEARCH to force the search.")
endif()
endif()
# 2. Bazel
if((NOT ${TENSORFLOW_FOUND} OR ${FORCE_TF_BAZEL_SEARCH}) AND NOT ${DISABLE_TF_BAZEL_SEARCH})
message("-- - Trying to find Tensorflow compiled by bazel")
include(cmake/detect_tf_bazel.cmake)
else()
if(${DISABLE_TF_BAZEL_SEARCH})
message("-- - Not searching for Tensorflow compiled by bazel, it is disabled.")
else()
message("-- - Not searching for Tensorflow compiled by bazel since Tensorflow has already been found. Set FORCE_TF_BAZEL_SEARCH to force the search.")
endif()
endif()
# 3. tensorflow_catkin
if((NOT ${TENSORFLOW_FOUND} OR ${FORCE_TF_CATKIN_SEARCH}) AND NOT ${DISABLE_TF_CATKIN_SEARCH})
message("-- - Trying to find Tensorflow from tensorflow_catkin")
include(cmake/detect_tf_catkin.cmake)
else()
if(${DISABLE_TF_CATKIN_SEARCH})
message("-- - Not searching for Tensorflow from tensorflow_catkin, it is disabled.")
else()
message("-- - Not searching for Tensorflow from tensorflow_catkin since Tensorflow has already been found. Set FORCE_TF_CATKIN_SEARCH to force the search.")
endif()
endif()
if(NOT ${TENSORFLOW_FOUND})
message(FATAL_ERROR "Tensorflow was not found")
else()
message("-- Using Tensorflow library found by ${TENSORFLOW_FOUND_BY}")
endif()
if(${tensorflow_ros_cpp_USES_CXX11_ABI})
message("-- The found Tensorflow library uses C++11 ABI.")
else()
message("-- The found Tensorflow library uses C++03 ABI.")
endif()
if(${HAS_TENSORFLOW_GPU})
message("-- The found Tensorflow library is compiled with CUDA support.")
else()
message("-- The found Tensorflow library is compiled without CUDA support.")
endif()
set(tensorflow_ros_cpp_CMAKE_CXX_FLAGS_PRIVATE "-D_GLIBCXX_USE_CXX11_ABI=${tensorflow_ros_cpp_USES_CXX11_ABI} -DTF_LIBRARY_VERSION=${TF_LIBRARY_VERSION}")
catkin_package(
INCLUDE_DIRS ${tensorflow_ros_cpp_INCLUDE_DIRS}
LIBRARIES ${tensorflow_ros_cpp_LIBRARIES}
DEPENDS ${tensorflow_ros_cpp_DEPENDS}
CATKIN_DEPENDS ${tensorflow_ros_cpp_CATKIN_DEPENDS}
CFG_EXTRAS tensorflow-extras.cmake # to add the c++11 compiler flag
)
add_custom_target(run ALL DEPENDS ${TENSORFLOW_TARGETS})
install(
FILES ${TENSORFLOW_TARGETS}
DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)