-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
266 lines (209 loc) · 10.2 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# cmake_minimum_required(VERSION 2.8 FATAL_ERROR) # we need at least 3.11 because we use the FetchContent feature to manage dependencies and at least 3.14 because we use FetchContent_MakeAvailable
cmake_minimum_required(VERSION 2.8...3.22)
project(data_loaders)
### VARIABLES ##############################################################
set(CMAKE_BUILD_TYPE RelWithDebInfo)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -Wall -O3 -Wno-reorder") #we need c++17 because this solves alignment issues with eigen http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1409
set(CMAKE_CXX_STANDARD 17) #we need c++17 because this solves alignment issues with eigen http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1409
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# libigl
# libigl options: choose between header only and compiled static library
# Header-only is preferred for small projects. For larger projects the static build
# considerably reduces the compilation times
option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF)
option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF)
option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
option(LIBIGL_WITH_COMISO "Use CoMiso" OFF)
option(LIBIGL_WITH_CORK "Use Cork" OFF)
option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
option(LIBIGL_WITH_LIM "Use LIM" OFF)
option(LIBIGL_WITH_MATLAB "Use Matlab" OFF)
option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF)
option(LIBIGL_WITH_OPENGL "Use OpenGL" OFF)
option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" OFF)
option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" OFF)
option(LIBIGL_WITH_PNG "Use PNG" OFF)
option(LIBIGL_WITH_PYTHON "Use Python" OFF)
option(LIBIGL_WITH_TETGEN "Use Tetgen" OFF)
option(LIBIGL_WITH_TRIANGLE "Use Triangle" OFF)
option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" OFF)
option(LIBIGL_WITH_XML "Use XML" OFF)
# set(PYTHON_VERSION 3.6 CACHE STRING "" FORCE)
# #pybind package
# #setting a python version to 3.6 for pybind so that the bindings work in 3.6 https://github.com/pybind/pybind11/issues/748
# unset(PYTHONINTERP_FOUND CACHE)
# unset(PYTHON_EXECUTABLE CACHE)
# unset(PYTHON_VERSION_STRING CACHE)
# unset(PYTHON_VERSION_MAJOR CACHE)
# unset(PYTHON_VERSION_MINOR CACHE)
# unset(PYTHON_VERSION_PATCH CACHE)
# unset(PYBIND11_INCLUDE_DIR CACHE)
# unset(PYTHON_INCLUDE_DIRS CACHE)
# unset(PYTHON_LIBRARIES CACHE)
# unset(PYTHON_MODULE_PREFIX CACHE)
# unset(PYTHON_MODULE_EXTENSION CACHE)
# unset(PYTHON_LIBRARY CACHE)
# set(PYBIND11_PYTHON_VERSION 3.6 CACHE STRING "" FORCE)
# message("PYBIND11_PYTHON_VERSION is" , ${PYBIND11_PYTHON_VERSION})
#### GLOBAL OPTIONS ###https://stackoverflow.com/questions/15201064/cmake-conditional-preprocessor-define-on-code
###### PACKAGES ############################################################
find_package(catkin QUIET)
set(catkin_FOUND 0 )
message("catkin found is ${catkin_FOUND}" )
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
find_package(OpenCV REQUIRED)
find_package(LIBIGL REQUIRED)
find_package(EasyPBR REQUIRED)
# add_subdirectory(${PROJECT_SOURCE_DIR}/deps/pybind11)
if(${catkin_FOUND})
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs cv_bridge pcl_ros image_transport tf2_ros tf2_eigen)
endif()
#try to compile with pytorch if you can
# set(PYTORCH_PATH "/opt/pytorch")
# set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ";${PYTORCH_PATH};")
# get and append paths for finding dep
execute_process( #do it like this https://github.com/facebookresearch/hanabi_SAD/blob/6e4ed590f5912fcb99633f4c224778a3ba78879b/rela/CMakeLists.txt#L10
COMMAND python -c "import torch; import os; print(os.path.dirname(torch.__file__), end='')"
OUTPUT_VARIABLE TorchPath
)
#sometimes we want to use libtorch because the pytorch one has a different abi
# set(TorchPath "/home/rosu/work/ws/libtorch-cxx11-abi-shared-with-deps-1.9.0+cu111/libtorch")
# set(TorchPath "/home/rosu/work/ws/libtorch-cxx11-abi-shared-with-deps-1.9.1+cu111/libtorch")
# message("TORCH path-------------------", ${TorchPath})
if(TorchPath STREQUAL "")
set(TORCH_FOUND False)
else()
list(APPEND CMAKE_PREFIX_PATH ${TorchPath})
find_package(Torch)
endif()
# set(TORCH_FOUND False)
add_subdirectory( ${EASYPBR_SRC_PATH}/deps/pybind11 ./../../build/pybind11 EXCLUDE_FROM_ALL)
#pybind attempt 3
pybind11_add_module(dataloaders ${PROJECT_SOURCE_DIR}/src/PyBridge.cxx )
add_subdirectory(${PROJECT_SOURCE_DIR}/deps/yaml-cpp)
### INCLUDES #########################################################
include_directories(${catkin_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/deps)
include_directories(${CMAKE_SOURCE_DIR}/deps/cnpy)
include_directories(${CMAKE_SOURCE_DIR}/deps/libigl/include)
include_directories(${CMAKE_SOURCE_DIR}/extern)
include_directories(${CMAKE_SOURCE_DIR}/deps/yaml-cpp/include )
# include_directories(${CMAKE_SOURCE_DIR}/deps/pybind11/include)
include_directories(${EIGEN3_INCLUDE_DIR})
include_directories(${EASYPBR_INCLUDE_DIR})
if(${TORCH_FOUND})
include_directories(${TORCH_INCLUDE_DIRS})
endif()
if(${catkin_FOUND})
catkin_package( INCLUDE_DIRS include CATKIN_DEPENDS roscpp std_msgs cv_bridge pcl_ros image_transport tf2_ros tf2_eigen )
endif()
### SOURCES #################################################################
set(MY_SRC
# ${PROJECT_SOURCE_DIR}/src/Frame.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderVolRef.cxx
# ${PROJECT_SOURCE_DIR}/src/DataLoaderImgRos.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderScanNet.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderShapeNetPartSeg.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderShapeNetImg.cxx
${PROJECT_SOURCE_DIR}/src/DataTransformer.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderSemanticKitti.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderPheno4D.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderPhenorobCP1.cxx
# ${PROJECT_SOURCE_DIR}/src/DataLoaderStanfordIndoor.cxx
# ${PROJECT_SOURCE_DIR}/src/DataLoaderToyExample.cxx
# ${PROJECT_SOURCE_DIR}/src/DataLoaderCloudRos.cxx
# ${PROJECT_SOURCE_DIR}/src/DataLoaderRueMonge.cxx
# ${PROJECT_SOURCE_DIR}/src/RosBagPlayer.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderImg.cxx
# ${PROJECT_SOURCE_DIR}/src/DataLoaderModelNet40.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderStanford3DScene.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderNerf.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderEasyPBR.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderColmap.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderSRN.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderDTU.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderDeepVoxels.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderLLFF.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderMultiFace.cxx
${PROJECT_SOURCE_DIR}/src/MiscDataFuncs.cxx
#fb
${PROJECT_SOURCE_DIR}/src/fb/DataLoaderBlenderFB.cxx
)
if(${TORCH_FOUND})
set(MY_SRC ${MY_SRC}
${PROJECT_SOURCE_DIR}/src/fb/DataLoaderUSCHair.cxx
)
endif()
set(DEPS_SRC
${PROJECT_SOURCE_DIR}/deps/json11/json11.cpp
${PROJECT_SOURCE_DIR}/deps/cnpy/cnpy.cpp
# ${PROJECT_SOURCE_DIR}/extern/pybind_casters/ndarray_converter.cpp
)
if (${catkin_FOUND} )
set(MY_SRC ${MY_SRC}
${PROJECT_SOURCE_DIR}/src/DataLoaderImgRos.cxx
${PROJECT_SOURCE_DIR}/src/DataLoaderCloudRos.cxx
${PROJECT_SOURCE_DIR}/src/RosBagPlayer.cxx
)
endif()
#loaders that require torch
if(${TORCH_FOUND})
set(MY_SRC ${MY_SRC}
${PROJECT_SOURCE_DIR}/src/fb/DataLoaderUSCHair.cxx
${PROJECT_SOURCE_DIR}/src/TensorReel.cxx
)
endif()
#disable warnings for yaml-cpp and cnpy
set_source_files_properties(
${PROJECT_SOURCE_DIR}/deps/cnpy/cnpy.cpp
PROPERTIES
COMPILE_FLAGS "-w"
)
set_target_properties(yaml-cpp PROPERTIES COMPILE_FLAGS "-w")
### SET ALL THE GLOBAL OPTIONS #########################################
if(${catkin_FOUND})
message("USING ROS")
add_definitions(-DWITH_ROS)
else()
message("NOT USING ROS")
endif()
#lib
add_library( dataloaders_cpp SHARED ${MY_SRC} ${DEPS_SRC} )
if(${TORCH_FOUND})
message("USING TORCH")
target_compile_definitions(dataloaders_cpp PUBLIC WITH_TORCH)
else()
message("NOT USING TORCH")
endif()
##pybind
# pybind11_add_module(dataloaders ${PROJECT_SOURCE_DIR}/src/PyBridge.cxx )
### EXECUTABLE #######################################
# add_executable(run_data_loaders ${PROJECT_SOURCE_DIR}/src/main.cxx )
### LIBS ###############################################
# message("easypbr lib is ", ${EASYPBR_LIBRARY})
set(LIBS ${LIBS} igl::core ${catkin_LIBRARIES} ${EASYPBR_LIBRARY} ${OpenCV_LIBS} yaml-cpp )
if(${TORCH_FOUND})
set(LIBS ${LIBS} ${TORCH_LIBRARIES} )
#torch 1.5.0 and above mess with pybind and we therefore need to link against libtorch_python.so also
find_library(TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib")
message(STATUS "TORCH_PYTHON_LIBRARY: ${TORCH_PYTHON_LIBRARY}")
if(TORCH_PYTHON_LIBRARY)
message(STATUS "Linking to torch_python_library")
set(LIBS ${LIBS} ${TORCH_PYTHON_LIBRARY} )
endif()
endif()
### TINY PROCESS LIBRARY #########################################
set (TINY_PROCESS_LIB_SOURCES ${CMAKE_SOURCE_DIR}/deps/tiny-process-library/process.cpp ${CMAKE_SOURCE_DIR}/deps/tiny-process-library/process_unix.cpp )
add_library( TINY_PROCESS_LIB ${TINY_PROCESS_LIB_SOURCES} )
target_link_libraries(TINY_PROCESS_LIB ${CMAKE_THREAD_LIBS_INIT})
set_target_properties(TINY_PROCESS_LIB PROPERTIES LINKER_LANGUAGE C)
set(LIBS ${LIBS} TINY_PROCESS_LIB)
target_link_libraries(dataloaders_cpp ${LIBS} )
target_link_libraries(dataloaders PRIVATE dataloaders_cpp )
# target_link_libraries(run_data_loaders PRIVATE data_loaders_cpp )
#definitions for cmake variables that are necesarry during runtime
target_compile_definitions(dataloaders_cpp PRIVATE PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}") #point to the cmakelist folder of the easy_pbr
target_compile_definitions(dataloaders_cpp PRIVATE CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}") # points to the CMakeList folder of whichever project included easy_pbr