eliemichel / LearnWebGPU-Code

The accompanying code of the Learn WebGPU C++ programming guide
https://eliemichel.github.io/LearnWebGPU
MIT License
114 stars 30 forks source link

IMPORTED_LOCATION not set for imported target "webgpu" on step 5 #13

Closed Laxystem closed 1 year ago

Laxystem commented 1 year ago

image

My CMakeLists.txt:

cmake_minimum_required(VERSION 3.0..3.25)
project(
        LearnWebGPU
        VERSION 0.0.1
        LANGUAGES CXX C
)

add_subdirectory(glfw)
add_subdirectory(webgpu)

add_executable(App main.cpp)

target_link_libraries(App PRIVATE glfw webgpu)

set_target_properties(App PROPERTIES
        CXX_STANDARD 17
        COMPILE_WARNING_AS_ERROR ON
)

if (MSVC)
        target_compile_options(App PRIVATE /W4)
else()
        target_compile_options(App PRIVATE -Wall -Wextra -pedantic)
endif()

if(XCODE)
        set_target_properties(App PROPERTIES
                XCODE_GENERATE_SCHEME ON
                XCODE_SCHEME_ENABLE_GPU_FRAME_CAPTURE_MODE "Metal")
endif()

target_copy_webgpu_binaries(App)
eliemichel commented 1 year ago

Hello! Can you show the content of the webgpu directory and in particular the cake files in there?

Laxystem commented 1 year ago

Hello! Can you show the content of the webgpu directory and in particular the cake files in there?

image

eliemichel commented 1 year ago

I meant the content of the files ^^ Make sure to use the last version of WebGPU-distribution (where did you get these fils from exactly? I try to keep everything up to date as much as possible but since at the same time I'm trying to follow the changes in WebGPU API there are likely outdated things that I lost track of!)

Laxystem commented 1 year ago
set(WGPU ${CMAKE_CURRENT_SOURCE_DIR})
if (NOT ARCH)
    set(ARCH x86_64)
endif()

# A pre-compiled target (IMPORTED) that is a dynamically
# linked library (SHARED, meaning .dll, .so or .dylib).
add_library(webgpu SHARED IMPORTED GLOBAL)

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")

    set(WGPU_RUNTIME_LIB ${WGPU}/windows-${ARCH}/wgpu_native.dll PARENT_SCOPE)
    set_target_properties(
        webgpu
        PROPERTIES
            IMPORTED_LOCATION "${WGPU_RUNTIME_LIB}"
            IMPORTED_IMPLIB "${WGPU}/windows-${ARCH}/wgpu_native.lib"
            INTERFACE_INCLUDE_DIRECTORIES "${WGPU}"
    )

elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")

    set(WGPU_RUNTIME_LIB ${WGPU}/linux-${ARCH}/libwgpu.so PARENT_SCOPE)
    set_target_properties(
        webgpu
        PROPERTIES
            IMPORTED_LOCATION "${WGPU_RUNTIME_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${WGPU}"
    )

elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")

    set(WGPU_RUNTIME_LIB ${WGPU}/macos-${ARCH}/libwgpu.dylib PARENT_SCOPE)
    set_target_properties(
        webgpu
        PROPERTIES
            IMPORTED_LOCATION "${WGPU_RUNTIME_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${WGPU}"
    )

else()

    message(FATAL_ERROR "Plateform not supported by this release of WebGPU. You may consider building it yourself from its source (see https://github.com/gfx-rs/wgpu-native)")

endif()

# The application's binary must find wgpu.dll or libwgpu.so at runtime,
# so we automatically copy it (it's called WGPU_RUNTIME_LIB in general)
# next to the binary.
function(target_copy_webgpu_binaries Target)
    add_custom_command(
        TARGET ${Target} POST_BUILD
        COMMAND
            ${CMAKE_COMMAND} -E copy_if_different
            ${WGPU_RUNTIME_LIB}
            $<TARGET_FILE_DIR:${Target}>
    )
endfunction()

Here it is, sorry!

And I got it from this link on your tutorial.

Laxystem commented 1 year ago

thank you for replying so quickly, btw.

eliemichel commented 1 year ago

You should use this version of the distribution that is more up to date: https://github.com/eliemichel/WebGPU-distribution/tree/wgpu (I believe there is a warning a bit below the link you've used to tell that only one of the download links is up to date for now but I agree it could be clearer)

If you're not on Linux the problem is that you are missing the lib file of your os (but again use the up to date version ;) )

Laxystem commented 1 year ago

image It works now, thanks! Although it does funny stuff when you don't write to the GLFW buffer ;3