Skip to content

Commit

Permalink
cmake fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed May 30, 2022
1 parent dd931fc commit c6f4d9d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,23 @@ if (THRUST_BACKEND STREQUAL "CUDA")
# we cannot set THRUST_INC_DIR when building with CUDA, otherwise the
# compiler will not use the system CUDA headers which causes incompatibility
enable_language(CUDA)
find_package(CUDA REQUIRED)
# clear THRUST_INC_DIR, we use the one from nvcc
set(THRUST_INC_DIR "")
# OpenMP also required
find_package(OpenMP REQUIRED)
set(MANIFOLD_INCLUDE OpenMP::OpenMP_CXX)
set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA)
set(MANIFOLD_NVCC_FLAGS ${MANIFOLD_NVCC_FLAGS} -fopenmp)
elseif (THRUST_BACKEND STREQUAL "OMP")
find_package(OpenMP REQUIRED)
set(MANIFOLD_INCLUDE OpenMP::OpenMP_CXX)
set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_OMP -fopenmp)
elseif (THRUST_BACKEND STREQUAL "CPP")
set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP)
else ()
message(FATAL_ERROR "Invalid value for THRUST_BACKEND: ${THRUST_BACKEND}. "
"Should be one of \"CUDA\", \"OMP\", \"CPP\" or \"TBB\"")
"Should be one of \"CUDA\", \"OMP\", \"CPP\"")
endif()

add_subdirectory(utilities)
Expand Down
24 changes: 16 additions & 8 deletions utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ project (utilities)

add_library(${PROJECT_NAME} src/detect_cuda.cpp)

target_include_directories(${PROJECT_NAME} INTERFACE ${THRUST_INC_DIR} ${GLM_INC_DIR})
target_include_directories(${PROJECT_NAME}
INTERFACE
${PROJECT_SOURCE_DIR}/include
)
target_compile_options(${PROJECT_NAME}
PRIVATE ${MANIFOLD_FLAGS}
)
target_include_directories(${PROJECT_NAME} PUBLIC ${THRUST_INC_DIR} ${GLM_INC_DIR})
if(THRUST_BACKEND STREQUAL "CUDA")
set_source_files_properties(src/detect_cuda.cpp PROPERTIES LANGUAGE CUDA)
set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_ARCHITECTURES 61)
target_compile_options(${PROJECT_NAME}
PRIVATE ${MANIFOLD_NVCC_FLAGS}
)
target_compile_options(${PROJECT_NAME}
PRIVATE "$<$<CONFIG:RELEASE>:${MANIFOLD_NVCC_RELEASE_FLAGS}>" "$<$<CONFIG:DEBUG>:${MANIFOLD_NVCC_DEBUG_FLAGS}>"
)
else()
target_compile_options(${PROJECT_NAME}
PRIVATE ${MANIFOLD_FLAGS}
)
endif()
target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR}/include)
2 changes: 2 additions & 0 deletions utilities/include/vec_dh.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#pragma once
#include <chrono>
#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
#include <cuda.h>
#endif
#include <iostream>
#include <thrust/execution_policy.h>
#include <thrust/uninitialized_copy.h>
Expand Down
5 changes: 4 additions & 1 deletion utilities/src/detect_cuda.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "thrust/execution_policy.h"
#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
#include <cuda_runtime.h>

Expand All @@ -10,5 +11,7 @@ void check_cuda_available() {
}
}
#else
void manifold::check_cuda_available() {}
namespace manifold {
void check_cuda_available() {}
}
#endif

0 comments on commit c6f4d9d

Please sign in to comment.