From 747defd01bc5b9e75dc4773c413e7d539502955c Mon Sep 17 00:00:00 2001 From: Timo de Kort Date: Sat, 25 May 2019 18:42:59 +0200 Subject: [PATCH 1/3] add necessary windows lib files for vulkan/dx12 introduce new argument feature-native to specify the back-end framework --- examples/hello_triangle_c/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/hello_triangle_c/CMakeLists.txt b/examples/hello_triangle_c/CMakeLists.txt index f3d9d3fca..0e30489c9 100644 --- a/examples/hello_triangle_c/CMakeLists.txt +++ b/examples/hello_triangle_c/CMakeLists.txt @@ -3,13 +3,20 @@ cmake_minimum_required(VERSION 3.11b) project(hello_triangle) set(TARGET_NAME hello_triangle) - +set(feature-native) add_executable(hello_triangle main.c) if(MSVC) add_definitions(-DWGPU_TARGET=WGPU_TARGET_WINDOWS) target_compile_options(${TARGET_NAME} PRIVATE /W4) set(GLFW_LIBRARY glfw3) + + target_link_libraries(${TARGET_NAME} userenv ws2_32 Dwmapi) + + if ("${feature-native}" STREQUAL "dx12") + target_link_libraries(${TARGET_NAME} d3dcompiler D3D12 DXGI) + endif() + elseif(APPLE) add_definitions(-DWGPU_TARGET=WGPU_TARGET_MACOS) set(OS_LIBRARIES "-framework Cocoa" "-framework CoreVideo" "-framework IOKit" "-framework QuartzCore") @@ -27,4 +34,4 @@ find_library(WGPU_LIBRARY wgpu_native HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug" ) -target_link_libraries(${TARGET_NAME} ${GLFW_LIBRARY} ${WGPU_LIBRARY} ${OS_LIBRARIES}) +target_link_libraries(${TARGET_NAME} ${GLFW_LIBRARY} ${WGPU_LIBRARY} ${OS_LIBRARIES}) \ No newline at end of file From 9b0607973e5496fb42e2d6b442c9e15dabe99f2c Mon Sep 17 00:00:00 2001 From: Timo de Kort Date: Sun, 26 May 2019 18:23:19 +0200 Subject: [PATCH 2/3] resolve PR comments - pass backends from the Makefile to the CMakeLists file - add check to see if the BACKEND argument is set - add dbghelp lib file --- Makefile | 2 +- examples/hello_triangle_c/CMakeLists.txt | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 18ab5645a..49afab0e6 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ ffi/wgpu-remote.h: wgpu-remote/cbindgen.toml $(wildcard wgpu-native/**/*.rs wgp rustup run nightly cbindgen wgpu-remote >$(FFI_DIR)/wgpu-remote.h examples-native: lib-native $(FFI_DIR)/wgpu.h examples/hello_triangle_c/main.c - cd examples/hello_triangle_c && $(CREATE_BUILD_DIR) && cd build && cmake .. && make + cd examples/hello_triangle_c && $(CREATE_BUILD_DIR) && cd build && cmake .. -DBACKEND=$(FEATURE_RUST) && make examples-remote: lib-remote $(FFI_DIR)/wgpu-remote.h examples/hello_remote_c/main.c cd examples/hello_remote_c && $(CREATE_BUILD_DIR) && cd build && cmake .. && make diff --git a/examples/hello_triangle_c/CMakeLists.txt b/examples/hello_triangle_c/CMakeLists.txt index 0e30489c9..128c85663 100644 --- a/examples/hello_triangle_c/CMakeLists.txt +++ b/examples/hello_triangle_c/CMakeLists.txt @@ -3,20 +3,27 @@ cmake_minimum_required(VERSION 3.11b) project(hello_triangle) set(TARGET_NAME hello_triangle) -set(feature-native) + +set(BACKEND_VULKAN "vulkan") +set(BACKEND_METAL "metal") +set(BACKEND_DX12 "dx12") +set(AVAILABLE_BACKENDS ${BACKEND_VULKAN} ${BACKEND_METAL} ${BACKEND_DX12}) + +if(NOT DEFINED BACKEND) + message(FATAL_ERROR "Backend has not been set, please do so by using the -DBACKEND= argument. \ + Available backends: ${AVAILABLE_BACKENDS}") +endif() + add_executable(hello_triangle main.c) if(MSVC) add_definitions(-DWGPU_TARGET=WGPU_TARGET_WINDOWS) target_compile_options(${TARGET_NAME} PRIVATE /W4) set(GLFW_LIBRARY glfw3) - - target_link_libraries(${TARGET_NAME} userenv ws2_32 Dwmapi) - - if ("${feature-native}" STREQUAL "dx12") - target_link_libraries(${TARGET_NAME} d3dcompiler D3D12 DXGI) + set(OS_LIBRARIES "userenv" "ws2_32" "Dwmapi" "dbghelp") + if("${BACKEND}" STREQUAL "${BACKEND_DX12}") + list(APPEND OS_LIBRARIES "d3dcompiler" "D3D12" "DXGI") endif() - elseif(APPLE) add_definitions(-DWGPU_TARGET=WGPU_TARGET_MACOS) set(OS_LIBRARIES "-framework Cocoa" "-framework CoreVideo" "-framework IOKit" "-framework QuartzCore") @@ -34,4 +41,4 @@ find_library(WGPU_LIBRARY wgpu_native HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug" ) -target_link_libraries(${TARGET_NAME} ${GLFW_LIBRARY} ${WGPU_LIBRARY} ${OS_LIBRARIES}) \ No newline at end of file +target_link_libraries(${TARGET_NAME} ${GLFW_LIBRARY} ${WGPU_LIBRARY} ${OS_LIBRARIES}) From 7bb528186f9be2d1c8b236eebe68ce9814406159 Mon Sep 17 00:00:00 2001 From: Timo de Kort Date: Sun, 26 May 2019 19:46:43 +0200 Subject: [PATCH 3/3] add DX11 support --- examples/hello_triangle_c/CMakeLists.txt | 28 ++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/hello_triangle_c/CMakeLists.txt b/examples/hello_triangle_c/CMakeLists.txt index 128c85663..c61737ae6 100644 --- a/examples/hello_triangle_c/CMakeLists.txt +++ b/examples/hello_triangle_c/CMakeLists.txt @@ -1,19 +1,23 @@ cmake_minimum_required(VERSION 3.11b) +set(BACKEND_VULKAN "vulkan") +set(BACKEND_METAL "metal") +set(BACKEND_DX11 "dx11") +set(BACKEND_DX12 "dx12") +set(AVAILABLE_BACKENDS + ${BACKEND_VULKAN} + ${BACKEND_METAL} + ${BACKEND_DX11} + ${BACKEND_DX12}) + +if(NOT DEFINED BACKEND OR NOT "${BACKEND}" IN_LIST AVAILABLE_BACKENDS) + message(FATAL_ERROR "BACKEND invalid or undefined, available backends: ${AVAILABLE_BACKENDS}") +endif() + project(hello_triangle) set(TARGET_NAME hello_triangle) -set(BACKEND_VULKAN "vulkan") -set(BACKEND_METAL "metal") -set(BACKEND_DX12 "dx12") -set(AVAILABLE_BACKENDS ${BACKEND_VULKAN} ${BACKEND_METAL} ${BACKEND_DX12}) - -if(NOT DEFINED BACKEND) - message(FATAL_ERROR "Backend has not been set, please do so by using the -DBACKEND= argument. \ - Available backends: ${AVAILABLE_BACKENDS}") -endif() - add_executable(hello_triangle main.c) if(MSVC) @@ -21,7 +25,9 @@ if(MSVC) target_compile_options(${TARGET_NAME} PRIVATE /W4) set(GLFW_LIBRARY glfw3) set(OS_LIBRARIES "userenv" "ws2_32" "Dwmapi" "dbghelp") - if("${BACKEND}" STREQUAL "${BACKEND_DX12}") + if("${BACKEND}" STREQUAL "${BACKEND_DX11}") + list(APPEND OS_LIBRARIES "d3dcompiler" "D3D11" "DXGI") + elseif("${BACKEND}" STREQUAL "${BACKEND_DX12}") list(APPEND OS_LIBRARIES "d3dcompiler" "D3D12" "DXGI") endif() elseif(APPLE)