Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 4bfbc25

Browse files
committed
add open3d build example
1 parent 85135c5 commit 4bfbc25

File tree

5 files changed

+166
-1
lines changed

5 files changed

+166
-1
lines changed

.clang-format

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BasedOnStyle: Google
2+
IndentWidth: 4
3+
ColumnLimit: 80
4+
UseTab: Never
5+
Standard: c++14
6+
ContinuationIndentWidth: 8
7+
AccessModifierOffset: -4
8+
BinPackParameters: false
9+
SortIncludes: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
build/
2+
13
# Prerequisites
24
*.d
35

CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# On Ubuntu 18.04, get the latest CMake from https://apt.kitware.com/.
2+
cmake_minimum_required(VERSION 3.18)
3+
set(CMAKE_CXX_STANDARD 14)
4+
project(Open3DCMakeFindPackage LANGUAGES C CXX)
5+
6+
if(POLICY CMP0091)
7+
# https://stackoverflow.com/a/56490614
8+
cmake_policy(SET CMP0091 NEW)
9+
endif()
10+
11+
# The options need to be the same as Open3D's default
12+
# If Open3D is configured and built with custom options, you'll also need to
13+
# specify the same custom options.
14+
option(STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" ON)
15+
# This needs cmake_policy(SET CMP0091 NEW)
16+
if (STATIC_WINDOWS_RUNTIME)
17+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
18+
else()
19+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
20+
endif()
21+
22+
# Find installed Open3D, which exports Open3D::Open3D
23+
if(WIN32)
24+
find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/CMake)
25+
else()
26+
find_package(Open3D HINTS ${CMAKE_INSTALL_PREFIX}/lib/cmake)
27+
endif()
28+
if(NOT Open3D_FOUND)
29+
message(FATAL_ERROR "Open3D not found, please use -DCMAKE_INSTALL_PREFIX=open3d_install_dir")
30+
endif()
31+
32+
add_executable(Draw Draw.cpp)
33+
target_link_libraries(Draw Open3D::Open3D)
34+
35+
# On Windows, when BUILD_SHARED_LIBS, copy .dll to the executable directory
36+
if(WIN32)
37+
get_target_property(open3d_type Open3D::Open3D TYPE)
38+
if(open3d_type STREQUAL "SHARED_LIBRARY")
39+
message(STATUS "Will copy Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
40+
add_custom_command(TARGET Draw POST_BUILD
41+
COMMAND ${CMAKE_COMMAND} -E copy
42+
${CMAKE_INSTALL_PREFIX}/bin/Open3D.dll
43+
${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
44+
endif()
45+
endif()

Draw.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ----------------------------------------------------------------------------
2+
// - Open3D: www.open3d.org -
3+
// ----------------------------------------------------------------------------
4+
// The MIT License (MIT)
5+
//
6+
// Copyright (c) 2021 www.open3d.org
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24+
// IN THE SOFTWARE.
25+
// ----------------------------------------------------------------------------
26+
27+
#include <string>
28+
29+
#include "open3d/Open3D.h"
30+
31+
int main(int argc, char *argv[]) {
32+
using namespace open3d;
33+
34+
if (argc == 2) {
35+
std::string option(argv[1]);
36+
if (option == "--skip-for-unit-test") {
37+
utility::LogInfo("Skiped for unit test.");
38+
return 0;
39+
}
40+
}
41+
42+
auto sphere = geometry::TriangleMesh::CreateSphere(1.0);
43+
sphere->ComputeVertexNormals();
44+
sphere->PaintUniformColor({0.0, 1.0, 0.0});
45+
visualization::DrawGeometries({sphere});
46+
return 0;
47+
}

README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
# open3d-cmake-find-package
1+
# Find Pre-Installed Open3D Package in CMake
2+
3+
This is one of the two CMake examples showing how to use Open3D in your CMake
4+
project:
5+
6+
* [Find Pre-Installed Open3D Package in CMake](https://github.com/intel-isl/open3d-cmake-find-package)
7+
* [Use Open3D as a CMake External Project](https://github.com/intel-isl/open3d-cmake-external-project)
8+
9+
For more details, check out the [Open3D repo](https://github.com/intel-isl/Open3D) and
10+
[Open3D docs](http://www.open3d.org/docs/release/cpp_project.html).
11+
12+
## Step 1: Compile and install Open3D
13+
14+
Follow the [Open3D compilation guide](http://www.open3d.org/docs/release/compilation.html),
15+
compile and install Open3D in your preferred location. You can specify the
16+
installation path with `CMAKE_INSTALL_PREFIX`. E.g.
17+
18+
On Ubuntu/MacOS:
19+
20+
```bash
21+
git clone --recursive https://github.com/intel-isl/Open3D.git
22+
cd Open3D
23+
mkdir build
24+
cd build
25+
cmake -DCMAKE_INSTALL_PREFIX=${HOME}/open3d_install ..
26+
cd ../..
27+
```
28+
29+
On Windows:
30+
31+
```batch
32+
git clone --recursive https://github.com/intel-isl/Open3D.git
33+
cd Open3D
34+
mkdir build
35+
cd build
36+
cmake -G "Visual Studio 16 2019 Win64" -A x64 -DCMAKE_INSTALL_PREFIX=C:\open3d_install ..
37+
cmake --build . --config Release --target install
38+
cd ..\..
39+
```
40+
41+
## Step 2: Use Open3D in this example project
42+
43+
On Ubuntu/MacOS:
44+
45+
```bash
46+
git clone https://github.com/intel-isl/open3d-cmake-find-package.git
47+
cd open3d-cmake-find-package
48+
mkdir build
49+
cd build
50+
cmake -DCMAKE_INSTALL_PREFIX=${HOME}/open3d_install ..
51+
./Draw
52+
```
53+
54+
On Windows:
55+
56+
```batch
57+
git clone https://github.com/intel-isl/open3d-cmake-find-package.git
58+
cd open3d-cmake-find-package
59+
mkdir build
60+
cmake -G "Visual Studio 16 2019 Win64" -A x64 -DCMAKE_PREFIX_PATH=C:\open3d_install ..
61+
cmake --build . --config Release
62+
Release\Draw
63+
```

0 commit comments

Comments
 (0)