@@ -12,9 +12,12 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
1212set_property (GLOBAL PROPERTY USE_FOLDERS ON )
1313
1414option (VEFC_BUILD_DEMO "Build the OpenGL demo." ON )
15+ option (VEFC_BUILD_DX11 "Build the Direct3D 11 demo." ON )
1516option (VEFC_BUILD_TESTS "Build the unit tests." ON )
1617option (VEFC_ENABLE_HARFBUZZ "Enable HarfBuzz-backed shaping support." ON )
1718option (VEFC_ENABLE_FREETYPE "Enable FreeType CPU rasterisation support." ON )
19+ option (VEFC_BUILD_VRHI "Build VRHI backend demo." OFF )
20+ set (VRHI_VERSION "v0.1.4" CACHE STRING "VRHI release version to fetch" )
1821
1922include (FetchContent )
2023
@@ -40,6 +43,142 @@ if(VEFC_ENABLE_HARFBUZZ)
4043 FetchContent_MakeAvailable (harfbuzz)
4144endif ()
4245
46+ if (VEFC_BUILD_VRHI)
47+ FetchContent_Declare (
48+ glfw
49+ GIT_REPOSITORY https://github.com/glfw/glfw.git
50+ GIT_TAG 3.4
51+ )
52+ set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
53+ set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE )
54+ set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE )
55+ FetchContent_MakeAvailable (glfw)
56+
57+ find_package (Vulkan REQUIRED )
58+
59+ if (WIN32 )
60+ set (VRHI_PLATFORM "windows-x64" )
61+ elseif (UNIX AND NOT APPLE )
62+ set (VRHI_PLATFORM "linux-x64" )
63+ elseif (APPLE )
64+ set (VRHI_PLATFORM "macos-arm64" )
65+ endif ()
66+
67+ FetchContent_Declare (
68+ vrhi
69+ URL "https://github.com/hypernewbie/vrhi/releases/download/${VRHI_VERSION} /vrhi-${VRHI_VERSION} -${VRHI_PLATFORM} .zip"
70+ SOURCE_DIR "${CMAKE_BINARY_DIR} /_deps/vrhi-src"
71+ )
72+ FetchContent_Declare (
73+ vrhi_debug
74+ URL "https://github.com/hypernewbie/vrhi/releases/download/${VRHI_VERSION} /vrhi-${VRHI_VERSION} -${VRHI_PLATFORM} -debug.zip"
75+ SOURCE_DIR "${CMAKE_BINARY_DIR} /_deps/vrhi-debug-src"
76+ )
77+ FetchContent_MakeAvailable (vrhi vrhi_debug)
78+
79+ set (VEFC_VRHI_RELEASE_ROOT "${CMAKE_BINARY_DIR} /_deps/vrhi-src" )
80+ set (VEFC_VRHI_DEBUG_ROOT "${CMAKE_BINARY_DIR} /_deps/vrhi-debug-src" )
81+ set (VEFC_VRHI_INCLUDE_DIR "${VEFC_VRHI_RELEASE_ROOT} /include" )
82+ set (VEFC_VRHI_RELEASE_LIB_DIR "${VEFC_VRHI_RELEASE_ROOT} /lib" )
83+ set (VEFC_VRHI_DEBUG_LIB_DIR "${VEFC_VRHI_DEBUG_ROOT} /lib" )
84+
85+ function (vefc_vrhi_find_library out_var lib_dir )
86+ cmake_parse_arguments (ARG "" "" "NAMES" ${ARGN} )
87+ if (NOT ARG_NAMES)
88+ message (FATAL_ERROR "vefc_vrhi_find_library requires at least one library name." )
89+ endif ()
90+
91+ unset (_vefc_vrhi_library CACHE )
92+ unset (_vefc_vrhi_library)
93+ find_library (_vefc_vrhi_library
94+ NAMES ${ARG_NAMES}
95+ HINTS "${lib_dir} "
96+ NO_DEFAULT_PATH
97+ )
98+ if (NOT _vefc_vrhi_library)
99+ message (FATAL_ERROR "Could not find any of [${ARG_NAMES} ] in ${lib_dir} " )
100+ endif ()
101+
102+ set (${out_var} "${_vefc_vrhi_library} " PARENT_SCOPE )
103+ endfunction ()
104+
105+ function (vefc_add_configured_imported_library target_name release_path debug_path )
106+ add_library (${target_name} UNKNOWN IMPORTED )
107+ set_target_properties (${target_name} PROPERTIES
108+ IMPORTED_LOCATION_DEBUG "${debug_path} "
109+ IMPORTED_LOCATION_RELEASE "${release_path} "
110+ IMPORTED_LOCATION_RELWITHDEBINFO "${release_path} "
111+ IMPORTED_LOCATION_MINSIZEREL "${release_path} "
112+ )
113+ endfunction ()
114+
115+ foreach (_vefc_vrhi_lib IN ITEMS vrhi nvrhi nvrhi_vk vk-bootstrap rtxmu SPIRV-Tools SPIRV-Tools-opt)
116+ string (REPLACE "-" "_" _vefc_vrhi_var "${_vefc_vrhi_lib} " )
117+ vefc_vrhi_find_library (VEFC_VRHI_${_vefc_vrhi_var}_RELEASE "${VEFC_VRHI_RELEASE_LIB_DIR} " NAMES "${_vefc_vrhi_lib} " )
118+ vefc_vrhi_find_library (VEFC_VRHI_${_vefc_vrhi_var}_DEBUG "${VEFC_VRHI_DEBUG_LIB_DIR} " NAMES "${_vefc_vrhi_lib} " )
119+ vefc_add_configured_imported_library (
120+ vefc_vrhi_${_vefc_vrhi_var}
121+ "${VEFC_VRHI_${_vefc_vrhi_var} _RELEASE}"
122+ "${VEFC_VRHI_${_vefc_vrhi_var} _DEBUG}"
123+ )
124+ endforeach ()
125+
126+ get_filename_component (VULKAN_SDK_LIB_DIR "${Vulkan_LIBRARY} " DIRECTORY )
127+ set (VEFC_SLANG_HINT_DIRS
128+ "${VULKAN_SDK_LIB_DIR} "
129+ "${VULKAN_SDK_LIB_DIR} /../lib"
130+ "${VULKAN_SDK_LIB_DIR} /../lib64"
131+ "${VULKAN_SDK_LIB_DIR} /../Bin"
132+ "${VULKAN_SDK_LIB_DIR} /../bin"
133+ "${VULKAN_SDK_LIB_DIR} /../macOS/lib"
134+ )
135+ list (REMOVE_DUPLICATES VEFC_SLANG_HINT_DIRS)
136+
137+ find_library (SLANG_LIBRARY
138+ NAMES slang
139+ HINTS ${VEFC_SLANG_HINT_DIRS}
140+ NO_DEFAULT_PATH
141+ )
142+ if (NOT SLANG_LIBRARY)
143+ message (FATAL_ERROR "Could not find Slang in Vulkan SDK hints: ${VEFC_SLANG_HINT_DIRS} " )
144+ endif ()
145+
146+ set (VEFC_SLANG_RPATH_DIRS)
147+ get_filename_component (SLANG_LIBRARY_DIR "${SLANG_LIBRARY} " DIRECTORY )
148+ list (APPEND VEFC_SLANG_RPATH_DIRS "${SLANG_LIBRARY_DIR} " )
149+
150+ find_library (SLANG_RT_LIBRARY
151+ NAMES slang-rt
152+ HINTS ${VEFC_SLANG_HINT_DIRS}
153+ NO_DEFAULT_PATH
154+ )
155+ if (SLANG_RT_LIBRARY)
156+ get_filename_component (SLANG_RT_LIBRARY_DIR "${SLANG_RT_LIBRARY} " DIRECTORY )
157+ list (APPEND VEFC_SLANG_RPATH_DIRS "${SLANG_RT_LIBRARY_DIR} " )
158+ endif ()
159+ list (REMOVE_DUPLICATES VEFC_SLANG_RPATH_DIRS)
160+
161+ if (WIN32 )
162+ find_file (SLANG_DLL
163+ NAMES slang.dll
164+ HINTS "${VULKAN_SDK_LIB_DIR} /../Bin" "${VULKAN_SDK_LIB_DIR} /../bin"
165+ NO_DEFAULT_PATH
166+ )
167+ find_file (SLANG_RT_DLL
168+ NAMES slang-rt.dll
169+ HINTS "${VULKAN_SDK_LIB_DIR} /../Bin" "${VULKAN_SDK_LIB_DIR} /../bin"
170+ NO_DEFAULT_PATH
171+ )
172+ if (NOT SLANG_DLL OR NOT SLANG_RT_DLL)
173+ message (FATAL_ERROR "Could not find slang.dll and slang-rt.dll in Vulkan SDK runtime directories." )
174+ endif ()
175+ endif ()
176+
177+ message (STATUS "VRHI Release: ${VEFC_VRHI_RELEASE_ROOT} " )
178+ message (STATUS "VRHI Debug: ${VEFC_VRHI_DEBUG_ROOT} " )
179+ message (STATUS "Using Slang: ${SLANG_LIBRARY} " )
180+ endif ()
181+
43182function (vefc_apply_common_options target )
44183 target_compile_features (${target} PRIVATE cxx_std_20 )
45184 target_include_directories (${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} )
@@ -94,27 +233,128 @@ if(VEFC_BUILD_DEMO)
94233 )
95234 vefc_apply_common_options (demo )
96235 vefc_apply_features (demo ${VEFC_ENABLE_HARFBUZZ} ${VEFC_ENABLE_FREETYPE} )
236+ endif ()
237+
238+ if (WIN32 AND VEFC_BUILD_DX11)
239+ add_executable (vefc_demo_dx11
240+ demo/demo_dx11.cpp
241+ )
242+ set_target_properties (vefc_demo_dx11 PROPERTIES
243+ VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} /demo"
244+ )
245+ target_link_libraries (vefc_demo_dx11 PRIVATE
246+ d3d11
247+ d3dcompiler
248+ dxgi
249+ user32
250+ )
251+ vefc_apply_common_options (vefc_demo_dx11 )
252+ vefc_apply_features (vefc_demo_dx11 ${VEFC_ENABLE_HARFBUZZ} ${VEFC_ENABLE_FREETYPE} )
253+ endif ()
254+
255+ if (VEFC_BUILD_VRHI)
256+ add_executable (vefc_demo_vrhi
257+ demo/demo_vrhi.cpp
258+ )
259+ set_target_properties (vefc_demo_vrhi PROPERTIES
260+ VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} /demo"
261+ )
262+
263+ target_include_directories (vefc_demo_vrhi PRIVATE
264+ ${VEFC_VRHI_INCLUDE_DIR}
265+ )
266+
267+ vefc_apply_common_options (vefc_demo_vrhi )
268+ vefc_apply_features (vefc_demo_vrhi ${VEFC_ENABLE_HARFBUZZ} ${VEFC_ENABLE_FREETYPE} )
269+
270+ target_link_libraries (vefc_demo_vrhi PRIVATE
271+ vefc_vrhi_vrhi
272+ vefc_vrhi_nvrhi
273+ vefc_vrhi_nvrhi_vk
274+ vefc_vrhi_vk_bootstrap
275+ vefc_vrhi_rtxmu
276+ vefc_vrhi_SPIRV_Tools
277+ vefc_vrhi_SPIRV_Tools_opt
278+ ${SLANG_LIBRARY}
279+ Vulkan::Vulkan
280+ glfw
281+ )
282+
283+ if (UNIX )
284+ set_target_properties (vefc_demo_vrhi PROPERTIES
285+ BUILD_RPATH "${VEFC_SLANG_RPATH_DIRS} "
286+ )
287+ endif ()
97288
98289 if (WIN32 )
99- add_executable (vefc_demo_dx11
100- demo/demo_dx11.cpp
290+ target_link_libraries (vefc_demo_vrhi PRIVATE user32 gdi32 )
291+
292+ add_custom_command (TARGET vefc_demo_vrhi POST_BUILD
293+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
294+ ${SLANG_DLL}
295+ $<TARGET_FILE_DIR :vefc_demo_vrhi >/
296+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
297+ ${SLANG_RT_DLL}
298+ $<TARGET_FILE_DIR :vefc_demo_vrhi >/
101299 )
102- set_target_properties (vefc_demo_dx11 PROPERTIES
103- VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} /demo"
300+ elseif (UNIX AND NOT APPLE )
301+ target_link_libraries (vefc_demo_vrhi PRIVATE dl pthread xcb X11 Xrandr Xi )
302+ endif ()
303+ endif ()
304+
305+ set (VEFC_DEMO_BACKEND_TEST_TARGETS)
306+ if (TARGET demo)
307+ list (APPEND VEFC_DEMO_BACKEND_TEST_TARGETS demo)
308+ endif ()
309+ if (TARGET vefc_demo_dx11)
310+ list (APPEND VEFC_DEMO_BACKEND_TEST_TARGETS vefc_demo_dx11)
311+ endif ()
312+ if (TARGET vefc_demo_vrhi)
313+ list (APPEND VEFC_DEMO_BACKEND_TEST_TARGETS vefc_demo_vrhi)
314+ endif ()
315+
316+ set (VEFC_TESTING_ENABLED OFF )
317+ if (VEFC_BUILD_TESTS OR VEFC_DEMO_BACKEND_TEST_TARGETS)
318+ enable_testing ()
319+ set (VEFC_TESTING_ENABLED ON )
320+ endif ()
321+
322+ if (VEFC_TESTING_ENABLED)
323+ function (vefc_add_demo_backend_test test_name target_name )
324+ if (NOT TARGET ${target_name} )
325+ return ()
326+ endif ()
327+
328+ add_test (
329+ NAME ${test_name}
330+ COMMAND ${target_name} --test
331+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} /demo"
104332 )
105- target_link_libraries (vefc_demo_dx11 PRIVATE
106- d3d11
107- d3dcompiler
108- dxgi
109- user32
333+ set_tests_properties (${test_name} PROPERTIES LABELS "demo-backend" )
334+ endfunction ()
335+
336+ vefc_add_demo_backend_test (vefc_demo_gl_test demo )
337+ vefc_add_demo_backend_test (vefc_demo_dx11_test vefc_demo_dx11 )
338+ vefc_add_demo_backend_test (vefc_demo_vrhi_test vefc_demo_vrhi )
339+
340+ if (CMAKE_CONFIGURATION_TYPES )
341+ add_custom_target (vefc_demo_backend_tests
342+ COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -L demo-backend -C $<CONFIG >
343+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} "
344+ DEPENDS ${VEFC_DEMO_BACKEND_TEST_TARGETS}
345+ USES_TERMINAL
346+ )
347+ else ()
348+ add_custom_target (vefc_demo_backend_tests
349+ COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -L demo-backend
350+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} "
351+ DEPENDS ${VEFC_DEMO_BACKEND_TEST_TARGETS}
352+ USES_TERMINAL
110353 )
111- vefc_apply_common_options (vefc_demo_dx11 )
112- vefc_apply_features (vefc_demo_dx11 ${VEFC_ENABLE_HARFBUZZ} ${VEFC_ENABLE_FREETYPE} )
113354 endif ()
114355endif ()
115356
116357if (VEFC_BUILD_TESTS)
117- enable_testing ()
118358
119359 set (VEFC_TEST_SOURCES
120360 tests/test_main.cpp
0 commit comments