|
| 1 | +cmake_minimum_required(VERSION 3.0) |
| 2 | +project(hybvio VERSION 1.0.0 DESCRIPTION "HybVIO VIO/SLAM runner") |
| 3 | + |
| 4 | +set(CMAKE_CXX_STANDARD 14) |
| 5 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -O2") |
| 6 | +# allow building a single shared library (adds -fPIC when compiling static libs) |
| 7 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 8 | +# Generate `compile_commands.json` for `clang-tidy`. |
| 9 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 10 | + |
| 11 | +option(FIND_BLAS "Force -DEIGEN_USE_BLAS." OFF) |
| 12 | +option(MARCH_NATIVE "Enable -march=native." OFF) |
| 13 | +if (MARCH_NATIVE) |
| 14 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") |
| 15 | +endif() |
| 16 | + |
| 17 | +if (NOT CMAKE_BUILD_TYPE) |
| 18 | + # TODO: setting this to RelWithDebInfo should be used for optimization flags |
| 19 | + # However: that seems to result to crashes for unknown reasons |
| 20 | + set(CMAKE_BUILD_TYPE Debug) |
| 21 | +endif() |
| 22 | + |
| 23 | +set(BUILD_CLI_TOOLS ON CACHE STRING "Build `main` binaries and tests.") |
| 24 | +set(LOGGING_ENABLED ON CACHE STRING "Enable logging") |
| 25 | + |
| 26 | +set(BUILD_WITH_GPU ON CACHE STRING "Build with GPU (OpenGL) support") |
| 27 | + |
| 28 | +set(BUILD_WITH_GLFW ON CACHE STRING "Support headless GPU processing on desktop with GLFW") |
| 29 | +set(BUILD_VISUALIZATIONS OFF CACHE STRING "Build Pangolin-based visualizations") |
| 30 | +set(LOGGING_LIBS "") |
| 31 | +if(BUILD_CLI_TOOLS AND LOGGING_ENABLED) |
| 32 | + add_definitions(-DUSE_LOGURU) |
| 33 | +endif() |
| 34 | +if(LOGGING_ENABLED) |
| 35 | + add_definitions(-DLOGGING_ENABLED) |
| 36 | +endif() |
| 37 | + |
| 38 | + |
| 39 | +# Make sure no Eigen LGPL code is used. It's mostly stuff like sparse matrix |
| 40 | +# operations that we would not want to use through Eigen in any case |
| 41 | +add_definitions("-DEIGEN_MPL2_ONLY") |
| 42 | + |
| 43 | +# Do not auto-parallelize matrix products (mainly affects the Odometry class) |
| 44 | +# Note that the odometry module may be faster without this flag, if also using |
| 45 | +# OpenMP, but then it may hog 100% CPU (on all cores) |
| 46 | +# from time to time, which is not what we're looking for. This may not have |
| 47 | +# an effect unless Eigen is configured to use OpenMP |
| 48 | +add_definitions("-DEIGEN_DONT_PARALLELIZE") |
| 49 | + |
| 50 | +# Note: try these too for debugging. For example, NaN initialization should |
| 51 | +# not affect the results if everything is implemented correctly. |
| 52 | +#add_definitions("-DEIGEN_INITIALIZE_MATRICES_BY_NAN") |
| 53 | +#add_definitions("-DEIGEN_NO_AUTOMATIC_RESIZING") |
| 54 | + |
| 55 | +if (FIND_BLAS) |
| 56 | + # Use Accelerate framework on Mac or system BLAS on Linux for Eigen. |
| 57 | + # This may or may not be faster than without BLAS. Similarly to the OpenMP |
| 58 | + # stuff in Eigen (disabled with EIGEN_DONT_PARALLELIZE), this can cause |
| 59 | + # CPU hogging on multiple-threads and the end result may not be optimal. |
| 60 | + find_package(BLAS REQUIRED) |
| 61 | + if(BLAS_FOUND) |
| 62 | + message(STATUS "using BLAS with Eigen") |
| 63 | + add_definitions("-DEIGEN_USE_BLAS") |
| 64 | + list(APPEND LIBS "${BLAS_LIBRARIES}") # appends "-framework Accelerate" |
| 65 | + endif() |
| 66 | +endif() |
| 67 | + |
| 68 | +option(USE_SLAM "Compile with SLAM support" OFF) |
| 69 | +set(TARGET_ARCH "host" CACHE STRING "Target architecture") |
| 70 | +find_package(mobile-cv-suite REQUIRED PATHS 3rdparty/mobile-cv-suite) |
| 71 | + |
| 72 | +add_subdirectory("codegen") |
| 73 | +foreach(X ${generated_sources}) |
| 74 | + message(STATUS "marking ${X} as a generated source file") |
| 75 | + set_source_files_properties(${X} PROPERTIES GENERATED TRUE) |
| 76 | +endforeach() |
| 77 | + |
| 78 | +add_library(parameters |
| 79 | + codegen/output/parameters.cpp |
| 80 | + src/util/util.cpp |
| 81 | + src/util/parameter_parser.cpp |
| 82 | + codegen/output/cmd_parameters.cpp |
| 83 | + src/util/util.cpp |
| 84 | + src/util/timer.cpp |
| 85 | + src/util/parameter_parser.cpp) |
| 86 | +add_dependencies(parameters generated_parameters cmd_generated_parameters) |
| 87 | +target_link_libraries(parameters mobile-cv-suite::core) |
| 88 | + |
| 89 | +if (BUILD_WITH_GPU) |
| 90 | + add_definitions(-DDAZZLING_GPU_ENABLED) |
| 91 | + if (BUILD_WITH_GLFW) |
| 92 | + add_definitions(-DDAZZLING_GLFW_ENABLED) |
| 93 | + find_package(glfw3 REQUIRED) |
| 94 | + list(APPEND LIBS glfw) |
| 95 | + endif() |
| 96 | + find_package(OpenGL REQUIRED) # can't find GL ES :( |
| 97 | + list(APPEND LIBS ${OPENGL_LIBRARIES}) |
| 98 | +endif() |
| 99 | + |
| 100 | +# This causes the targets in feature-tracking/CMakeList.txt to be available |
| 101 | +# here without including the individual source files |
| 102 | +add_subdirectory("src/tracker") |
| 103 | + |
| 104 | +if (USE_SLAM) |
| 105 | + # add SLAM |
| 106 | + add_subdirectory("src/slam") |
| 107 | +else() |
| 108 | + add_library(slam src/util/slam_noop.cpp) |
| 109 | + target_link_libraries(slam mobile-cv-suite::core) # Required for Eigen includes |
| 110 | +endif() |
| 111 | + |
| 112 | +# Static library that main program and tests can link to. |
| 113 | +add_library(odometry |
| 114 | + src/odometry/control.cpp |
| 115 | + src/odometry/ekf.cpp |
| 116 | + src/odometry/triangulation.cpp |
| 117 | + src/odometry/util.cpp |
| 118 | + src/odometry/sample_sync.cpp |
| 119 | + src/odometry/ekf_state_index.cpp |
| 120 | + src/odometry/backend.cpp |
| 121 | + src/odometry/output.cpp |
| 122 | + src/views/api_visualization_helpers.cpp |
| 123 | + src/views/visualization_pose.cpp |
| 124 | + src/views/visualization_internals.cpp |
| 125 | + src/api/visualizations.cpp |
| 126 | + src/api/api.cpp |
| 127 | + src/util/util.cpp |
| 128 | + src/api/type_convert.cpp |
| 129 | + ) |
| 130 | + |
| 131 | +target_link_libraries(odometry slam tracker ${LIBS} mobile-cv-suite::core) |
| 132 | +target_include_directories(odometry PUBLIC ".") |
| 133 | + |
| 134 | +if(BUILD_CLI_TOOLS) |
| 135 | + if (BUILD_VISUALIZATIONS) |
| 136 | + add_definitions(-DBUILD_VISUALIZATIONS) |
| 137 | + set(VISU_SRCS |
| 138 | + src/commandline/visual_update_viewer.cpp |
| 139 | + src/commandline/draw_gl.cpp) |
| 140 | + set(VISU_LIBS |
| 141 | + Threads::Threads |
| 142 | + parameters |
| 143 | + ${LOGGING_LIBS} |
| 144 | + mobile-cv-suite::visualization |
| 145 | + ${OPENGL_LIBRARIES}) |
| 146 | + else() |
| 147 | + set(VISU_SRCS "") |
| 148 | + set(VISU_LIBS "") |
| 149 | + endif() |
| 150 | + if(USE_SLAM) |
| 151 | + add_definitions(-DUSE_DBOW2) |
| 152 | + add_definitions(-DUSE_SLAM) |
| 153 | + |
| 154 | + set(SLAM_SRCS "") |
| 155 | + set(SLAM_LIBS |
| 156 | + Threads::Threads |
| 157 | + parameters |
| 158 | + mobile-cv-suite::slam) |
| 159 | + |
| 160 | + # Select newer OpenGL, see `cmake --help-policy CMP0072` |
| 161 | + # cmake_policy(SET CMP0072 NEW) # TODO what CMake version does this require? |
| 162 | + |
| 163 | + find_package(Threads REQUIRED) |
| 164 | + else() |
| 165 | + set(SLAM_LIBS "") |
| 166 | + set(SLAM_SRCS "") |
| 167 | + endif() |
| 168 | + |
| 169 | + add_executable(main |
| 170 | + src/commandline/command_queue.cpp |
| 171 | + src/commandline/input.cpp |
| 172 | + src/commandline/input_csv.cpp |
| 173 | + src/commandline/input_jsonl.cpp |
| 174 | + src/commandline/main.cpp |
| 175 | + src/commandline/video_input.cpp |
| 176 | + src/commandline/videoutil.cpp |
| 177 | + ${VISU_SRCS} |
| 178 | + ${SLAM_SRCS}) |
| 179 | + target_link_libraries(main PRIVATE odometry parameters ${LIBS} ${VISU_LIBS} ${SLAM_LIBS}) |
| 180 | + |
| 181 | + # Put binaries from subdirectories (test) to the target directory. |
| 182 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) |
| 183 | + |
| 184 | + # Copy test data to the target directory so that we can simply run the test binary. |
| 185 | + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test) |
| 186 | + |
| 187 | + # Lets `make test` and `ctest` commands run tests. |
| 188 | + enable_testing() |
| 189 | + |
| 190 | + list(APPEND LIBS mobile-cv-suite::core) # applies to run-tests |
| 191 | + add_subdirectory(test) |
| 192 | +endif() |
0 commit comments