Skip to content

Commit 639cf78

Browse files
committed
add 3rdparty/ngfx/ngfx.cmake capable of finding the NSight GFX SDK & creating interface ngfx interface target on success, allow for picking found versions
1 parent 69cd5d2 commit 639cf78

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

3rdparty/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ NBL_ADD_GIT_TRACKING_META_LIBRARY(nabla "${NBL_ROOT_PATH}")
296296
NBL_ADD_GIT_TRACKING_META_LIBRARY(dxc "${CMAKE_CURRENT_SOURCE_DIR}/dxc/dxc")
297297
NBL_GENERATE_GIT_TRACKING_META()
298298

299+
# NGFX
300+
include(ngfx/ngfx.cmake)
301+
299302
if(NBL_BUILD_IMGUI)
300303
set(NBL_IMGUI_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/imgui")
301304
set(NBL_IMGUI_TEST_ENGINE_PROJECT_ROOT "${THIRD_PARTY_SOURCE_DIR}/imgui_test_engine")

3rdparty/ngfx/ngfx.cmake

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
option(NBL_BUILD_WITH_NGFX "Enable NGFX build" OFF)
2+
3+
# NOTE: on windows default installation path is:
4+
# "C:/Program Files/NVIDIA Corporation/Nsight Graphics <version>/SDKs/NsightGraphicsSDK" <- define as "NGFX_SDK" environment variable
5+
# then you can pick SDK version with "NGFX_SDK_VERSION" cache variable (CMake GUI list supported)
6+
7+
if(NBL_BUILD_WITH_NGFX)
8+
if(NOT DEFINED ENV{NGFX_SDK})
9+
message(FATAL_ERROR "\"NGFX_SDK\" environment variable must be defined to build with NBL_BUILD_WITH_NGFX enabled!")
10+
endif()
11+
12+
set(NGFX_SDK "$ENV{NGFX_SDK}")
13+
cmake_path(NORMAL_PATH NGFX_SDK OUTPUT_VARIABLE NGFX_SDK)
14+
15+
if(NOT EXISTS "${NGFX_SDK}")
16+
message(FATAL_ERROR "Found \"NGFX_SDK\" environment variable but it is invalid, env:NGFX_SDK=\"${NGFX_SDK}\" doesn't exist!")
17+
endif()
18+
19+
file(GLOB ENTRIES "${NGFX_SDK}/*")
20+
21+
set(NGFX_VERSIONS "")
22+
foreach(ENTRY ${ENTRIES})
23+
if(IS_DIRECTORY ${ENTRY})
24+
list(APPEND NGFX_VERSIONS ${ENTRY})
25+
endif()
26+
endforeach()
27+
28+
if(NOT NGFX_VERSIONS)
29+
message(FATAL_ERROR "Could not find any NGFX SDK Version!")
30+
endif()
31+
32+
list(TRANSFORM NGFX_VERSIONS REPLACE "${NGFX_SDK}/" "")
33+
list(SORT NGFX_VERSIONS)
34+
list(GET NGFX_VERSIONS -1 LATEST_NGFX_VERSION)
35+
36+
# on the cache variable init pick the latest version, then let user pick from list
37+
set(NGFX_SDK_VERSION "${LATEST_NGFX_VERSION}" CACHE STRING "NGFX SDK Version")
38+
set_property(CACHE NGFX_SDK_VERSION PROPERTY STRINGS ${NGFX_VERSIONS})
39+
40+
set(NGFX_SDK_BASE "${NGFX_SDK}/$CACHE{NGFX_SDK_VERSION}")
41+
42+
# TODO: wanna support more *host* platforms? (*)
43+
# NOTE: also I'm hardcoding windows x64 library requests till I know the answer for (*)
44+
find_file(NBL_NGFX_INJECTION_HEADER NGFX_Injection.h PATHS ${NGFX_SDK_BASE}/include)
45+
find_file(NBL_NGFX_INJECTION_DLL NGFX_Injection.dll PATHS ${NGFX_SDK_BASE}/lib/x64)
46+
find_file(NBL_NGFX_INJECTION_IMPORT_LIBRARY NGFX_Injection.lib PATHS ${NGFX_SDK_BASE}/lib/x64)
47+
48+
if(NBL_NGFX_INJECTION_HEADER AND NBL_NGFX_INJECTION_DLL AND NBL_NGFX_INJECTION_IMPORT_LIBRARY)
49+
message(STATUS "Enabled build with NVIDIA Nsight Graphics SDK $CACHE{NGFX_SDK_VERSION}\nlocated in: \"${NGFX_SDK_BASE}\"")
50+
else()
51+
message(STATUS "Could not enable build with NVIDIA Nsight Graphics SDK $CACHE{NGFX_SDK_VERSION} - invalid components!")
52+
message(STATUS "Located in: \"${NGFX_SDK_BASE}\"")
53+
message(STATUS "NBL_NGFX_INJECTION_HEADER=\"${NBL_NGFX_INJECTION_HEADER}\"")
54+
message(STATUS "NBL_NGFX_INJECTION_DLL=\"${NBL_NGFX_INJECTION_DLL}\"")
55+
message(STATUS "NBL_NGFX_INJECTION_IMPORT_LIBRARY=\"${NBL_NGFX_INJECTION_IMPORT_LIBRARY}\"")
56+
message(FATAL_ERROR "You installation may be corupted, please fix it and re-run CMake or disable NBL_BUILD_WITH_NGFX!")
57+
endif()
58+
59+
add_library(ngfx INTERFACE)
60+
target_sources(ngfx INTERFACE "${NBL_NGFX_INJECTION_HEADER}")
61+
target_include_directories(ngfx INTERFACE "${NGFX_SDK_BASE}/include")
62+
target_link_libraries(ngfx INTERFACE "${NBL_NGFX_INJECTION_IMPORT_LIBRARY}")
63+
endif()

0 commit comments

Comments
 (0)