Skip to content

Commit

Permalink
Merge pull request #42 from Hineven/main
Browse files Browse the repository at this point in the history
Update CMakeFile.txt.
Fix optix finding routines.

Co-Authored-By: Hineven <hinevenwob@qq.com>
  • Loading branch information
cuteday and Hineven committed Nov 2, 2023
2 parents 6d3ff20 + fb1a13a commit 748b3d6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 55 deletions.
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,31 @@ else()
message("Do not find python, disable python binding")
endif()

# Resolve the atlbase.h issue when building with IDEs other than Visual Studio
if(${CMAKE_CXX_COMPILER_ID} EQUAL MSVC)
# atlbase.h is required under Windows build.
# Test for the presense of "atlbase.h"
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX("atlbase.h" HAVE_ATLBASE_H)
# Try to find atlbase.h within MSVC
if(NOT HAVE_ATLBASE_H)
message(STATUS "atlbase.h not found. Trying to find it within atlmfc directory in the current MSVC installation.")
# Find MSVC executable directory
get_filename_component(MSVC_EXECUTABLE_DIR ${CMAKE_CXX_COMPILER} DIRECTORY)
# Try to find atlmfc directory within the current toolchain directory
find_path(ATLMFC_INCLUDE_DIR "atlmfc" PATHS "${MSVC_DIR}/../../..")
# If atlmfc directory is found, append it to the include directories
if(ATLMFC_INCLUDE_DIR)
message(STATUS "Found atlmfc directory at ${ATLMFC_INCLUDE_DIR}")
# Include atlbase.h
include_directories(${ATLMFC_INCLUDE_DIR})
else()
message(FATAL_ERROR "atlmfc directory not found. Please specify it manually.")
endif()
endif()
endif()


ADD_SUBDIRECTORY (src)
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
SET (KRR_INCLUDE_DIRS ${KRR_INCLUDE_DIRS} PARENT_SCOPE) # exporting KRR_INCLUDE_DIRS to parent scope
Expand Down
90 changes: 37 additions & 53 deletions common/build/FindOptiX.cmake
Original file line number Diff line number Diff line change
@@ -1,55 +1,39 @@
# Locate the OptiX distribution. Search relative to the SDK first, then look in the system.

# Our initial guess will be within the SDK.

if (DEFINED ENV{OptiX_INSTALL_DIR})
set (OptiX_INSTALL_DIR $ENV{OptiX_INSTALL_DIR})
set (searched_OptiX_INSTALL_DIR ${OptiX_INSTALL_DIR})
elseif(NOT OptiX_INSTALL_DIR)
if (WIN32)
find_path(searched_OptiX_INSTALL_DIR
NAME include/optix.h
PATHS
"C:/ProgramData/NVIDIA Corporation/OptiX SDK 8.0.0"
"C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.7.0"
"C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.6.0"
"C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.5.0"
"C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.4.0"
"C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.3.0"
"C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.2.0"
"C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.1.0"
"C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.0.0"
"C:/ProgramData/NVIDIA Corporation/OptiX SDK *"
)
endif()
################################################################################
# Optix
################################################################################
if(NOT DEFINED ENV{OptiX_INSTALL_DIR} AND NOT DEFINED OptiX_INSTALL_DIR)
if(NOT DEFINED ENV{OPTIX_ROOT})
message("Try to find OptiX SDK in PROGRAMDATA directory.")
if(NOT DEFINED ENV{PROGRAMDATA})
message(FATAL_ERROR "PROGRAMDATA is not defined. OPTIX_ROOT has to be specified manually.")
else()
# Transform the path to generic style
file(TO_CMAKE_PATH "$ENV{PROGRAMDATA}" PROGRAMDATA)
# Find the directory with prefix of "OptiX SDK" in PROGRAMDATA directory
file(GLOB OPTIX_ROOT "${PROGRAMDATA}/NVIDIA Corporation/OptiX SDK*")
# If there are multiple directories, use the first one
list(GET OPTIX_ROOT 0 OPTIX_ROOT)
# If there is no directory, popup an error message
if(NOT OPTIX_ROOT)
message(FATAL_ERROR "OPTIX_ROOT has to be specified manually.")
else ()
message(STATUS "Found OptiX SDK at ${OPTIX_ROOT}")
endif()
endif()
else()
set( OPTIX_ROOT $ENV{OPTIX_ROOT} )
endif()
else()
if(DEFINED ENV{OptiX_INSTALL_DIR})
set( OPTIX_ROOT $ENV{OptiX_INSTALL_DIR} )
else()
set( OPTIX_ROOT ${OptiX_INSTALL_DIR} )
endif()
message(STATUS "Using specified OptiX path at ${OPTIX_ROOT}")
endif()
mark_as_advanced(searched_OptiX_INSTALL_DIR)
set(OptiX_INSTALL_DIR ${searched_OptiX_INSTALL_DIR} CACHE PATH "Path to OptiX installed location.")
set(OptiX_ROOT_DIR ${searched_OptiX_INSTALL_DIR} CACHE PATH "Path to OptiX installed location.")
set(OptiX_INSTALL_DIR $ENV{OptiX_INSTALL_DIR} CACHE PATH "Path to OptiX installed location.")
set(OptiX_ROOT_DIR ${searched_OptiX_INSTALL_DIR} CACHE PATH "Path to OptiX installed location.")

# Include
find_path(OptiX_INCLUDE
NAMES optix.h
PATHS "${OptiX_INSTALL_DIR}/include"
NO_DEFAULT_PATH
)
find_path(OptiX_INCLUDE
NAMES optix.h
)

# Check to make sure we found what we were looking for
function(OptiX_report_error error_message required)
if(OptiX_FIND_REQUIRED AND required)
message(FATAL_ERROR "${error_message}")
else()
if(NOT OptiX_FIND_QUIETLY)
message(STATUS "${error_message}")
endif(NOT OptiX_FIND_QUIETLY)
endif()
endfunction()

if(NOT OptiX_INCLUDE)
OptiX_report_error("OptiX headers (optix.h and friends) not found. Please locate before proceeding." TRUE)
endif()
message(STATUS "Found OptiX SDK at ${OPTIX_ROOT}")
# Guess the OptiX install directory by OPTIX_ROOT
set(OptiX_INSTALL_DIR ${OPTIX_ROOT} CACHE PATH "Path to OptiX installation location")
# Include the OptiX header directory
set(OptiX_INCLUDE_DIR ${OPTIX_ROOT}/include CACHE PATH "Path to OptiX include directory")
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ADD_SUBDIRECTORY(${KRR_RENDER_SOURCE_DIR}/core/math)
MESSAGE ("Source directory: ${KRR_RENDER_SOURCE_DIR}")
MESSAGE ("Build output directory: ${CMAKE_BINARY_DIR}")
MESSAGE ("CUDA include directory: ${CUDA_INCLUDE_DIRS}")
MESSAGE ("Optix include directory: ${OptiX_INCLUDE}")
MESSAGE ("Optix include directory: ${OptiX_INCLUDE_DIR}")

INCLUDE (${KRR_RENDER_ROOT}/common/build/source.cmake)

Expand Down Expand Up @@ -47,7 +47,7 @@ ADD_DEPENDENCIES (krr_lib krr_soa_generated)
SET_PROPERTY(TARGET krr_lib PROPERTY CUDA_SEPARABLE_COMPILATION ON)
SET_PROPERTY(TARGET krr_lib PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON)
TARGET_COMPILE_DEFINITIONS (krr_lib PUBLIC ${KRR_DEFINITIONS})
TARGET_INCLUDE_DIRECTORIES (krr_lib SYSTEM PUBLIC ${KRR_INCLUDE_ALL} ${OptiX_INCLUDE})
TARGET_INCLUDE_DIRECTORIES (krr_lib SYSTEM PUBLIC ${KRR_INCLUDE_ALL} ${OptiX_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(krr_lib PUBLIC ${KRR_SECONDARY_LIBS_ALL})
TARGET_LINK_OPTIONS(krr_lib PUBLIC "LINKER:/NODEFAULTLIB:LIBCMT")

Expand Down

0 comments on commit 748b3d6

Please sign in to comment.