Skip to content

Commit c511ffb

Browse files
kohakukunDawn LUCI CQ
authored andcommitted
dawn: Add install command to CMakeLists files
Change-Id: I39503bb0f53c1932e3bf7925b38203c60e458a2e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/136500 Commit-Queue: Corentin Wallez <[email protected]> Reviewed-by: Corentin Wallez <[email protected]> Kokoro: Kokoro <[email protected]> Reviewed-by: Ben Clayton <[email protected]>
1 parent eb44794 commit c511ffb

File tree

8 files changed

+128
-12
lines changed

8 files changed

+128
-12
lines changed

CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,45 @@ function (set_if_not_defined name value description)
7676
endif()
7777
endfunction()
7878

79+
function (install_if_enabled target)
80+
if(NOT DAWN_ENABLE_INSTALL)
81+
return()
82+
endif()
83+
84+
install(TARGETS ${target}
85+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
86+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
87+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
88+
)
89+
90+
get_target_property(targetHeaders ${target} INTERFACE_SOURCES)
91+
if (NOT targetHeaders)
92+
return()
93+
endif()
94+
95+
foreach(headerFile ${targetHeaders})
96+
# Starting from CMake 3.20 there is the cmake_path command that could simplify this code.
97+
# Compute the install subdirectory for the header by stripping out the path to
98+
# the include / gen/include directory...
99+
string(FIND "${headerFile}" "${DAWN_INCLUDE_DIR}" foundIndex)
100+
if (foundIndex EQUAL 0)
101+
string(LENGTH "${DAWN_INCLUDE_DIR}/" lengthToRemove)
102+
endif()
103+
string(FIND "${headerFile}" "${DAWN_BUILD_GEN_DIR}/include/" foundIndex)
104+
if (foundIndex EQUAL 0)
105+
string(LENGTH "${DAWN_BUILD_GEN_DIR}/include/" lengthToRemove)
106+
endif()
107+
string(SUBSTRING "${headerFile}" "${lengthToRemove}" -1 headerRelDir)
108+
109+
# ... then remove everything after the last /
110+
string(FIND "${headerRelDir}" "/" foundIndex REVERSE)
111+
string(SUBSTRING "${headerRelDir}" 0 ${foundIndex} headerRelDir)
112+
113+
install(FILES "${headerFile}" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${headerRelDir})
114+
endforeach()
115+
endfunction()
116+
117+
79118
# Default values for the backend-enabling options
80119
set(ENABLE_D3D11 OFF)
81120
set(ENABLE_D3D12 OFF)
@@ -121,6 +160,7 @@ if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
121160
endif()
122161

123162
option_if_not_defined(DAWN_ENABLE_ASAN "Enable address sanitizer" OFF)
163+
option_if_not_defined(DAWN_ENABLE_INSTALL "Enable install step for Dawn libraries" OFF)
124164
option_if_not_defined(DAWN_ENABLE_TSAN "Enable thread sanitizer" OFF)
125165
option_if_not_defined(DAWN_ENABLE_MSAN "Enable memory sanitizer" OFF)
126166
option_if_not_defined(DAWN_ENABLE_UBSAN "Enable undefined behaviour sanitizer" OFF)
@@ -155,6 +195,7 @@ else()
155195
set(TINT_DEFAULT_GLSL OFF)
156196
endif()
157197

198+
option_if_not_defined(TINT_ENABLE_INSTALL "Enable install step for Tint libraries" OFF)
158199
option_if_not_defined(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" ON)
159200
option_if_not_defined(TINT_BUILD_DOCS "Build documentation" ON)
160201
option_if_not_defined(TINT_DOCS_WARN_AS_ERROR "When building documentation, treat warnings as errors" OFF)

generator/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ function(DawnGenerator)
9292
COMMENT "Dawn: Generating files for ${G_PRINT_NAME}."
9393
)
9494

95+
set_source_files_properties(${OUTPUTS} PROPERTIES GENERATED TRUE)
96+
9597
# Return the list of outputs.
9698
set(${G_RESULT_VARIABLE} ${OUTPUTS} PARENT_SCOPE)
9799
endfunction()

src/dawn/CMakeLists.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ DawnJSONGenerator(
7373
# because the file doesn't exist on disk.
7474
add_library(dawn_headers STATIC ${DAWN_PLACEHOLDER_FILE})
7575
common_compile_options(dawn_headers)
76-
target_sources(dawn_headers PRIVATE ${DAWN_HEADERS_GEN_SOURCES})
76+
target_sources(dawn_headers INTERFACE
77+
"${DAWN_INCLUDE_DIR}/webgpu/webgpu.h"
78+
PRIVATE
79+
${DAWN_HEADERS_GEN_SOURCES}
80+
)
7781
target_link_libraries(dawn_headers INTERFACE dawn_public_config)
82+
install_if_enabled(dawn_headers)
7883

7984
###############################################################################
8085
# Dawn C++ headers
@@ -90,12 +95,14 @@ DawnJSONGenerator(
9095
# dawn_headers above.
9196
add_library(dawncpp_headers STATIC ${DAWN_PLACEHOLDER_FILE})
9297
common_compile_options(dawncpp_headers)
93-
target_sources(dawncpp_headers PRIVATE
98+
target_sources(dawncpp_headers INTERFACE
99+
"${DAWN_INCLUDE_DIR}/webgpu/webgpu_cpp.h"
94100
"${DAWN_INCLUDE_DIR}/dawn/EnumClassBitmasks.h"
101+
PRIVATE
95102
${DAWNCPP_HEADERS_GEN_SOURCES}
96103
)
97104
target_link_libraries(dawncpp_headers INTERFACE dawn_headers)
98-
105+
install_if_enabled(dawncpp_headers)
99106
###############################################################################
100107
# Dawn C++ wrapper
101108
###############################################################################
@@ -113,6 +120,8 @@ target_link_libraries(dawncpp PUBLIC dawncpp_headers)
113120

114121
add_library(webgpu_cpp ALIAS dawncpp)
115122

123+
install_if_enabled(dawncpp)
124+
116125
###############################################################################
117126
# libdawn_proc
118127
###############################################################################
@@ -129,9 +138,17 @@ target_compile_definitions(dawn_proc PRIVATE "WGPU_IMPLEMENTATION")
129138
if(BUILD_SHARED_LIBS)
130139
target_compile_definitions(dawn_proc PRIVATE "WGPU_SHARED_LIBRARY")
131140
endif()
132-
target_sources(dawn_proc PRIVATE ${DAWNPROC_GEN_SOURCES})
141+
target_sources(dawn_proc
142+
INTERFACE
143+
"${DAWN_INCLUDE_DIR}/dawn/dawn_thread_dispatch_proc.h"
144+
"${DAWN_INCLUDE_DIR}/dawn/dawn_proc.h"
145+
PRIVATE
146+
${DAWNPROC_GEN_SOURCES}
147+
)
133148
target_link_libraries(dawn_proc PUBLIC dawn_headers)
134149

150+
install_if_enabled(dawn_proc)
151+
135152
###############################################################################
136153
# Other generated files (upstream header, emscripten header, emscripten bits)
137154
###############################################################################

src/dawn/glfw/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ if(DAWN_USE_GLFW)
1616

1717
add_library(dawn_glfw STATIC ${DAWN_PLACEHOLDER_FILE})
1818
common_compile_options(dawn_glfw)
19-
target_sources(dawn_glfw PRIVATE
19+
target_sources(dawn_glfw
20+
INTERFACE
21+
"${DAWN_INCLUDE_DIR}/webgpu/webgpu_glfw.h"
22+
PRIVATE
2023
"utils.cpp"
2124
)
2225
target_link_libraries(dawn_glfw

src/dawn/native/CMakeLists.txt

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ if(BUILD_SHARED_LIBS)
2626
target_compile_definitions(dawn_native PRIVATE "DAWN_NATIVE_SHARED_LIBRARY")
2727
endif()
2828

29-
target_sources(dawn_native PRIVATE
29+
target_sources(dawn_native
30+
INTERFACE
3031
"${DAWN_INCLUDE_DIR}/dawn/native/DawnNative.h"
3132
"${DAWN_INCLUDE_DIR}/dawn/native/dawn_native_export.h"
33+
PRIVATE
3234
${DAWN_NATIVE_UTILS_GEN_SOURCES}
3335
"Adapter.h"
3436
"Adapter.cpp"
@@ -268,8 +270,10 @@ if (WINDOWS_STORE)
268270
endif()
269271

270272
if (DAWN_ENABLE_D3D11 OR DAWN_ENABLE_D3D12)
271-
target_sources(dawn_native PRIVATE
273+
target_sources(dawn_native
274+
INTERFACE
272275
"${DAWN_INCLUDE_DIR}/dawn/native/D3DBackend.h"
276+
PRIVATE
273277
"d3d/BackendD3D.cpp"
274278
"d3d/BackendD3D.h"
275279
"d3d/BlobD3D.cpp"
@@ -305,8 +309,10 @@ if (DAWN_ENABLE_D3D11 OR DAWN_ENABLE_D3D12)
305309
endif()
306310

307311
if (DAWN_ENABLE_D3D11)
308-
target_sources(dawn_native PRIVATE
312+
target_sources(dawn_native
313+
INTERFACE
309314
"${DAWN_INCLUDE_DIR}/dawn/native/D3D11Backend.h"
315+
PRIVATE
310316
"d3d11/BackendD3D11.cpp"
311317
"d3d11/BackendD3D11.h"
312318
"d3d11/BindGroupD3D11.cpp"
@@ -360,8 +366,10 @@ if (DAWN_ENABLE_D3D11)
360366
endif()
361367

362368
if (DAWN_ENABLE_D3D12)
363-
target_sources(dawn_native PRIVATE
369+
target_sources(dawn_native
370+
INTERFACE
364371
"${DAWN_INCLUDE_DIR}/dawn/native/D3D12Backend.h"
372+
PRIVATE
365373
"d3d12/BackendD3D12.cpp"
366374
"d3d12/BackendD3D12.h"
367375
"d3d12/BindGroupD3D12.cpp"
@@ -445,8 +453,10 @@ if (DAWN_ENABLE_D3D12)
445453
endif()
446454

447455
if (DAWN_ENABLE_METAL)
448-
target_sources(dawn_native PRIVATE
456+
target_sources(dawn_native
457+
INTERFACE
449458
"${DAWN_INCLUDE_DIR}/dawn/native/MetalBackend.h"
459+
PRIVATE
450460
"Surface_metal.mm"
451461
"metal/BackendMTL.h"
452462
"metal/BackendMTL.mm"
@@ -498,8 +508,10 @@ if (DAWN_ENABLE_METAL)
498508
endif()
499509

500510
if (DAWN_ENABLE_NULL)
501-
target_sources(dawn_native PRIVATE
511+
target_sources(dawn_native
512+
INTERFACE
502513
"${DAWN_INCLUDE_DIR}/dawn/native/NullBackend.h"
514+
PRIVATE
503515
"null/DeviceNull.cpp"
504516
"null/DeviceNull.h"
505517
)
@@ -524,8 +536,10 @@ if (DAWN_ENABLE_OPENGL)
524536
RESULT_VARIABLE "DAWN_NATIVE_OPENGL_AUTOGEN_SOURCES"
525537
)
526538

527-
target_sources(dawn_native PRIVATE
539+
target_sources(dawn_native
540+
INTERFACE
528541
"${DAWN_INCLUDE_DIR}/dawn/native/OpenGLBackend.h"
542+
PRIVATE
529543
${DAWN_NATIVE_OPENGL_AUTOGEN_SOURCES}
530544
"opengl/BackendGL.cpp"
531545
"opengl/BackendGL.h"
@@ -589,7 +603,9 @@ endif()
589603

590604
if (DAWN_ENABLE_VULKAN)
591605
target_sources(dawn_native PRIVATE
606+
INTERFACE
592607
"${DAWN_INCLUDE_DIR}/dawn/native/VulkanBackend.h"
608+
PRIVATE
593609
"vulkan/BackendVk.cpp"
594610
"vulkan/BackendVk.h"
595611
"vulkan/BindGroupLayoutVk.cpp"
@@ -721,3 +737,6 @@ if(BUILD_SHARED_LIBS)
721737
target_compile_definitions(webgpu_dawn PRIVATE "WGPU_SHARED_LIBRARY")
722738
endif()
723739
target_sources(webgpu_dawn PRIVATE ${WEBGPU_DAWN_NATIVE_PROC_GEN})
740+
741+
install_if_enabled(dawn_native)
742+
install_if_enabled(webgpu_dawn)

src/dawn/platform/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ if(BUILD_SHARED_LIBS)
2121
endif()
2222

2323
target_sources(dawn_platform PRIVATE
24+
PUBLIC
2425
"${DAWN_INCLUDE_DIR}/dawn/platform/DawnPlatform.h"
2526
"${DAWN_INCLUDE_DIR}/dawn/platform/dawn_platform_export.h"
27+
PRIVATE
2628
"DawnPlatform.cpp"
2729
"WorkerThread.cpp"
2830
"WorkerThread.h"
@@ -33,3 +35,5 @@ target_sources(dawn_platform PRIVATE
3335
"tracing/TraceEvent.h"
3436
)
3537
target_link_libraries(dawn_platform PUBLIC dawn_headers PRIVATE dawn_internal_config dawn_common)
38+
39+
install_if_enabled(dawn_platform)

src/dawn/wire/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ if(BUILD_SHARED_LIBS)
2727
endif()
2828

2929
target_sources(dawn_wire PRIVATE
30+
INTERFACE
3031
"${DAWN_INCLUDE_DIR}/dawn/wire/Wire.h"
3132
"${DAWN_INCLUDE_DIR}/dawn/wire/WireClient.h"
3233
"${DAWN_INCLUDE_DIR}/dawn/wire/WireServer.h"
3334
"${DAWN_INCLUDE_DIR}/dawn/wire/dawn_wire_export.h"
35+
PRIVATE
3436
${DAWN_WIRE_GEN_SOURCES}
3537
"BufferConsumer.h"
3638
"BufferConsumer_impl.h"
@@ -95,3 +97,5 @@ target_link_libraries(dawn_wire
9597
PUBLIC dawn_headers
9698
PRIVATE dawn_common dawn_internal_config
9799
)
100+
101+
install_if_enabled(dawn_wire)

src/tint/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ function(tint_add_target TARGET KIND)
347347

348348
if(${KIND} STREQUAL lib)
349349
add_library(${TARGET} STATIC EXCLUDE_FROM_ALL)
350+
if (TINT_ENABLE_INSTALL)
351+
install(TARGETS ${TARGET}
352+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
353+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
354+
)
355+
endif()
350356
tint_default_compile_options(${TARGET})
351357

352358
if(TINT_BUILD_FUZZERS)
@@ -355,6 +361,12 @@ function(tint_add_target TARGET KIND)
355361
set(FUZZ_TARGET "${TARGET}${TINT_FUZZ_SUFFIX}")
356362
add_library(${FUZZ_TARGET} STATIC EXCLUDE_FROM_ALL)
357363
target_sources(${FUZZ_TARGET} PRIVATE ${SOURCES})
364+
if (TINT_ENABLE_INSTALL)
365+
install(TARGETS ${FUZZ_TARGET}
366+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
367+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
368+
)
369+
endif()
358370
tint_default_compile_options(${FUZZ_TARGET})
359371
endif()
360372
elseif(${KIND} STREQUAL cmd)
@@ -587,3 +599,17 @@ endif(TINT_BUILD_TESTS)
587599
# Target aliases
588600
################################################################################
589601
add_library(libtint ALIAS tint_api)
602+
603+
if (TINT_ENABLE_INSTALL)
604+
# We need to recurse all folders and include all headers because tint.h includes most headers from src/tint
605+
file(GLOB TINT_HEADERS "${DAWN_INCLUDE_DIR}/tint/*.h")
606+
607+
install(FILES ${TINT_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tint/)
608+
609+
file(GLOB_RECURSE TINT_SRC_HEADERS RELATIVE ${CMAKE_SOURCE_DIR}/src/tint/ "*.h")
610+
611+
foreach(TINT_HEADER_FILE ${TINT_SRC_HEADERS})
612+
get_filename_component(TINT_HEADER_DIR ${TINT_HEADER_FILE} DIRECTORY)
613+
install(FILES ${CMAKE_SOURCE_DIR}/src/tint/${TINT_HEADER_FILE} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/src/tint/${TINT_HEADER_DIR})
614+
endforeach ()
615+
endif()

0 commit comments

Comments
 (0)