--- CMakeLists.txt.orig	2025-11-28 05:28:48.000000000 +0800
+++ CMakeLists.txt	2025-12-26 01:33:15.000000000 +0800
@@ -31,6 +31,12 @@
   set(SHADERC_ENABLE_INSTALL ON)
 endif()
 
+option(USE_EXTERNAL_SPIRV_TOOLS "Use external installed SPIRV-TOOLS" OFF)
+if(USE_EXTERNAL_SPIRV_TOOLS)
+  set (ALLOW_EXTERNAL_SPIRV_TOOLS ON)
+  message(STATUS "USING EXTERNAL INSTALLED SPIRV-Tools")
+endif()
+
 option(SHADERC_SKIP_TESTS "Skip building tests" ${SHADERC_SKIP_TESTS})
 if(NOT ${SHADERC_SKIP_TESTS})
   set(SHADERC_ENABLE_TESTS ON)
@@ -127,11 +133,6 @@
   endif()
 endif(MSVC)
 
-
-# Configure subdirectories.
-# We depend on these for later projects, so they should come first.
-add_subdirectory(third_party)
-
 add_subdirectory(libshaderc_util)
 add_subdirectory(libshaderc)
 add_subdirectory(glslc)
@@ -139,11 +140,13 @@
     add_subdirectory(examples)
 endif()
 
-add_custom_target(build-version
-  ${Python_EXECUTABLE}
-  ${CMAKE_CURRENT_SOURCE_DIR}/utils/update_build_version.py
-  ${shaderc_SOURCE_DIR} ${spirv-tools_SOURCE_DIR} ${glslang_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/build-version.inc
-  COMMENT "Update build-version.inc in the Shaderc build directory (if necessary).")
+if(NOT USE_EXTERNAL_SPIRV_TOOLS)
+  add_custom_target(build-version
+    ${Python_EXECUTABLE}
+    ${CMAKE_CURRENT_SOURCE_DIR}/utils/update_build_version.py
+    ${shaderc_SOURCE_DIR} ${spirv-tools_SOURCE_DIR} ${glslang_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/build-version.inc
+    COMMENT "Update build-version.inc in the Shaderc build directory (if necessary).")
+endif()
 
 function(define_pkg_config_file NAME LIBS)
   add_custom_target(${NAME}-pkg-config ALL
--- third_party/CMakeLists.txt.orig	2024-09-23 23:32:56.000000000 +0200
+++ third_party/CMakeLists.txt	2024-10-16 11:38:56.000000000 +0200
@@ -24,6 +24,13 @@
 set( SKIP_SPIRV_TOOLS_INSTALL ${SHADERC_SKIP_INSTALL} )
 set( SKIP_GOOGLETEST_INSTALL ${SHADERC_SKIP_INSTALL} )
 
+set( SKIP_GLSLANG_INSTALL ${ALLOW_EXTERNAL_SPIRV_TOOLS} )
+set( SKIP_SPIRV_TOOLS_INSTALL ${ALLOW_EXTERNAL_SPIRV_TOOLS} )
+set( SKIP_GOOGLETEST_INSTALL ${ALLOW_EXTERNAL_SPIRV_TOOLS} )
+if (ALLOW_EXTERNAL_SPIRV_TOOLS)
+    set( INSTALL_GTEST OFF)
+endif()
+
 # Configure third party projects.
 if(${SHADERC_ENABLE_TESTS})
   if (IS_DIRECTORY ${SHADERC_GOOGLE_TEST_DIR})
@@ -43,51 +50,67 @@
   add_subdirectory(${SHADERC_SPIRV_HEADERS_DIR} spirv-headers)
 endif()
 
-if (NOT TARGET SPIRV-Tools)
-  # Check SPIRV-Tools before glslang so that it is linked into glslang.
-  # we control optimizations via glslang API calls directly.
-  if (IS_DIRECTORY ${SHADERC_SPIRV_TOOLS_DIR})
-    if ("${SHADERC_SKIP_TESTS}")
-      # Also skip building tests in SPIRV-Tools.
+if (ALLOW_EXTERNAL_SPIRV_TOOLS)
+  if (NOT TARGET SPIRV-Tools)
+    # Look for external SPIR-V Tools build, if not stop build with error
+    message(STATUS "Trying to find local SPIR-V tools")
+    find_package(SPIRV-Tools-opt)
+    if(NOT TARGET SPIRV-Tools-opt)
+      message(FATAL_ERROR "Requested to use external installed SPIRV-Tools but they are NOT FOUND")
+    else()
+      message(STATUS "External SPIRV-Tools Found")
       set(SPIRV_SKIP_TESTS ON CACHE BOOL "Skip building SPIRV-Tools tests")
-    elseif(NOT "${SPIRV_SKIP_TESTS}")
-      # SPIRV-Tools requires effcee, re2, and abseil to build tests.
-      # re2 depends on abseil, so abseil must be added first.
-      set(ABSL_INTERNAL_AT_LEAST_CXX17 ON)
-      set(ABSL_PROPAGATE_CXX_STD ON)
-      set(ABSL_ENABLE_INSTALL ON)
-      add_subdirectory(${SHADERC_ABSL_DIR} absl EXCLUDE_FROM_ALL)
-
-      # re2 tests take a long time and do not add much value, since re2 is a
-      # dependency of a dependency, so not running them.
-      set(RE2_BUILD_TESTING OFF CACHE STRING "Run RE2 Tests")
-      add_subdirectory(${SHADERC_RE2_DIR} re2)
-      add_subdirectory(${SHADERC_EFFCEE_DIR} effcee)
     endif()
-    add_subdirectory(${SHADERC_SPIRV_TOOLS_DIR} spirv-tools)
-    if (NOT "${SPIRV_SKIP_TESTS}")
-      if (MSVC)
-        if (${MSVC_VERSION} LESS 1920)
-	  # VS 2017 requires /bigobj on test_opt
-	  # https://github.com/google/shaderc/issues/1345
-	  # https://github.com/KhronosGroup/SPIRV-Tools/issues/5335
-	  target_compile_options(test_opt PRIVATE /bigobj)
+  endif()
+else()
+  if (NOT TARGET SPIRV-Tools)
+  # Check SPIRV-Tools before glslang so that it is linked into glslang.
+  # we control optimizations via glslang API calls directly.
+    if (IS_DIRECTORY ${SHADERC_SPIRV_TOOLS_DIR})
+      if ("${SHADERC_SKIP_TESTS}")
+        # Also skip building tests in SPIRV-Tools.
+        set(SPIRV_SKIP_TESTS ON CACHE BOOL "Skip building SPIRV-Tools tests")
+      elseif(NOT "${SPIRV_SKIP_TESTS}")
+        # SPIRV-Tools requires effcee, re2, and abseil to build tests.
+        # re2 depends on abseil, so abseil must be added first.
+        set(ABSL_INTERNAL_AT_LEAST_CXX17 ON)
+        set(ABSL_PROPAGATE_CXX_STD ON)
+        set(ABSL_ENABLE_INSTALL ON)
+        add_subdirectory(${SHADERC_ABSL_DIR} absl EXCLUDE_FROM_ALL)
+
+        # re2 tests take a long time and do not add much value, since re2 is a
+        # dependency of a dependency, so not running them.
+        set(RE2_BUILD_TESTING OFF CACHE STRING "Run RE2 Tests")
+        add_subdirectory(${SHADERC_RE2_DIR} re2)
+        add_subdirectory(${SHADERC_EFFCEE_DIR} effcee)
+      endif()
+      add_subdirectory(${SHADERC_SPIRV_TOOLS_DIR} spirv-tools)
+      if (NOT "${SPIRV_SKIP_TESTS}")
+        if (MSVC)
+          if (${MSVC_VERSION} LESS 1920)
+    	  # VS 2017 requires /bigobj on test_opt
+    	  # https://github.com/google/shaderc/issues/1345
+    	  # https://github.com/KhronosGroup/SPIRV-Tools/issues/5335
+          target_compile_options(test_opt PRIVATE /bigobj)
+          endif()
         endif()
       endif()
     endif()
-  endif()
-  if (NOT TARGET SPIRV-Tools)
-    message(FATAL_ERROR "SPIRV-Tools was not found - required for compilation")
+    if (NOT TARGET SPIRV-Tools)
+      message(FATAL_ERROR "SPIRV-Tools was not found - required for compilation")
+    endif()
   endif()
 endif()
 
 if (NOT TARGET glslang)
   if (IS_DIRECTORY ${SHADERC_GLSLANG_DIR})
-    if (SHADERC_ENABLE_TESTS)
-      # Glslang tests are off by default. Turn them on if testing Shaderc.
-      set(GLSLANG_TESTS ON)
+    if(NOT ALLOW_EXTERNAL_SPIRV_TOOLS)
+        if (SHADERC_ENABLE_TESTS)
+        # Glslang tests are off by default. Turn them on if testing Shaderc.
+        set(GLSLANG_TESTS ON)
+        endif()
+        set(GLSLANG_ENABLE_INSTALL $<NOT:${SKIP_GLSLANG_INSTALL}>)
     endif()
-    set(GLSLANG_ENABLE_INSTALL $<NOT:${SKIP_GLSLANG_INSTALL}>)
     add_subdirectory(${SHADERC_GLSLANG_DIR} glslang)
   endif()
   if (NOT TARGET glslang)
--- glslc/CMakeLists.txt.orig	2024-09-23 23:32:56.000000000 +0200
+++ glslc/CMakeLists.txt	2024-10-16 11:06:19.000000000 +0200
@@ -54,7 +54,11 @@
   target_include_directories(glslc_exe PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/.. ${spirv-tools_SOURCE_DIR}/include)
   set_target_properties(glslc_exe PROPERTIES OUTPUT_NAME glslc)
   target_link_libraries(glslc_exe PRIVATE glslc shaderc_util shaderc)
-  add_dependencies(glslc_exe build-version)
+  if(USE_EXTERNAL_SPIRV_TOOLS)
+    target_compile_definitions(glslc PUBLIC USE_EXTERNAL_SPIRV_TOOLS)
+  else()
+    add_dependencies(glslc_exe build-version)
+  endif(USE_EXTERNAL_SPIRV_TOOLS)
 endif(SHADERC_ENABLE_EXECUTABLES)
 
 shaderc_add_tests(
--- glslc/src/main.cc.orig	2024-09-23 23:32:56.000000000 +0200
+++ glslc/src/main.cc	2024-10-16 11:39:57.000000000 +0200
@@ -204,10 +204,11 @@
   return true;
 }
 
+#ifndef USE_EXTERNAL_SPIRV_TOOLS
 const char kBuildVersion[] =
 #include "build-version.inc"
     ;
-
+#endif
 // Gets an optional stage name followed by required offset argument.  Returns
 // false and emits a message to *errs if any errors occur.  After calling this
 // function, *index will be the index of the last command line argument
@@ -293,7 +294,9 @@
 #undef RESOURCE
       return 0;
     } else if (arg == "--version") {
+#ifndef USE_EXTERNAL_SPIRV_TOOLS
       std::cout << kBuildVersion << std::endl;
+#endif
       std::cout << "Target: " << spvTargetEnvDescription(SPV_ENV_UNIVERSAL_1_0)
                 << std::endl;
       return 0;
