Skip to content

Commit

Permalink
bring back static lib support
Browse files Browse the repository at this point in the history
  • Loading branch information
PZerua committed Aug 9, 2024
1 parent 13c0a13 commit 3db088a
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,39 @@ option(TINT_ENABLE_BREAK_IN_DEBUGGER "Enable tint::debugger::Break()" OFF)
option(TINT_CHECK_CHROMIUM_STYLE "Check for [chromium-style] issues during build" OFF)
option(TINT_RANDOMIZE_HASHES "Randomize the hash seed value to detect non-deterministic output" OFF)

set(DAWN_ENABLE_METAL OFF)
set(DAWN_ENABLE_D3D12 OFF)
set(DAWN_ENABLE_VULKAN ON)

set(DAWN_ENABLE_D3D11 OFF)
set(DAWN_ENABLE_NULL OFF)
set(DAWN_ENABLE_DESKTOP_GL OFF)
set(DAWN_ENABLE_OPENGLES OFF)

set(DAWN_USE_GLFW OFF)

# Used for reflection
set(TINT_BUILD_TINT ON)

# Disable unneeded parts
set(DAWN_BUILD_SAMPLES OFF)
set(TINT_BUILD_SAMPLES OFF)
set(TINT_BUILD_DOCS OFF)
set(TINT_BUILD_TESTS OFF)
set(TINT_BUILD_FUZZERS OFF)
set(TINT_BUILD_SPIRV_TOOLS_FUZZER OFF)
set(TINT_BUILD_AST_FUZZER OFF)
set(TINT_BUILD_REGEX_FUZZER OFF)
set(TINT_BUILD_BENCHMARKS OFF)
set(TINT_BUILD_TESTS OFF)
set(TINT_BUILD_AS_OTHER_OS OFF)
set(TINT_BUILD_REMOTE_COMPILE OFF)
set(TINT_BUILD_CMD_TOOLS OFF)

set(TINT_ENABLE_INSTALL ON)

set(DAWN_FETCH_DEPENDENCIES ON)

set_if_not_defined(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.")

set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
Expand Down Expand Up @@ -496,3 +529,7 @@ if (DAWN_BUILD_MONOLITHIC_LIBRARY AND DAWN_ENABLE_INSTALL)
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Dawn"
)
endif ()

if (WIN32)
add_subdirectory(dawn_static)
endif()
66 changes: 66 additions & 0 deletions dawn_static/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
function(create_bundled_lib output_lib output_libname input_lib)

function(collect_dependencies target)

if (NOT TARGET ${target})
return()
endif ()

get_target_property(alias ${target} ALIASED_TARGET)
if (TARGET ${alias})
set(target ${alias})
endif ()

set(done_prop bundled_lib_${output_lib}_${target}_done)
get_property(done GLOBAL PROPERTY ${done_prop})
if (done)
return()
endif ()
set_property(GLOBAL PROPERTY ${done_prop} ON)

get_target_property(_type ${target} TYPE)
if (${_type} STREQUAL "STATIC_LIBRARY")
list(APPEND static_libs ${target})
endif ()

set(_link_libs_type LINK_LIBRARIES)
if (${_type} STREQUAL "INTERFACE_LIBRARY")
set(_link_libs_type INTERFACE_LINK_LIBRARIES)
endif ()
get_target_property(target_dependencies ${target} ${_link_libs_type})

foreach (dependency IN LISTS target_dependencies)
collect_dependencies(${dependency})
endforeach ()

set(static_libs ${static_libs} PARENT_SCOPE)

endfunction()

collect_dependencies(${input_lib})

list(REMOVE_DUPLICATES static_libs)

# message("### Static lib dependencies: ${static_libs}")

set(output_file "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${output_libname}${CMAKE_STATIC_LIBRARY_SUFFIX}")

if (WIN32)

foreach (target IN LISTS static_libs)
list(APPEND lib_files $<TARGET_FILE:${target}>)
endforeach ()

add_custom_command(
COMMAND ${CMAKE_AR} /NOLOGO /OUT:${output_file} ${lib_files}
OUTPUT ${output_file}
DEPENDS ${static_libs}
VERBATIM)

endif()

add_custom_target(${output_lib} ALL DEPENDS ${output_file})

endfunction()

create_bundled_lib(libdawn_static dawn_static webgpu_dawn libtint)

0 comments on commit 3db088a

Please sign in to comment.