Skip to content

Commit

Permalink
Merge pull request Forceflow#39 from KernelA/universal-cmake
Browse files Browse the repository at this point in the history
CMake for Windows and Linux
  • Loading branch information
Forceflow authored Jul 13, 2020
2 parents 992bca0 + ca7804c commit 49020e2
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 86 deletions.
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ matrix:
- CUDA=10.1.105-1
- CUDA_SHORT=10.1
- UBUNTU_VERSION=ubuntu1804
- CUDA_ARCH=30
dist: bionic

before_install:
Expand All @@ -34,11 +35,16 @@ before_install:
- sudo apt-get install -y mesa-common-dev libglu1-mesa-dev libxi-dev
- git clone https://github.com/Forceflow/trimesh2.git
- cd trimesh2 && make && cd ..
- wget https://github.com/Kitware/CMake/releases/download/v3.13.0/cmake-3.13.0-Linux-x86_64.sh -q -O ./cmake-install.sh
- chmod u+x ./cmake-install.sh
- mkdir ./cmake
- ./cmake-install.sh --skip-license --prefix=./cmake
- rm ./cmake-install.sh

script:
- mkdir build
- cd build
- cmake ..
- make
- ../cmake/bin/cmake -DTrimesh2_INCLUDE_DIR="../trimesh2/include" -DTrimesh2_LINK_DIR="../trimesh2/lib.Linux64" -DCUDA_ARCH=${CUDA_ARCH} ..
- ../cmake/bin/cmake --build . -j 2
# Force CPU voxelization to test on Travis (we won't have a GPU here)
- ./cuda_voxelizer -f ../test_models/bunny.OBJ -cpu
68 changes: 49 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
CMAKE_MINIMUM_REQUIRED(VERSION 3.13 FATAL_ERROR)

PROJECT ( CudaVoxelizer )
PROJECT(CudaVoxelize LANGUAGES CXX)

SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
IF(MSVC)
ENABLE_LANGUAGE(CUDA)
ENDIF()

FIND_PACKAGE(CUDA QUIET REQUIRED)
FIND_PACKAGE(GLM REQUIRED)
FIND_PACKAGE(glm REQUIRED)
FIND_PACKAGE(OpenMP REQUIRED)


IF(NOT MSVC)
FIND_PACKAGE(CUDA REQUIRED)
ENDIF()

SET(CUDA_VOXELIZER_EXECUTABLE cuda_voxelizer)

SET(Trimesh2_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/trimesh2/include" CACHE PATH "Path to Trimesh2 includes")
SET(Trimesh2_INCLUDE_DIR CACHE PATH "Path to Trimesh2 includes")
SET(CUDA_ARCH CACHE STRING "CUDA compute capability. It is prefer to set native value for your video card. Example: 61")

IF(NOT CUDA_ARCH)
MESSAGE(FATAL_ERROR "You must set CUDA_ARCH variable. For example: 61.")
ENDIF()

IF(NOT Trimesh2_INCLUDE_DIR)
MESSAGE(FATAL_ERROR "You need to set variable Trimesh2_INCLUDE_DIR")
ENDIF()

FIND_FILE(Trimesh2_TriMesh_h TriMesh.h ${Trimesh2_INCLUDE_DIR})
IF(NOT Trimesh2_TriMesh_h)
message(SEND_ERROR "Can't find TriMesh.h in ${Trimesh2_INCLUDE_DIR}")
message(FATAL_ERROR "Can't find TriMesh.h in ${Trimesh2_INCLUDE_DIR}")
ENDIF()
MARK_AS_ADVANCED(Trimesh2_TriMesh_h)
INCLUDE_DIRECTORIES(${Trimesh2_INCLUDE_DIR})

SET(Trimesh2_LINK_DIR "${CMAKE_SOURCE_DIR}/trimesh2/lib.Linux64" CACHE PATH "Path to Trimesh2 libraries")
SET(Trimesh2_LINK_DIR CACHE PATH "Path to Trimesh2 library dir.")

IF(NOT Trimesh2_LINK_DIR)
MESSAGE(FATAL_ERROR "You need to set variable Trimesh2_LINK_DIR")
ENDIF()

IF(NOT EXISTS "${Trimesh2_LINK_DIR}")
MESSAGE(FATAL_ERROR "Trimesh2 library dir does not exist")
ENDIF()

FIND_LIBRARY(Trimesh2_LIBRARY trimesh ${Trimesh2_LINK_DIR})

IF(NOT Trimesh2_LIBRARY)
message(SEND_ERROR "Can't find libtrimesh.a in ${Trimesh2_LINK_DIR}")
ENDIF()
MARK_AS_ADVANCED(Trimesh2_LIBRARY)

MESSAGE(STATUS "CUDA compute capability set to ${CUDA_ARCH}")
MESSAGE(STATUS "Found Trimesh2 include: ${Trimesh2_TriMesh_h}")
MESSAGE(STATUS "Found Trimesh2 lib: ${Trimesh2_LIBRARY}")

SET(CUDA_VOXELIZER_SRCS
./src/main.cpp
./src/util_cuda.cpp
Expand All @@ -39,15 +65,19 @@ SET(CUDA_VOXELIZER_SRCS_CU
./src/voxelize_solid.cu
)

IF(MSVC)
ADD_EXECUTABLE(
${CUDA_VOXELIZER_EXECUTABLE}
${CUDA_VOXELIZER_SRCS}
${CUDA_VOXELIZER_SRCS_CU})
ELSE()
CUDA_ADD_EXECUTABLE(
${CUDA_VOXELIZER_EXECUTABLE}
${CUDA_VOXELIZER_EXECUTABLE}
${CUDA_VOXELIZER_SRCS}
${CUDA_VOXELIZER_SRCS_CU})
ENDIF()

TARGET_INCLUDE_DIRECTORIES( ${CUDA_VOXELIZER_EXECUTABLE} PUBLIC
${Trimesh2_INCLUDE_DIR})

TARGET_LINK_LIBRARIES ( ${CUDA_VOXELIZER_EXECUTABLE}
${Trimesh2_LIBRARY}
gomp
)
TARGET_COMPILE_FEATURES(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE cxx_std_11)
TARGET_INCLUDE_DIRECTORIES(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE ${Trimesh2_INCLUDE_DIR})
TARGET_LINK_LIBRARIES (${CUDA_VOXELIZER_EXECUTABLE} ${Trimesh2_LIBRARY} glm OpenMP::OpenMP_CXX)
TARGET_COMPILE_OPTIONS(${CUDA_VOXELIZER_EXECUTABLE} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_${CUDA_ARCH},code=sm_${CUDA_ARCH}>)
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,30 @@ The project has the following build dependencies:
* [GLM](http://glm.g-truc.net/0.9.8/index.html) for vector math. Any recent version will do.
* [OpenMP](https://www.openmp.org/)

### Windows
### CMake

1. Install dependency.
2. `mkdir build`
3. `cd build`

For Windows with Visual Studio 2019:
```
cmake -A x64 -DTrimesh2_INCLUDE_DIR:PATH="path_to_trimesh2_include" -DTrimesh2_LINK_DIR:PATH="path_to_trimesh2_library_dir" -DCUDA_ARCH:STRING="your_cuda_compute_capability" ..
```

For Linux:
```
cmake -DTrimesh2_INCLUDE_DIR:PATH="path_to_trimesh2_include" -DTrimesh2_LINK_DIR:PATH="path_to_trimesh2_library_dir" -DCUDA_ARCH:STRING="your_cuda_compute_capability" ..
```
`your_cuda_compute_capability` is string. For example `-DCUDA_ARCH:STRING=61` or `-DCUDA_ARCH:STRING=60`. [More about it](https://docs.nvidia.com/cuda/archive/10.2/cuda-compiler-driver-nvcc/index.html#options-for-steering-gpu-code-generation-gpu-architecture).

Run:
```
cmake --build . -j number_of_cores
```

### Windows without CMake

A Visual Studio 2019 project solution is provided in the `msvc`folder. It is configured for CUDA 11, but you can edit the project file to make it work with lower CUDA versions. You can edit the `custom_includes.props` file to configure the library locations, and specify a place where the resulting binaries should be placed.

```
Expand All @@ -48,7 +71,7 @@ A Visual Studio 2019 project solution is provided in the `msvc`folder. It is con
```

### Linux
[Philipp-M](https://github.com/Philipp-M) and [andreanicastro](https://github.com/andreanicastro) were kind enough to write [CMake](https://cmake.org/) support. Since November 2019, cuda_voxelizer also builds on [Travis CI](https://travis-ci.org/Forceflow/cuda_voxelizer), so check out the [yaml config file](https://github.com/Forceflow/cuda_voxelizer/blob/master/.travis.yml) for more Linux build support.
[Philipp-M](https://github.com/Philipp-M) and [andreanicastro](https://github.com/andreanicastro) were kind enough to write [CMake](https://cmake.org/) support. Since November 2019, cuda_voxelizer also builds on [Travis CI](https://travis-ci.org/Forceflow/cuda_voxelizer), so check out the [yaml config file](https://github.com/Forceflow/cuda_voxelizer/blob/main/.travis.yml) for more Linux build support.

## Details
`cuda_voxelizer` implements an optimized version of the method described in M. Schwarz and HP Seidel's 2010 paper [*Fast Parallel Surface and Solid Voxelization on GPU's*](http://research.michael-schwarz.com/publ/2010/vox/). The morton-encoded table was based on my 2013 HPG paper [*Out-Of-Core construction of Sparse Voxel Octrees*](http://graphics.cs.kuleuven.be/publications/BLD14OCCSVO/) and the work in [*libmorton*](https://github.com/Forceflow/libmorton).
Expand Down
63 changes: 0 additions & 63 deletions cmake/FindGLM.cmake

This file was deleted.

0 comments on commit 49020e2

Please sign in to comment.