Skip to content

Commit

Permalink
CMake: add option to disable building of executable
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom94 committed Feb 14, 2023
1 parent f7b465f commit b1124c6
Showing 1 changed file with 20 additions and 31 deletions.
51 changes: 20 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if (NOT NGP_DEPLOY)
set(NGP_VERSION "${NGP_VERSION}dev")
endif()

option(NGP_BUILD_EXECUTABLE "Build instant-ngp.exe?" ON)
option(NGP_BUILD_WITH_GUI "Build with GUI support (requires GLFW and GLEW)?" ON)
option(NGP_BUILD_WITH_OPTIX "Build with OptiX to enable hardware ray tracing?" ON)
option(NGP_BUILD_WITH_PYTHON_BINDINGS "Build bindings that allow instrumenting instant-ngp with Python?" ON)
Expand Down Expand Up @@ -332,10 +333,7 @@ target_include_directories(ngp PUBLIC ${NGP_INCLUDE_DIRECTORIES})
target_link_directories(ngp PUBLIC ${NGP_LINK_DIRECTORIES})
target_link_libraries(ngp PUBLIC ${NGP_LIBRARIES} tiny-cuda-nn)

add_executable(instant-ngp src/main.cu)
target_link_libraries(instant-ngp PRIVATE ngp)

# Copy DLSS shared libraries
# Copy shared libraries to the binary directory as needed
if (NGP_VULKAN)
set(NGX_BUILD_DIR "$<IF:$<CONFIG:Debug>,dev,rel>")
if (MSVC)
Expand All @@ -344,23 +342,32 @@ if (NGP_VULKAN)
set(NGX_SHARED_LIB "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/dlss/lib/Linux_x86_64/${NGX_BUILD_DIR}/libnvidia-ngx-dlss.so.*")
endif()

add_custom_command(TARGET instant-ngp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${NGX_SHARED_LIB}" $<TARGET_FILE_DIR:instant-ngp>
COMMAND_EXPAND_LISTS
)
add_custom_command(TARGET ngp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${NGX_SHARED_LIB}" "${CMAKE_CURRENT_BINARY_DIR}" COMMAND_EXPAND_LISTS)
endif()

if (MSVC)
# Copy CUDA runtime DLLs to the build directory so that Python can find them.
file(GLOB CUDA_DLLS "${CUDA_COMPILER_BIN}/cudart64*.dll")
if (CUDA_DLLS)
add_custom_command(TARGET instant-ngp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CUDA_DLLS} $<TARGET_FILE_DIR:instant-ngp>
COMMAND_EXPAND_LISTS
)
add_custom_command(TARGET ngp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CUDA_DLLS} "${CMAKE_CURRENT_BINARY_DIR}" COMMAND_EXPAND_LISTS)
endif()
endif()

if (NGP_BUILD_EXECUTABLE)
add_executable(instant-ngp src/main.cu)
target_link_libraries(instant-ngp PRIVATE ngp)

# Link the executable to the project directory and copy over DLLs such that instant-ngp can be invoked without going into the build folder.
set(NGP_BINARY_FILE "\"${CMAKE_CURRENT_SOURCE_DIR}/$<TARGET_FILE_NAME:instant-ngp>\"")
if (MSVC)
add_custom_command(TARGET instant-ngp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:instant-ngp> ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB NGP_REQUIRED_DLLS "${CMAKE_CURRENT_BINARY_DIR}/*.dll")
if (NGP_REQUIRED_DLLS)
add_custom_command(TARGET instant-ngp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${NGP_REQUIRED_DLLS} ${CMAKE_CURRENT_SOURCE_DIR} COMMAND_EXPAND_LISTS)
endif()
else()
add_custom_command(TARGET instant-ngp POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:instant-ngp> "${NGP_BINARY_FILE}")
endif()
endif(NGP_BUILD_EXECUTABLE)

if (Python_FOUND)
add_library(pyngp SHARED src/python_api.cu)
Expand All @@ -369,21 +376,3 @@ if (Python_FOUND)
target_compile_definitions(pyngp PUBLIC -DNGP_PYTHON)
pybind11_extension(pyngp)
endif()

# Link the executable to the project directory and copy over DLLs such that instant-ngp can be invoked without going into the build folder.
set(NGP_BINARY_FILE "\"${CMAKE_CURRENT_SOURCE_DIR}/$<TARGET_FILE_NAME:instant-ngp>\"")
if (MSVC)
add_custom_command(TARGET instant-ngp POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:instant-ngp> ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB NGP_REQUIRED_DLLS "${CUDA_COMPILER_BIN}/cudart64*.dll")
if (NGP_VULKAN)
list(APPEND NGP_REQUIRED_DLLS "${NGX_SHARED_LIB}")
endif()
if (NGP_REQUIRED_DLLS)
add_custom_command(TARGET instant-ngp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${NGP_REQUIRED_DLLS} ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND_EXPAND_LISTS
)
endif()
else()
add_custom_command(TARGET instant-ngp POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE:instant-ngp> "${NGP_BINARY_FILE}")
endif()

0 comments on commit b1124c6

Please sign in to comment.