CMake: Make placeholder files for generated files
This works around a limitation prior to CMake 3.20 where teh GENERATED
property is only local to a directory, which prevented putting generated
headers in the INTERFACE of a library.
Fixed: dawn:2477
Change-Id: I81e78afe76902a6e8d65d075242fbcdf66bfa0be
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/181040
Reviewed-by: Austin Eng <enga@chromium.org>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7b0647c..efac34c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,12 +27,15 @@
cmake_minimum_required(VERSION 3.10.2)
-# When upgrading to CMake 3.11 we can remove DAWN_PLACEHOLDER_FILE because source-less add_library
-# becomes available.
-# When upgrading to CMake 3.12 we should add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake in
-# case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to
-# override options in third_party dependencies. We can also add the HOMEPAGE_URL
-# entry to the project `HOMEPAGE_URL "https://dawn.googlesource.com/dawn"`
+# - When upgrading to CMake 3.11 we can remove DAWN_PLACEHOLDER_FILE because source-less
+# add_library becomes available.
+# - When upgrading to CMake 3.12 we should add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake
+# in case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to
+# override options in third_party dependencies. We can also add the HOMEPAGE_URL entry to the
+# project `HOMEPAGE_URL "https://dawn.googlesource.com/dawn"`
+# - When upgrading to CMake 3.20 we can take advantage of the GENERATED property being global in
+# DawnGenerator. We should also use the path utilities in install_if_enabled.
+
project(
Dawn
diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt
index 8f3933a..c178640 100644
--- a/generator/CMakeLists.txt
+++ b/generator/CMakeLists.txt
@@ -105,7 +105,20 @@
COMMENT "Dawn: Generating files for ${G_PRINT_NAME}."
)
- set_source_files_properties(${OUTPUTS} PROPERTIES GENERATED TRUE)
+ # Prior to CMake 3.20 the GENERATED property is local to a directory which means that putting
+ # generated headers in INTERFACE properties causes dependent targets to complain that they
+ # cannot find the file. (because they don't see it as generated and want to check is is
+ # actually on the filesystem).
+ # Work around this by creating empty files placeholder generated files so that the build
+ # configuration process can success.
+ foreach(path ${OUTPUTS})
+ if (NOT EXISTS ${path})
+ string(FIND "${path}" "/" foundIndex REVERSE)
+ string(SUBSTRING "${path}" 0 ${foundIndex} dir)
+ file(MAKE_DIRECTORY ${dir})
+ file(TOUCH ${path})
+ endif()
+ endforeach()
# Return the list of outputs.
set(${G_RESULT_VARIABLE} ${OUTPUTS} PARENT_SCOPE)
diff --git a/src/dawn/CMakeLists.txt b/src/dawn/CMakeLists.txt
index acd9a80..fc4037b 100644
--- a/src/dawn/CMakeLists.txt
+++ b/src/dawn/CMakeLists.txt
@@ -77,19 +77,9 @@
RESULT_VARIABLE "DAWN_HEADERS_GEN_SOURCES"
)
-# Headers only INTERFACE library with generated headers don't work in CMake
-# because the GENERATED property is local to a directory. Instead we make a
-# STATIC library with a placeholder cpp file.
-#
-# INTERFACE libraries can only have INTERFACE sources so the sources get added
-# to the dependant's list of sources. If these dependents are in another
-# directory, they don't see the GENERATED property and fail to configure
-# because the file doesn't exist on disk.
-add_library(dawn_headers STATIC ${DAWN_PLACEHOLDER_FILE})
-common_compile_options(dawn_headers)
+add_library(dawn_headers INTERFACE)
target_sources(dawn_headers INTERFACE
"${DAWN_INCLUDE_DIR}/webgpu/webgpu.h"
- PRIVATE
${DAWN_HEADERS_GEN_SOURCES}
)
target_link_libraries(dawn_headers INTERFACE dawn_public_config)
@@ -105,15 +95,11 @@
RESULT_VARIABLE "DAWNCPP_HEADERS_GEN_SOURCES"
)
-# This headers only library needs to be a STATIC library, see comment for
-# dawn_headers above.
-add_library(dawncpp_headers STATIC ${DAWN_PLACEHOLDER_FILE})
-common_compile_options(dawncpp_headers)
+add_library(dawncpp_headers INTERFACE)
target_sources(dawncpp_headers
INTERFACE
"${DAWN_INCLUDE_DIR}/webgpu/webgpu_cpp.h"
"${DAWN_INCLUDE_DIR}/webgpu/webgpu_enum_class_bitmasks.h"
- PRIVATE
${DAWNCPP_HEADERS_GEN_SOURCES}
)
target_link_libraries(dawncpp_headers INTERFACE dawn_headers)