Windows11+VS2019+Open3D_0.18.0 编译配置记录

17 篇文章 2 订阅
14 篇文章 1 订阅

在C++处理三维数据时,想可视化三维点云便于调试分析,鉴于Python上的Open3D用着很舒适,所以尝试进行C++的Open3D配置(若无特别说明均在Release x64平台下配置测试)


查阅官方文档

CMake 安装

如果设备上没有cmake需要先下载安装一个cmake,我用的cmake-3.30.2-windows-x86_64.msi

在这里插入图片描述
运行安装程序,一直Next,老规矩按个人习惯安装在D盘
在这里插入图片描述

若出现如下报错,打开任务管理器结束所有安装程序重新安装

在这里插入图片描述


Open3D 编译

1. clone Open3D仓库

git clone https://github.com/isl-org/Open3D

2. 进行 CMake

这里我选择打开CMake GUI进行配置
设置路径如下
在这里插入图片描述
点击Configure,出现如下提示,选择生成器和平台
在这里插入图片描述
第一次 Configure 会失败,因为它默认打开了BULD_PYTHON_MODULE但还没有指定PYTHON3路径,点击 GroupedBUILD组下除了BULD_EXAMPLESBUILD_GUI,其它关闭,并在CMAKE组下更改安装目录为 D:\Program Files\Open3D

在这里插入图片描述

在这里插入图片描述
重新Configure并进行Generate

在这里插入图片描述

整个过程略有曲折,重新cmake了两次,最终通过的CMakeLists.txt如下

cmake_minimum_required(VERSION 3.22)
# If you're using Ubuntu 18.04, we suggest you install the latest CMake from the
# official repository https://apt.kitware.com/.
# CMake 3.22+ is required by Assimp v5.4.2
# CMake 3.20+ is required to detect IntelLLVM compiler for SYCL

# CMAKE_HOST_SYSTEM_PROCESSOR is only available after calling project(),
# which depends on ${OPEN3D_VERSION}, which depends on ${DEVELOPER_BUILD}.
if(UNIX AND NOT APPLE)
    execute_process(COMMAND uname -m
        OUTPUT_VARIABLE PROCESSOR_ARCH
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    if(PROCESSOR_ARCH STREQUAL "aarch64")
        set(LINUX_AARCH64 TRUE)
    endif()
endif()
if(APPLE)
    execute_process(COMMAND uname -m
        OUTPUT_VARIABLE PROCESSOR_ARCH
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    if(PROCESSOR_ARCH STREQUAL "arm64")
        set(APPLE_AARCH64 TRUE)
        set (CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING
            "Minimum OS X deployment version" FORCE)
    else()
        set (CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING
            "Minimum OS X deployment version" FORCE)
    endif()
endif()

include(CMakeDependentOption)

# Open3D build options
option(BUILD_SHARED_LIBS          "Build shared libraries"                   OFF)
option(BUILD_EXAMPLES             "Build Open3D examples programs"           ON )
option(BUILD_UNIT_TESTS           "Build Open3D unit tests"                  OFF)
option(BUILD_BENCHMARKS           "Build the micro benchmarks"               OFF)
option(BUILD_PYTHON_MODULE        "Build the python module"                  ON )
option(BUILD_CUDA_MODULE          "Build the CUDA module"                    OFF)
option(BUILD_WITH_CUDA_STATIC     "Build with static CUDA libraries"         ON )
option(BUILD_COMMON_CUDA_ARCHS    "Build for common CUDA GPUs (for release)" OFF)
if (WIN32)   # Causes CUDA runtime error on Windows (See issue #6555)
    option(ENABLE_CACHED_CUDA_MANAGER "Enable cached CUDA memory manager"    OFF)
else()
    option(ENABLE_CACHED_CUDA_MANAGER "Enable cached CUDA memory manager"    ON )
endif()
if(NOT LINUX_AARCH64 AND NOT APPLE_AARCH64)
    option(BUILD_ISPC_MODULE      "Build the ISPC module"                    ON )
else()
    option(BUILD_ISPC_MODULE      "Build the ISPC module"                    OFF)
endif()
option(BUILD_COMMON_ISPC_ISAS     "Build for common ISPC ISAs (for release)" OFF)
option(BUILD_GUI                  "Builds new GUI"                           ON )
option(WITH_OPENMP                "Use OpenMP multi-threading"               ON )
option(WITH_IPPICV                "Use Intel Performance Primitives"         ON )
option(ENABLE_HEADLESS_RENDERING  "Use OSMesa for headless rendering"        OFF)
if(BUILD_SHARED_LIBS)
    option(STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime"      OFF)
else()
    option(STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime"      ON )
endif()
option(BUILD_SYCL_MODULE          "Build SYCL module with Intel oneAPI"      OFF)
option(GLIBCXX_USE_CXX11_ABI      "Set -D_GLIBCXX_USE_CXX11_ABI=1"           ON )
option(ENABLE_SYCL_UNIFIED_SHARED_MEMORY "Enable SYCL unified shared memory" OFF)
if(BUILD_GUI AND (WIN32 OR UNIX AND NOT LINUX_AARCH64 AND NOT APPLE_AARCH64))
    option(BUILD_WEBRTC           "Build WebRTC visualizer"                  ON )
else()
    option(BUILD_WEBRTC           "Build WebRTC visualizer"                  OFF)
endif()
option(BUILD_JUPYTER_EXTENSION    "Build Jupyter, requires BUILD_WEBRTC=ON"  OFF)

# 3rd-party build options
if(LINUX_AARCH64 OR APPLE_AARCH64)
    option(USE_BLAS               "Use BLAS/LAPACK instead of MKL"           ON )
else()
    option(USE_BLAS               "Use BLAS/LAPACK instead of MKL"           OFF)
endif()
if(USE_BLAS)
    option(USE_SYSTEM_BLAS        "Use system pre-installed openblas"        OFF)
else()
    option(USE_SYSTEM_BLAS        "Use system pre-installed openblas"        ON )
endif()
option(USE_SYSTEM_ASSIMP          "Use system pre-installed assimp"          OFF)
option(USE_SYSTEM_CURL            "Use system pre-installed curl"            OFF)
option(USE_SYSTEM_CUTLASS         "Use system pre-installed cutlass"         OFF)
option(USE_SYSTEM_EIGEN3          "Use system pre-installed eigen3"          OFF)
option(USE_SYSTEM_EMBREE          "Use system pre-installed Embree"          OFF)
option(USE_SYSTEM_FILAMENT        "Use system pre-installed filament"        OFF)
option(USE_SYSTEM_FMT             "Use system pre-installed fmt"             OFF)
option(USE_SYSTEM_GLEW            "Use system pre-installed glew"            OFF)
option(USE_SYSTEM_GLFW            "Use system pre-installed glfw"            OFF)
option(USE_SYSTEM_GOOGLETEST      "Use system pre-installed Googletest"      OFF)
option(USE_SYSTEM_IMGUI           "Use system pre-installed imgui"           OFF)
option(USE_SYSTEM_JPEG            "Use system pre-installed jpeg"            OFF)
option(USE_SYSTEM_JSONCPP         "Use system pre-installed jsoncpp"         OFF)
option(USE_SYSTEM_LIBLZF          "Use system pre-installed liblzf"          OFF)
option(USE_SYSTEM_MSGPACK         "Use system pre-installed msgpack"         OFF)
option(USE_SYSTEM_NANOFLANN       "Use system pre-installed nanoflann"       OFF)
option(USE_SYSTEM_OPENSSL         "Use system pre-installed OpenSSL"         OFF)
option(USE_SYSTEM_PNG             "Use system pre-installed png"             OFF)
option(USE_SYSTEM_PYBIND11        "Use system pre-installed pybind11"        OFF)
option(USE_SYSTEM_QHULLCPP        "Use system pre-installed qhullcpp"        OFF)
option(USE_SYSTEM_STDGPU          "Use system pre-installed stdgpu"          OFF)
option(USE_SYSTEM_TBB             "Use system pre-installed TBB"             OFF)
option(USE_SYSTEM_TINYGLTF        "Use system pre-installed tinygltf"        OFF)
option(USE_SYSTEM_TINYOBJLOADER   "Use system pre-installed tinyobjloader"   OFF)
option(USE_SYSTEM_VTK             "Use system pre-installed VTK"             OFF)
option(USE_SYSTEM_ZEROMQ          "Use system pre-installed ZeroMQ"          OFF)
if(LINUX_AARCH64 OR APPLE_AARCH64)
    option(BUILD_VTK_FROM_SOURCE      "Build VTK from source"                ON )
else()
    option(BUILD_VTK_FROM_SOURCE      "Build VTK from source"                OFF)
endif()
if(LINUX_AARCH64)
    option(BUILD_FILAMENT_FROM_SOURCE "Build filament from source"           ON )
else()
    option(BUILD_FILAMENT_FROM_SOURCE "Build filament from source"           OFF)
endif()

option(PREFER_OSX_HOMEBREW        "Prefer Homebrew libs over frameworks"     ON )
option(WITH_MINIZIP               "Enable MiniZIP"                           OFF)

# Sensor options
option(BUILD_LIBREALSENSE         "Build support for Intel RealSense camera" OFF)
option(USE_SYSTEM_LIBREALSENSE    "Use system pre-installed librealsense"    OFF)
option(BUILD_AZURE_KINECT         "Build support for Azure Kinect sensor"    OFF)

# ML library options
option(BUILD_TENSORFLOW_OPS       "Build ops for TensorFlow"                 OFF)
option(BUILD_PYTORCH_OPS          "Build ops for PyTorch"                    OFF)
option(BUNDLE_OPEN3D_ML           "Includes the Open3D-ML repo in the wheel" OFF)

# Release build options
option(DEVELOPER_BUILD      "Add +commit_hash to the project version number" ON )
if (NOT DEVELOPER_BUILD)
    if (NOT BUILD_COMMON_CUDA_ARCHS)
        set(BUILD_COMMON_CUDA_ARCHS ON CACHE BOOL "Build for common CUDA GPUs (for release)" FORCE)
        message(WARNING "Setting BUILD_COMMON_CUDA_ARCHS=ON since DEVELOPER_BUILD is OFF.")
    endif()
endif()

# Default build type on single-config generators.
# For multi-config generators (e.g. Visual Studio), CMAKE_CONFIGURATION_TYPES
# will be set, and we don't specify a default CMAKE_BUILD_TYPE.
# https://blog.kitware.com/cmake-and-the-default-build-type/
if(NOT CMAKE_CONFIGURATION_TYPES)
    if(NOT CMAKE_BUILD_TYPE)
        message(STATUS "Setting build type to Release as none was specified.")
        set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
        # Set the possible values of build type for cmake-gui.
        set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
                    "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
    endif()
    message(STATUS "CMAKE_BUILD_TYPE is set to ${CMAKE_BUILD_TYPE}.")
endif()

find_program(CCACHE "ccache")
if (CCACHE)
    message(STATUS "ccache found at ${CCACHE}")
    set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE})
    set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
    if(BUILD_CUDA_MODULE)
        set(CMAKE_CUDA_COMPILER_LAUNCHER ${CCACHE})
    endif()
endif()

if(POLICY CMP0135)
    cmake_policy(SET CMP0135 NEW)  # URL contents timestamped by download time
endif()
# In ExternalProject_Add, if OPEN3D_THIRD_PARTY_DOWNLOAD_DIR is specified, CMake will
# use this directory to cache downloaded 3rd party dependencies and automatically skip
# downloading from the Internet if the files are available. This is only supported by
# a limited number of 3rd party libraries.
set(OPEN3D_THIRD_PARTY_DOWNLOAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty_downloads"
    CACHE PATH "Third-party download directory for caching.")
message(STATUS "Downloading third-party dependencies to ${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}")

set(FILAMENT_PRECOMPILED_ROOT "" CACHE PATH "Path to precompiled Filament library (used if BUILD_FILAMENT_FROM_SOURCE=OFF)")

if (PREFER_OSX_HOMEBREW)
    set(CMAKE_FIND_FRAMEWORK LAST)
    set(CMAKE_FIND_APPBUNDLE LAST)
endif()

# Set OpenGL policy
if(NOT USE_SYSTEM_GLFW)
    cmake_policy(SET CMP0072 OLD)
endif()
cmake_policy(GET CMP0072 CMP0072_VALUE)

# Catch a few incompatible build options
if ((LINUX_AARCH64 OR APPLE_AARCH64) AND BUILD_ISPC_MODULE)
    message(FATAL_ERROR "ISPC module is not yet supported on ARM Linux")
endif()
if (LINUX_AARCH64 AND NOT BUILD_FILAMENT_FROM_SOURCE)
    message(FATAL_ERROR "ARM CPU detected, you must set BUILD_FILAMENT_FROM_SOURCE=ON.")
endif()
if ((LINUX_AARCH64 OR APPLE_AARCH64) AND NOT USE_BLAS)
    message(FATAL_ERROR "ARM CPU detected, you must set USE_BLAS=ON.")
endif()
if (APPLE AND ENABLE_HEADLESS_RENDERING)
    message(WARNING "Headless rendering is not supported on Mac OS")
    set(ENABLE_HEADLESS_RENDERING OFF)
endif()
if(ENABLE_HEADLESS_RENDERING AND BUILD_GUI)
    message(WARNING "Headless rendering disables the Open3D GUI")
    set(BUILD_GUI OFF)
endif()
if(ENABLE_HEADLESS_RENDERING AND (USE_SYSTEM_GLEW OR USE_SYSTEM_GLFW))
    message(WARNING "Headless rendering requires customized GLEW and GLFW builds")
    set(USE_SYSTEM_GLEW OFF)
    set(USE_SYSTEM_GLFW OFF)
endif()
if(BUNDLE_OPEN3D_ML AND NOT (BUILD_TENSORFLOW_OPS OR BUILD_PYTORCH_OPS))
    message(SEND_ERROR "3DML depends on TensorFlow or PyTorch Ops. Enable them with -DBUILD_TENSORFLOW_OPS=ON or -DBUILD_PYTORCH_OPS=ON")
endif()
if(BUILD_WEBRTC AND LINUX_AARCH64)
    message(FATAL_ERROR "BUILD_WEBRTC=ON is not yet supported on ARM Linux")
endif()
if(BUILD_WEBRTC AND NOT BUILD_GUI)
    message(FATAL_ERROR "BUILD_WEBRTC=ON requires BUILD_GUI=ON")
endif()
if(BUILD_JUPYTER_EXTENSION AND NOT BUILD_WEBRTC)
    # BUILD_JUPYTER_EXTENSION transitively depends on BUILD_GUI
    message(FATAL_ERROR "BUILD_JUPYTER_EXTENSION=ON requires BUILD_WEBRTC=ON")
endif()
if(BUILD_JUPYTER_EXTENSION AND NOT BUILD_PYTHON_MODULE)
    message(FATAL_ERROR "BUILD_JUPYTER_EXTENSION=ON requires BUILD_PYTHON_MODULE=ON")
endif()

# Parse Open3D version number
file(STRINGS "cpp/open3d/version.txt" OPEN3D_VERSION_READ)
foreach(ver ${OPEN3D_VERSION_READ})
    if (ver MATCHES "OPEN3D_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
        set(OPEN3D_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
    endif()
endforeach()
set(OPEN3D_VERSION_DEVHASH "")
if(DEVELOPER_BUILD)
    execute_process(COMMAND git -C "${CMAKE_SOURCE_DIR}" log --pretty=format:%h -n 1
        OUTPUT_VARIABLE GIT_REV)
    if (GIT_REV)
        set(OPEN3D_VERSION_DEVHASH "+${GIT_REV}")
    endif()
endif()
string(CONCAT OPEN3D_VERSION
    "${OPEN3D_VERSION_MAJOR}"
    ".${OPEN3D_VERSION_MINOR}"
    ".${OPEN3D_VERSION_PATCH}"
)
set(OPEN3D_VERSION_FULL "${OPEN3D_VERSION}${OPEN3D_VERSION_DEVHASH}" CACHE
    STRING "Open3D full version.")
# Set additional info
set(PROJECT_EMAIL       "open3d@intel.com")
set(PROJECT_DOCS        "https://www.open3d.org/docs")
set(PROJECT_CODE        "https://github.com/isl-org/Open3D")
set(PROJECT_ISSUES      "https://github.com/isl-org/Open3D/issues")

project(Open3D
    VERSION ${OPEN3D_VERSION}
    # Set PROJECT_DESCRIPTION
    DESCRIPTION "Open3D: A Modern Library for 3D Data Processing."
    # Set PROJECT_HOMEPAGE_URL
    HOMEPAGE_URL "https://www.open3d.org"
    LANGUAGES C CXX)
message(STATUS "Open3D ${OPEN3D_VERSION_FULL}")

# Check SYCL compatiblility
if (BUILD_SYCL_MODULE AND NOT CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
    message(FATAL_ERROR "BUILD_SYCL_MODULE requires IntelLLVM (DPC++) compiler, "
                        "but got CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID} "
                        "and CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}.")
endif()
if (BUILD_SYCL_MODULE AND (NOT UNIX OR APPLE))
    message(FATAL_ERROR "Open3D SYCL support is only available on Linux")
endif()
if(BUILD_SYCL_MODULE AND NOT GLIBCXX_USE_CXX11_ABI)
    message(FATAL_ERROR "BUILD_SYCL_MODULE=ON requires GLIBCXX_USE_CXX11_ABI=ON")
endif()
if(BUILD_SYCL_MODULE AND BUILD_TENSORFLOW_OPS)
    message(FATAL_ERROR "BUILD_SYCL_MODULE=ON requires BUILD_TENSORFLOW_OPS=OFF")
endif()
if(BUILD_SYCL_MODULE AND BUILD_PYTORCH_OPS)
    message(FATAL_ERROR "BUILD_SYCL_MODULE=ON requires BUILD_PYTORCH_OPS=OFF")
endif()
if(BUILD_SYCL_MODULE AND BUILD_CUDA_MODULE)
    message(FATAL_ERROR "BUILD_SYCL_MODULE and BUILD_SYCL_MODULE cannot be on at the same time for now.")
endif()

# Global flag to set CXX standard.
# This does not affect 3rd party libraries.
# Tensorflow 2.9+ requires cxx_17, but MSVC 19.29 throws errors with C++17
# enabled.
if (BUILD_SYCL_MODULE OR BUILD_TENSORFLOW_OPS)
    set(CMAKE_CXX_STANDARD 17)
else()
    set(CMAKE_CXX_STANDARD 14)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)   # Improved compatibility

# FIXME: Remove this workaround once a fixed Visual Studio 16.10 version is released.
if (BUILD_CUDA_MODULE
    AND CMAKE_CXX_COMPILER MATCHES "MSVC"
    AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "19.29"
)
    # Keep C++14 standard for unaffected C++ files, but use C++17 for CUDA files.
    set(CMAKE_CUDA_STANDARD 17)
    # Suppress warnings for deprecated C++17 functions.
    add_compile_definitions($<$<COMPILE_LANGUAGE:CUDA>:_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING>)
    message(WARNING "Visual Studio 16.10 (MSVC 19.29) introduced a compiler bug when compiling CUDA code with C++14. "
        "Workaround this bug by setting the CUDA standard to C++17.")
endif()

# CMake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cmake")

# Setup Python executable
if(NOT DEFINED Python3_FIND_REGISTRY)
    # Only consider PATH variable on Windows by default
    set(Python3_FIND_REGISTRY NEVER)
endif()
# Requires Python 3.6+
find_package(Python3 3.6
             COMPONENTS Interpreter Development)
if (Python3_FOUND)
    # Setup PYTHON_EXECUTABLE for 3rdparty modules
    # which still use the deprecated find_package(PythonInterp)
    set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE} CACHE STRING
        "Deprecated path to the Python executable (for 3rdparty only)" FORCE)
else()
    if (BUILD_PYTHON_MODULE)
        message(FATAL_ERROR "BUILD_PYTHON_MODULE=ON requires Python >= 3.6. Please ensure it is in PATH.")
    endif()
endif()

# npm version has to be MAJOR.MINOR.PATCH
string(CONCAT PROJECT_VERSION_THREE_NUMBER "${OPEN3D_VERSION_MAJOR}"
                                           ".${OPEN3D_VERSION_MINOR}"
                                           ".${OPEN3D_VERSION_PATCH}")

# PyPI package name controls specifies the repository name on PyPI. The default
# name is "open3d". In the past, for historical reasons, we've used the
# following names for PyPI, while they are now deprecated:
# - open3d-python
# - py3d
# - open3d-original
# - open3d-official
# - open-3d
if(NOT DEFINED PYPI_PACKAGE_NAME)
    set(PYPI_PACKAGE_NAME "open3d")
endif()

# Set installation paths
if(UNIX OR CYGWIN)
    include(GNUInstallDirs)
    set(Open3D_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
    set(Open3D_INSTALL_BIN_DIR "${CMAKE_INSTALL_BINDIR}")
    set(Open3D_INSTALL_LIB_DIR "${CMAKE_INSTALL_LIBDIR}")
    # Put resources in */share/
    set(Open3D_INSTALL_RESOURCE_DIR "${CMAKE_INSTALL_DATADIR}")
    set(Open3D_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
else()
    set(Open3D_INSTALL_INCLUDE_DIR include)
    set(Open3D_INSTALL_BIN_DIR bin)
    set(Open3D_INSTALL_LIB_DIR lib)
    # Put resources in */bin, with executables / DLLs
    set(Open3D_INSTALL_RESOURCE_DIR bin)
    set(Open3D_INSTALL_CMAKE_DIR CMake)
endif()

# Put build results in some predictable places
# The $<CONFIG> generator expression makes sure that XCode or Visual Studio do not
# append additional path components, as we need to know *exactly* where the build results
# end up.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/$<CONFIG>)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/$<CONFIG>)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

# Global Security options (including 3rd party code)
# Add -fPIC for library and -fPIE for executable to compiler and linker. Does not add -pie !
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Explicitly specify the preference of using -pthread over -lpthread.
# This must be defined here since CUDA calls find_package(Threads) internally.
set(THREADS_PREFER_PTHREAD_FLAG TRUE)

# Overwrites property for Thread::Threads in find_package(Threads)
# For CUDA, "-pthread" is replaced with "-Xcompiler -pthread" (CMake's default)
# For ISPC, "-pthread" is disabled
macro(open3d_patch_findthreads_module_)
    if(TARGET Threads::Threads AND THREADS_HAVE_PTHREAD_ARG)
        set_property(TARGET Threads::Threads
                     PROPERTY INTERFACE_COMPILE_OPTIONS
                     "$<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>:SHELL:-Xcompiler -pthread>"
                     "$<$<AND:$<NOT:$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>>,$<NOT:$<COMPILE_LANGUAGE:ISPC>>>:-pthread>")
    endif()
endmacro()
cmake_language(EVAL CODE "cmake_language(DEFER CALL open3d_patch_findthreads_module_)")

# Build CUDA module by default if CUDA is available
if(BUILD_CUDA_MODULE)
    include(Open3DMakeCudaArchitectures)
    open3d_make_cuda_architectures(CUDA_ARCHS)
    set(CMAKE_CUDA_ARCHITECTURES ${CUDA_ARCHS})

    message(STATUS "Using CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
    enable_language(CUDA)

    if (CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "10.1")
        message(FATAL_ERROR "CUDA 10.0 and older are not supported. Please upgrade to CUDA 10.1 or newer.")
    endif()
endif ()

# ISPC language emulation support
include(Open3DISPC)

if (CMAKE_ISPC_COMPILER_LOADED OR (CMAKE_GENERATOR MATCHES "Make" OR CMAKE_GENERATOR MATCHES "Ninja"))
    option(ISPC_USE_LEGACY_EMULATION "Use legacy ISPC language emulation over first-class CMake support" OFF)
else()
    option(ISPC_USE_LEGACY_EMULATION "Use legacy ISPC language emulation over first-class CMake support" ON)
endif()
mark_as_advanced(ISPC_USE_LEGACY_EMULATION)
option(ISPC_PRINT_LEGACY_COMPILE_COMMANDS "Prints legacy compile commands on CMake configuration time" ON)
mark_as_advanced(ISPC_PRINT_LEGACY_COMPILE_COMMANDS)

# Build ISPC module by default if ISPC is available
if (BUILD_ISPC_MODULE)
    include(Open3DFetchISPCCompiler)
    open3d_fetch_ispc_compiler()

    include(Open3DMakeISPCInstructionSets)
    open3d_make_ispc_instruction_sets(ISPC_ISAS)
    set(CMAKE_ISPC_INSTRUCTION_SETS ${ISPC_ISAS})

    message(STATUS "Using ISPC instruction sets: ${CMAKE_ISPC_INSTRUCTION_SETS}")

    open3d_ispc_enable_language(ISPC)

    if (CMAKE_ISPC_COMPILER_ID STREQUAL "Intel" AND CMAKE_ISPC_COMPILER_VERSION VERSION_LESS "1.16")
        message(FATAL_ERROR "ISPC 1.15 and older are not supported. Please upgrade to ISPC 1.16 or newer.")
    endif()

    if (NOT CMAKE_ISPC_COMPILER_ID)
        message(FATAL_ERROR "Unknown ISPC compiler.")
    endif()
endif()

# OS specific settings
if(WIN32)
    # Windows defaults to hidden symbol visibility, override that
    # TODO: It would be better to explicitly export symbols.
    #       Then, we could use -fvisibility=hidden for Linux as well
    SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
    if(MSVC)
        # Make sure we don't hit the 65535 object member limit with MSVC
        #
        # /bigobj allows object files with more than 65535 members
        # /Ob2 enables function inlining, because MSVC is particularly
        # verbose with inline members
        #
        # See: https://github.com/tensorflow/tensorflow/pull/10962
        add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/bigobj;/Ob2>")
    endif()
    if (STATIC_WINDOWS_RUNTIME)
        set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
    else()
        set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
    endif()
endif()

# Folder view for project files
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

macro(add_source_group module_name)
    file(GLOB MODULE_HEADER_FILES "${module_name}/*.h")
    source_group("Header Files\\${module_name}" FILES ${MODULE_HEADER_FILES})
    file(GLOB MODULE_SOURCE_FILES "${module_name}/*.cpp")
    source_group("Source Files\\${module_name}" FILES ${MODULE_SOURCE_FILES})
    file(GLOB MODULE_ISPC_HEADER_FILES "${module_name}/*.isph")
    source_group("Header Files\\ISPC" FILES ${MODULE_ISPC_HEADER_FILES})
    file(GLOB MODULE_ISPC_SOURCE_FILES "${module_name}/*.ispc")
    source_group("Source Files\\ISPC" FILES ${MODULE_ISPC_SOURCE_FILES})
    file(GLOB MODULE_SHADER_FILES "${module_name}/*.glsl")
    source_group("Source Files\\Shader\\GLSL" FILES ${MODULE_SHADER_FILES})
    file(GLOB MODULE_MATERIAL_FILES "${module_name}/*.mat")
    source_group("Source Files\\Material" FILES ${MODULE_MATERIAL_FILES})
endmacro()

# Include convenience functions
include(Open3DLink3rdpartyLibraries)
include(Open3DSetGlobalProperties)
include(Open3DShowAndAbortOnWarning)
include(Open3DSYCLTargetSources)

# Enumerate all third-party libraries which we need later
# This creates the necessary targets and sets the
# Open3D_3RDPARTY_*_TARGETS variables we use in open3d_link_3rdparty_libraries
include(3rdparty/find_dependencies.cmake)

# Open3D library
add_subdirectory(cpp)

# Examples
add_subdirectory(examples)

# Documentation
add_subdirectory(docs)

# Install CMake configuration files
install(EXPORT ${PROJECT_NAME}Targets NAMESPACE ${PROJECT_NAME}:: DESTINATION ${Open3D_INSTALL_CMAKE_DIR})
export(EXPORT ${PROJECT_NAME}Targets NAMESPACE ${PROJECT_NAME}::)

if (Python3_EXECUTABLE)
    # `make check-style` checks style for c++/cuda/python/ipynb files
    add_custom_target(check-style
        COMMAND ${Python3_EXECUTABLE}
        ${CMAKE_CURRENT_SOURCE_DIR}/util/check_style.py
        COMMENT "Python executable used for style check: ${Python3_EXECUTABLE}."
    )

    # `make apply-style` applies style for c++/cuda/python/ipynb files
    add_custom_target(apply-style
        COMMAND ${Python3_EXECUTABLE}
        ${CMAKE_CURRENT_SOURCE_DIR}/util/check_style.py --apply
        COMMENT "Python executable used for style check: ${Python3_EXECUTABLE}."
    )
endif()

include(Open3DPackaging)

# `make check-cpp-style` checks style for c++/cuda files.
# This works outside of python virtualenv.
add_custom_target(check-cpp-style
    COMMAND ${CMAKE_COMMAND}
    -DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}"
    -DAPPLY=OFF
    -P ${CMAKE_CURRENT_SOURCE_DIR}/util/check_cpp_style.cmake
)

# `make apply-cpp-style` applies style for c++/cuda files.
# This works outside of python virtualenv.
add_custom_target(apply-cpp-style
    COMMAND ${CMAKE_COMMAND}
    -DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}"
    -DAPPLY=ON
    -P ${CMAKE_CURRENT_SOURCE_DIR}/util/check_cpp_style.cmake
)

include(Open3DPrintConfigurationSummary)
open3d_print_configuration_summary()

包括如下所示的issue#5297 等问题都通过以上配置得到了解决,如果懒折腾可以直接copy以上CMakeLists.txt进行cmake

error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in Open3DConfig.obj

3. Open3D.sln 编译安装

完成后点击Open Project或在build目录下自行打开 Open3D.sln

在解决方案的CMakePredefinedTargets目录下,分别对ALL_BUILDINSTALL右键->生成

进行ALL_BUILD时会下载一些第三方库,整个过程比预想中慢很多,注意设置网络代理
在这里插入图片描述

由于采用了多线程,编译过程会将CPU吃满,整个系统会略显卡顿

ALL_BUILD成功输出如下
在这里插入图片描述
INSTALL成功输出如下

在这里插入图片描述
然后就可以在之前设置的安装目录下看到相关库文件
在这里插入图片描述

test

小测一下

打开 XXX\Open3D\build\Open3D\Release\Open3DViewer.exe
找一份点云拖进去

在这里插入图片描述
ok


Visual Studio 配置

新建一个C++空项目,在属性管理器中新建属性表如下
在这里插入图片描述

1. VC++目录 -> 包含目录

添加

D:\Program Files\Open3D\include 
D:\Program Files\Open3D\include\open3d
D:\Program Files\Open3D\include\open3d\3rdparty

在这里插入图片描述

2. VC++目录 -> 库目录

添加

D:\Program Files\Open3D\lib

VC++目录 ->包含目录

3. 链接器 -> 输入 -> 附加依赖项

添加 D:\Program Files\Open3D\lib 目录下的所有lib
这里再次召唤我之前写的lib文件名提取脚本,提取出lib文件名如下,添加到附加依赖项中

注意,这里还需要添加一个OpenGL32.Lib

OpenGL32.Lib
Open3D.lib
Open3D_3rdparty_assimp.lib
Open3D_3rdparty_blas_mkl_core.lib
Open3D_3rdparty_blas_mkl_intel_ilp64.lib
Open3D_3rdparty_blas_mkl_sequential.lib
Open3D_3rdparty_blas_tbb_static.lib
Open3D_3rdparty_curl.lib
Open3D_3rdparty_embree_embree4.lib
Open3D_3rdparty_embree_embree_avx.lib
Open3D_3rdparty_embree_embree_avx2.lib
Open3D_3rdparty_embree_lexers.lib
Open3D_3rdparty_embree_math.lib
Open3D_3rdparty_embree_sys.lib
Open3D_3rdparty_embree_tasking.lib
Open3D_3rdparty_filament_bluegl.lib
Open3D_3rdparty_filament_bluevk.lib
Open3D_3rdparty_filament_filabridge.lib
Open3D_3rdparty_filament_filaflat.lib
Open3D_3rdparty_filament_filamat_lite.lib
Open3D_3rdparty_filament_filament.lib
Open3D_3rdparty_filament_filameshio.lib
Open3D_3rdparty_filament_geometry.lib
Open3D_3rdparty_filament_ibl.lib
Open3D_3rdparty_filament_image.lib
Open3D_3rdparty_filament_meshoptimizer.lib
Open3D_3rdparty_filament_smol-v.lib
Open3D_3rdparty_filament_utils.lib
Open3D_3rdparty_fmt.lib
Open3D_3rdparty_glew.lib
Open3D_3rdparty_glfw.lib
Open3D_3rdparty_imgui.lib
Open3D_3rdparty_jpeg.lib
Open3D_3rdparty_jsoncpp.lib
Open3D_3rdparty_liblzf.lib
Open3D_3rdparty_openssl_crypto.lib
Open3D_3rdparty_openssl_ssl.lib
Open3D_3rdparty_png.lib
Open3D_3rdparty_qhullcpp.lib
Open3D_3rdparty_qhull_r.lib
Open3D_3rdparty_rply.lib
Open3D_3rdparty_tbb_tbbmalloc_static.lib
Open3D_3rdparty_tbb_tbb_static.lib
Open3D_3rdparty_tinyfiledialogs.lib
Open3D_3rdparty_uvatlas.lib
Open3D_3rdparty_vtk_vtkCommonCore-9.1.lib
Open3D_3rdparty_vtk_vtkCommonDataModel-9.1.lib
Open3D_3rdparty_vtk_vtkCommonExecutionModel-9.1.lib
Open3D_3rdparty_vtk_vtkCommonMath-9.1.lib
Open3D_3rdparty_vtk_vtkCommonMisc-9.1.lib
Open3D_3rdparty_vtk_vtkCommonSystem-9.1.lib
Open3D_3rdparty_vtk_vtkCommonTransforms-9.1.lib
Open3D_3rdparty_vtk_vtkFiltersCore-9.1.lib
Open3D_3rdparty_vtk_vtkFiltersGeneral-9.1.lib
Open3D_3rdparty_vtk_vtkFiltersModeling-9.1.lib
Open3D_3rdparty_vtk_vtkFiltersSources-9.1.lib
Open3D_3rdparty_vtk_vtkkissfft-9.1.lib
Open3D_3rdparty_vtk_vtkpugixml-9.1.lib
Open3D_3rdparty_vtk_vtksys-9.1.lib
Open3D_3rdparty_zeromq.lib
Open3D_3rdparty_zlib.lib

在这里插入图片描述

保存属性表

test

找一份代码进行测试

#include <string>

#include "Open3D/Open3D.h"

int main()
{
    auto sphere = open3d::geometry::TriangleMesh::CreateSphere(1.0);
    sphere->ComputeVertexNormals();
    sphere->PaintUniformColor({ 0.0, 0.5, 0.5 });
    open3d::visualization::DrawGeometries({ sphere });
    return 0;
}

成功
在这里插入图片描述
ok


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WoooChi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值