CMake: Massage CMakeLists for use by NodeJS bindings

Allow the third_party directory to be controlled by the outer sub-project.

Change-Id: I11030c75254c264c1955150bdf1983771b33b614
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/64500
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 112932b..59b9f0c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,14 @@
   set(TINT_BUILD_TESTS_DEFAULT ON)
 endif()
 
+function (set_if_not_defined name value description)
+    if(NOT DEFINED ${name})
+        set(${name} ${value} PARENT_SCOPE)
+    endif()
+endfunction()
+
+set_if_not_defined(TINT_THIRD_PARTY_DIR "${tint_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.")
+
 option(TINT_BUILD_SAMPLES "Build samples" ON)
 option(TINT_BUILD_DOCS "Build documentation" ${TINT_BUILD_DOCS_DEFAULT})
 option(TINT_DOCS_WARN_AS_ERROR "When building documentation, treat warnings as errors" OFF)
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index b7e94aa..d5ff3f4 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -35,6 +35,7 @@
     if (${TINT_BUILD_SPIRV_TOOLS_FUZZER})
       set(SPIRV_BUILD_FUZZER ON CACHE BOOL "Controls whether spirv-fuzz is built" FORCE)
     endif()
-    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools EXCLUDE_FROM_ALL)
+    set(SPIRV-Headers_SOURCE_DIR "${TINT_THIRD_PARTY_DIR}/spirv-headers")
+    add_subdirectory("${TINT_THIRD_PARTY_DIR}/spirv-tools" "${CMAKE_BINARY_DIR}/third_party/spirv-tools" EXCLUDE_FROM_ALL)
   endif()
 endif()