CMakeLists.txt
cmake_minimum_required(VERSION 3.1) project(openvslam LANGUAGES CXX C) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(POLICY CMP0042) cmake_policy(SET CMP0042 NEW) endif() if(POLICY CMP0074) cmake_policy(SET CMP0074 OLD) endif() list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) # digging into the root directory of OpenVSLAM get_filename_component(DEFAULT_OpenVSLAM_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) get_filename_component(DEFAULT_OpenVSLAM_DIR ${DEFAULT_OpenVSLAM_DIR} DIRECTORY) get_filename_component(DEFAULT_OpenVSLAM_DIR ${DEFAULT_OpenVSLAM_DIR} DIRECTORY) set(OpenVSLAM_ROOT ${DEFAULT_OpenVSLAM_DIR} CACHE STRING "Root directory of OpenVSLAM") message(STATUS "Root directory of OpenVSLAM: ${OpenVSLAM_ROOT}") set(OpenVSLAM_SRC_DIR ${OpenVSLAM_ROOT}/src) message(STATUS "Source directory of OpenVSLAM: ${OpenVSLAM_SRC_DIR}") set(OpenVSLAM_LIB_DIR ${OpenVSLAM_ROOT}/build/lib CACHE STRING "Directory which contains the shared library of OpenVSLAM") message(STATUS "Library directory of OpenVSLAM: ${OpenVSLAM_LIB_DIR}") include_directories( ${catkin_INCLUDE_DIRS} ${OpenVSLAM_SRC_DIR}) link_libraries( ${catkin_LIBRARIES} ${OpenVSLAM_LIB}) # ----- Set build type ----- if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Release") set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") # ----- Set options for debugging ----- set(USE_CCACHE ON CACHE BOOL "Use ccache to accelerate build") find_program(CCACHE_EXE ccache) if(USE_CCACHE AND CCACHE_EXE) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_EXE}") set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_EXE}") message(STATUS "ccache: Enabled") else() set(USE_CCACHE OFF) message(STATUS "ccache: Disabled") endif() set(USE_SANITIZER OFF CACHE BOOL "Enable Address/Memory sanitizer (set env as ASAN_OPTIONS=detect_leaks=1)") if(USE_SANITIZER) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address") message(STATUS "Address/Memory sanitizer: ENABLED") else() message(STATUS "Address/Memory sanitizer: DISABLED") endif() # ----- Set compiler options ----- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -ffast-math") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -ffast-math") set(BUILD_WITH_MARCH_NATIVE OFF CACHE BOOL "Enable architecture-aware optimization (-march=native)") if(BUILD_WITH_MARCH_NATIVE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native -march=native") set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -mtune=native -march=native") message(STATUS "Architecture-aware optimization (-march=native): ENABLED") else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native") set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -mtune=native") message(STATUS "Architecture-aware optimization (-march=native): DISABLED") endif() # ----- Find dependencies ----- find_package(catkin REQUIRED COMPONENTS roscpp geometry_msgs sensor_msgs cv_bridge message_filters # 消息同步 image_transport ) find_package(Boost REQUIRED COMPONENTS filesystem) # Threads find_package(Threads REQUIRED) # Eigen find_package(Eigen3 3.3 REQUIRED) # yaml-cpp find_package(yaml-cpp REQUIRED) #设置opencv安装路径 set(CMAKE_PREFIX_PATH "/home/r9000k/v1_software/opencv/opencv455/install") #find_package(OpenCV REQUIRED) #include_directories(${OpenCV_INCLUDE_DIRS}) find_package(OpenCV REQUIRED) # OpenCV message(STATUS "Use OpenCV ${OpenCV_VERSION}") catkin_package( CATKIN_DEPENDS roscpp geometry_msgs sensor_msgs cv_bridge DEPENDS Boost ) # ----- Install configuration ----- include(CMakePackageConfigHelpers) # ----- Build selection ----- set(USE_PANGOLIN_VIEWER ON CACHE BOOL "Enable Pangolin Viewer") set(USE_SOCKET_PUBLISHER OFF CACHE BOOL "Enable Socket Publisher") # ----- Find dependencies ----- include_directories( ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} "/usr/local/include/eigen3" ) # popl set(popl_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/3rd/popl/include) set(USE_STACK_TRACE_LOGGER OFF CACHE BOOL "Enable automatic stack trace logger of google-glog") if(USE_STACK_TRACE_LOGGER) find_package(Glog REQUIRED) include_directories(${GLOG_INCLUDE_DIR}) message(STATUS "Stack trace logger: ENABLED") else() message(STATUS "Stack trace logger: DISABLED") endif() set(USE_GOOGLE_PERFTOOLS OFF CACHE BOOL "Enable profiler of google-perftools") if(USE_GOOGLE_PERFTOOLS) find_package(Gperftools REQUIRED) include_directories(${GPERFTOOLS_INCLUDE_DIRS}) message(STATUS "Google Perftools: ENABLED") else() message(STATUS "Google Perftools: DISABLED") endif() # ----- Show dialog ----- if(USE_PANGOLIN_VIEWER) message(STATUS "Viewer for examples: PangolinViewer") elseif(USE_SOCKET_PUBLISHER) message(STATUS "Viewer for examples: SocketPublisher") else() message(STATUS "Viewer for examples: None") endif() # ----- Build example executables ----- set(EXECUTABLE_TARGETS "") add_executable(run_image_slam src/run_image_slam.cc) list(APPEND EXECUTABLE_TARGETS run_image_slam) target_link_libraries(run_image_slam PRIVATE ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${Boost_LIBRARIES} ) foreach(EXECUTABLE_TARGET IN LISTS EXECUTABLE_TARGETS) # Set output directory for executables set_target_properties(${EXECUTABLE_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}" RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}" RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${PROJECT_BINARY_DIR}" RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${PROJECT_BINARY_DIR}") # PangolinViewer is used on a priority basis if(USE_PANGOLIN_VIEWER) # Set macro flag target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE USE_PANGOLIN_VIEWER) # Link viewer target_link_libraries(${EXECUTABLE_TARGET} PRIVATE pangolin_viewer) elseif(USE_SOCKET_PUBLISHER) # Set macro flag target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE USE_SOCKET_PUBLISHER) # Link viewer target_link_libraries(${EXECUTABLE_TARGET} PRIVATE socket_publisher) endif() # Setup stack trace logger if(USE_STACK_TRACE_LOGGER) target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE USE_STACK_TRACE_LOGGER) target_link_libraries(${EXECUTABLE_TARGET} PRIVATE ${GLOG_LIBRARIES}) endif() # Setup google-perftools if(USE_GOOGLE_PERFTOOLS) target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE USE_GOOGLE_PERFTOOLS) target_link_libraries(${EXECUTABLE_TARGET} PRIVATE ${GPERFTOOLS_LIBRARIES}) endif() # Link OpenVSLAM target_link_libraries(${EXECUTABLE_TARGET} PRIVATE ${PROJECT_NAME} opencv_imgcodecs opencv_videoio) # include popl and spdlog headers target_include_directories(${EXECUTABLE_TARGET} PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/3rd/popl/include> $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/3rd/spdlog/include>) endforeach()
标签:USE,set,CMAKE,openvslam,OpenVSLAM,FLAGS,ros,DIR From: https://www.cnblogs.com/gooutlook/p/18393215