Skip to content

Commit

Permalink
Test cmake refactor branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jspanchu committed Jun 19, 2024
1 parent c0602d5 commit 124e86e
Showing 1 changed file with 6 additions and 61 deletions.
67 changes: 6 additions & 61 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,76 +21,21 @@ include(FetchContent)
set(dawn_disconnect_subsequent_updates ON)
FetchContent_Declare(dawn
GIT_REPOSITORY https://dawn.googlesource.com/dawn
GIT_TAG "chromium/${CHROMIUM_VERSION_PATCH}"
GIT_TAG "chromium/6546"
GIT_SUBMODULES ""
GIT_SHALLOW ON)
# Dawn outputs various library files in a directory structure that mirrors
# it's source tree. While this is convenient to understand provenance,
# having all of them under one roof is quite convenient for packaging.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
# Forces dawn to generate static libraries and bundle them all into one giant shared library.
set(BUILD_SHARED_LIBS OFF)
set(DAWN_ENABLE_INSTALL ON)
set(DAWN_FETCH_DEPENDENCIES ON)
# Disable unneeded parts
set(DAWN_BUILD_SAMPLES OFF)
set(DAWN_USE_GLFW OFF)
set(DAWN_BUILD_PROTOBUF OFF)
set(DAWN_FETCH_DEPENDENCIES ON)
set(DAWN_BUILD_SAMPLES OFF)
set(TINT_BUILD_CMD_TOOLS OFF)
set(TINT_BUILD_SAMPLES OFF)
set(TINT_BUILD_DOCS OFF)
set(TINT_BUILD_TESTS OFF)
# add dawn source directory to build system
FetchContent_MakeAvailable(dawn)
# This is all of necessary dawn libraries bundled up.
add_library(dawn SHARED "${dawn_BINARY_DIR}/gen/src/dawn/native/webgpu_dawn_native_proc.cpp")
add_library(dawn::dawn ALIAS dawn)
# 'nested-namespace-definition' requires compiler flag '/std:c++17'
target_compile_features(dawn PRIVATE cxx_std_17)
target_link_libraries(dawn
PRIVATE dawn_native)
# associate the header with the target so that it gets installed.
target_sources(dawn INTERFACE
FILE_SET dawn_webgpu_header
TYPE HEADERS
BASE_DIRS "${dawn_BINARY_DIR}/gen/include"
FILES "${dawn_BINARY_DIR}/gen/include/dawn/webgpu.h")
target_compile_definitions(dawn
PUBLIC "WGPU_SHARED_LIBRARY")
target_compile_definitions(dawn
PRIVATE "WGPU_IMPLEMENTATION")
# installs header `dawn/webgpu.h` and the shared library `dawn`
include(GNUInstallDirs)
install(TARGETS dawn
EXPORT dawn-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FILE_SET dawn_webgpu_header)
install(
DIRECTORY "${dawn_BINARY_DIR}/gen/emscripten-bits"
TYPE LIB)
# installs helpful package info so that folks can locate us via cmake find_package or pkg-config.
install(EXPORT dawn-targets
FILE dawnTargets.cmake
NAMESPACE dawn::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/dawn)
# Create a ConfigVersion.cmake file:
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/dawnConfigVersion.cmake
COMPATIBILITY AnyNewerVersion)
# Configure config file
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/dawnConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/dawnConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/dawn)
# Install the fully generated config and configVersion files
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/dawnConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/dawnConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/dawn)
# Run simple unit tests to ensure wgpu symbols were exported.
include(CTest)
set(BUILD_TESTING ON)
Expand All @@ -108,10 +53,10 @@ if (BUILD_TESTING)
add_executable(simple_cpp tests/simple.cpp)
target_compile_features(simple_cpp PRIVATE cxx_std_17)
target_link_libraries(simple_cpp PRIVATE webgpu_headers ${CMAKE_DL_LIBS})
add_test(NAME test-simple-cpp COMMAND simple_cpp "$<TARGET_FILE:dawn>")
add_test(NAME test-simple-cpp COMMAND simple_cpp "$<TARGET_FILE:dawn::webgpu_dawn>")
add_executable(simple_c tests/simple.c)
target_link_libraries(simple_c PRIVATE webgpu_headers ${CMAKE_DL_LIBS})
add_test(NAME test-simple-c COMMAND simple_c "$<TARGET_FILE:dawn>")
add_test(NAME test-simple-c COMMAND simple_c "$<TARGET_FILE:dawn::webgpu_dawn>")
endif ()
# Packaging
include(CPack)

0 comments on commit 124e86e

Please sign in to comment.