-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
115 lines (91 loc) · 4.84 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Many pieces of this file came from libigl-example-project and gptoolbox for mex compilation.
cmake_minimum_required(VERSION 3.20)
project(smooth_distance LANGUAGES CXX)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# libigl
option(LIBIGL_OPENGL "Use OpenGL" ON)
option(LIBIGL_GLFW "Use GLFW" ON)
option(LIBIGL_IMGUI "Use ImGui" ON)
option(LIBIGL_PNG "Use PNG" ON)
find_package(Matlab COMPONENTS MEX_COMPILER MX_LIBRARY ENG_LIBRARY MAT_LIBRARY)
if(Matlab_FOUND)
option(LIBIGL_RESTRICTED_MATLAB "Use Matlab" ON)
endif()
include(FetchContent)
include(pybind11)
#find_package(LIBIGL REQUIRED QUIET)
include(libigl)
# Add your project files
file(GLOB SRCFILES "src/*.cpp")
file(GLOB INCFILES "include/*.h" "include/*.hpp")
add_library(smooth_dist_cpu STATIC ${SRCFILES} ${INCFILES})
target_link_libraries(smooth_dist_cpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
target_include_directories(smooth_dist_cpu PUBLIC include)
add_executable(scene_builder app/scene_builder.cpp)
target_link_libraries(scene_builder smooth_dist_cpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
add_executable(benchmark_cpu app/benchmark_cpu.cpp)
target_link_libraries(benchmark_cpu smooth_dist_cpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
add_executable(beta_error_test app/beta_error_test.cpp)
target_link_libraries(beta_error_test smooth_dist_cpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
add_executable(barnes_hut_smoothness_test app/barnes_hut_smoothness_test.cpp)
target_link_libraries(barnes_hut_smoothness_test smooth_dist_cpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
add_executable(rigid_body_simulator app/rigid_body_simulator.cpp)
target_link_libraries(rigid_body_simulator smooth_dist_cpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
pybind11_add_module(smoothdists_bindings plugin/smoothdists_bindings.cpp)
target_link_libraries(smoothdists_bindings PUBLIC smooth_dist_cpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
# mex compilation
if(Matlab_FOUND)
# Based on gptoolbox
set( CMAKE_SHARED_LIBRARY_SUFFIX ".${Matlab_MEX_EXTENSION}" ) # set suffix to .mexa64
set( CMAKE_SHARED_LIBRARY_PREFIX ) # remove the "lib" prefix
set( CMAKE_SHARED_LIBRARY_CXX_FLAGS ) # remove the -fPIC option. mex does not accept the "-fPIC" option
set( CMAKE_POSITION_INDEPENDENT_CODE ON)
set( CMAKE_INSTALL_RPATH "\$ORIGIN" )
function(compile_each I_MEX_SOURCES I_LIBS )
foreach(MEX_SOURCE ${I_MEX_SOURCES})
message(STATUS "MEX_SOURCE: ${MEX_SOURCE}")
get_filename_component(MEX_OUTPUT ${MEX_SOURCE} NAME_WE)
add_library(${MEX_OUTPUT} SHARED ${MEX_SOURCE})
# Not sure if this should be (WIN32) or (MSVC OR MSYS OR MINGW)
# https://stackoverflow.com/a/40152725/148668
if(WIN32)
# https://stackoverflow.com/a/11095194/148668
set_target_properties(${MEX_OUTPUT} PROPERTIES LINK_FLAGS "/export:mexFunction")
endif()
target_link_libraries(${MEX_OUTPUT} ${I_LIBS})
target_include_directories(${MEX_OUTPUT} PUBLIC ${Matlab_INCLUDE_DIRS})
#list(APPEND MEX_OUTPUTS ${MEX_OUTPUT})
endforeach()
endfunction()
#file( GLOB MEX_SOURCES *.cpp )
list(APPEND CORE_LIBS ${Matlab_LIBRARIES})
add_definitions("-DMEX")
compile_each("mex/build_distance_bvh.cpp" "${CORE_LIBS};igl::core;igl_restricted::matlab;smooth_dist_cpu")
compile_each("mex/smooth_min_distance.cpp" "${CORE_LIBS};igl::core;igl_restricted::matlab;smooth_dist_cpu")
endif()
# Cuda compilation
find_package(CUDA)
if(CUDA_FOUND)
cmake_policy(SET CMP0104 NEW)
enable_language(CUDA)
file(GLOB SRCFILES_GPU "src/*.cu")
set(SRCFILES_GPU_HOST_ONLY ${SRCFILES})
foreach(F IN LISTS SRCFILES_GPU)
string(REPLACE ".cu" ".cpp" F_CPP ${F})
list(REMOVE_ITEM SRCFILES_GPU_HOST_ONLY ${F_CPP})
endforeach()
set(CUDA_USE_STATIC_CUDA_RUNTIME ON)
include_directories(${CUDA_TOOLKIT_INCLUDE})
add_library(smooth_dist_gpu STATIC ${SRCFILES_GPU} ${SRCFILES_GPU_HOST_ONLY} ${INCFILES})
target_link_libraries(smooth_dist_gpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
target_include_directories(smooth_dist_gpu PUBLIC include)
set_target_properties(smooth_dist_gpu PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
add_executable(sphere_tracer_gpu app/sphere_tracer_gpu.cu)
target_link_libraries(sphere_tracer_gpu smooth_dist_gpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
set_target_properties(sphere_tracer_gpu PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
add_executable(benchmark_gpu app/benchmark_gpu.cu)
target_link_libraries(benchmark_gpu smooth_dist_gpu igl::core igl::opengl igl::glfw igl::imgui igl::png)
set_target_properties(benchmark_gpu PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
endif()