Fix clean CMake builds

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 Dummy 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.

Use this trick for both dawn_headers and dawncpp_headers that are header
only libraries with generated headers.

Bug: dawn:333
Change-Id: Ib0d6dcc5f351a638d1c5360214c0ce14a28fee3e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15921
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2020-02-14 19:09:33 +00:00 committed by Commit Bot service account
parent 2fd6181929
commit 71b3dd56da
1 changed files with 14 additions and 4 deletions

View File

@ -22,8 +22,16 @@ DawnJSONGenerator(
RESULT_VARIABLE "DAWN_HEADERS_GEN_SOURCES"
)
add_library(dawn_headers INTERFACE)
target_sources(dawn_headers INTERFACE
# 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 Dummy 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_DUMMY_FILE})
target_sources(dawn_headers PRIVATE
"${DAWN_INCLUDE_DIR}/dawn/dawn_wsi.h"
${DAWN_HEADERS_GEN_SOURCES}
)
@ -39,8 +47,10 @@ DawnJSONGenerator(
RESULT_VARIABLE "DAWNCPP_HEADERS_GEN_SOURCES"
)
add_library(dawncpp_headers INTERFACE)
target_sources(dawncpp_headers INTERFACE
# This headers only library needs to be a STATIC library, see comment for
# dawn_headers above.
add_library(dawncpp_headers STATIC ${DAWN_DUMMY_FILE})
target_sources(dawncpp_headers PRIVATE
"${DAWN_INCLUDE_DIR}/dawn/EnumClassBitmasks.h"
${DAWNCPP_HEADERS_GEN_SOURCES}
)