--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1084,7 +1084,7 @@
   set(CMAKE_COLOR_DIAGNOSTICS ON)
 endif()
 if(NOT MSVC)
-  string(APPEND CMAKE_CXX_FLAGS " -O2 -fPIC")
+  string(APPEND CMAKE_CXX_FLAGS " -O2")
 
   # This prevents use of `c10::optional`, `c10::nullopt` etc within the codebase
   string(APPEND CMAKE_CXX_FLAGS " -DC10_NODEPRECATED")
@@ -1095,7 +1095,6 @@
   # Details at http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1459
   string(APPEND CMAKE_CXX_FLAGS " -Wall")
   string(APPEND CMAKE_CXX_FLAGS " -Wextra")
-  append_cxx_flag_if_supported("-Werror=return-type" CMAKE_CXX_FLAGS)
   append_cxx_flag_if_supported("-Werror=non-virtual-dtor" CMAKE_CXX_FLAGS)
   append_cxx_flag_if_supported("-Werror=braced-scalar-init" CMAKE_CXX_FLAGS)
   append_cxx_flag_if_supported("-Werror=range-loop-construct" CMAKE_CXX_FLAGS)

@@ -1083,7 +1082,6 @@
   endif()
   append_cxx_flag_if_supported("-fno-math-errno" CMAKE_CXX_FLAGS)
   append_cxx_flag_if_supported("-fno-trapping-math" CMAKE_CXX_FLAGS)
-  append_cxx_flag_if_supported("-Werror=format" CMAKE_CXX_FLAGS)
   if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13)
     append_cxx_flag_if_supported("-Wno-dangling-reference" CMAKE_CXX_FLAGS)
     append_cxx_flag_if_supported("-Wno-error=dangling-reference" CMAKE_CXX_FLAGS)
     append_cxx_flag_if_supported("-Wno-error=redundant-move" CMAKE_CXX_FLAGS)
--- a/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt
+++ b/aten/src/ATen/native/quantized/cpu/qnnpack/CMakeLists.txt
@@ -323,7 +323,7 @@
 set_target_properties(pytorch_qnnpack PROPERTIES PUBLIC_HEADER include/qnnpack_func.h)
 
 # ---[ Configure clog
-if(NOT TARGET clog)
+if(FALSE)
   set(CLOG_BUILD_TESTS OFF CACHE BOOL "")
   set(CLOG_RUNTIME_TYPE "${CPUINFO_RUNTIME_TYPE}" CACHE STRING "")
   add_subdirectory(
@@ -335,7 +335,8 @@
     target_compile_options(clog PRIVATE "-Wno-unused-result")
   endif()
 endif()
-target_link_libraries(pytorch_qnnpack PUBLIC clog)
+find_library(CLOG_LIBRARY NAMES clog REQUIRED)
+target_link_libraries(pytorch_qnnpack PUBLIC ${CLOG_LIBRARY})
 
 # ---[ Configure cpuinfo
 if(NOT TARGET cpuinfo AND USE_SYSTEM_CPUINFO)
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -87,7 +87,7 @@ endif()
 # Note: the folders that are being commented out have not been properly
 # addressed yet.
 
-if(NOT MSVC AND USE_XNNPACK)
+if(FALSE)
   if(NOT TARGET fxdiv)
     set(FXDIV_BUILD_TESTS OFF CACHE BOOL "")
     set(FXDIV_BUILD_BENCHMARKS OFF CACHE BOOL "")
@@ -1212,7 +1212,6 @@ if(USE_XPU)
 endif()
 
 if(NOT MSVC AND USE_XNNPACK)
-  TARGET_LINK_LIBRARIES(torch_cpu PRIVATE fxdiv)
 endif()
 
 # ==========================================================
@@ -1324,17 +1323,6 @@
 target_include_directories(torch_cpu PRIVATE
   "/usr/include/kineto")
 
-if(USE_KINETO)
-  target_include_directories(torch_cpu PRIVATE
-    ${TORCH_ROOT}/third_party/kineto/libkineto/src)
-endif()
-
-target_include_directories(torch_cpu PRIVATE
-  ${TORCH_ROOT}/third_party/cpp-httplib)
-
-target_include_directories(torch_cpu PRIVATE
-  ${TORCH_ROOT}/third_party/nlohmann/include)
-
 install(DIRECTORY
   "${TORCH_SRC_DIR}/csrc"
   "${TORCH_SRC_DIR}/headeronly"
--- a/cmake/Codegen.cmake
+++ b/cmake/Codegen.cmake
@@ -64,7 +64,7 @@ if(INTERN_BUILD_ATEN_OPS)
   if(MSVC)
     set(OPT_FLAG "/fp:strict ")
   else(MSVC)
-    set(OPT_FLAG "-O3 ")
+    set(OPT_FLAG " ")
     if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
       set(OPT_FLAG " ")
     endif()
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -492,7 +492,9 @@
       set_property(TARGET pytorch_qnnpack PROPERTY POSITION_INDEPENDENT_CODE ON)
       set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON)
       # QNNPACK depends on gemmlowp headers
-      target_include_directories(pytorch_qnnpack PRIVATE "${CAFFE2_THIRD_PARTY_ROOT}/gemmlowp")
+      find_package(gemmlowp REQUIRED)
+      get_target_property(GEMMLOWP_INCLUDE_DIRS gemmlowp::gemmlowp INTERFACE_INCLUDE_DIRECTORIES)
+      target_include_directories(pytorch_qnnpack PRIVATE ${GEMMLOWP_INCLUDE_DIRS})
     endif()
 
     list(APPEND Caffe2_DEPENDENCY_LIBS pytorch_qnnpack)
@@ -593,7 +591,7 @@
   find_library(microkernels-prod_LIBRARY microkernels-prod)
   set_property(TARGET XNNPACK PROPERTY IMPORTED_LOCATION "${XNNPACK_LIBRARY}")
   set_property(TARGET microkernels-prod PROPERTY IMPORTED_LOCATION "${microkernels-prod_LIBRARY}")
-  if(NOT XNNPACK_LIBRARY OR NOT microkernels-prod_LIBRARY)
+  if(FALSE)
     message(FATAL_ERROR "Cannot find XNNPACK")
   endif()
   message("-- Found XNNPACK: ${XNNPACK_LIBRARY}")
@@ -674,7 +672,7 @@ if(BUILD_TEST OR BUILD_MOBILE_BENCHMARK OR BUILD_MOBILE_TEST)
 endif()
 
 # ---[ FBGEMM
-if(USE_FBGEMM)
+if(FALSE)
   set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
   if(NOT DEFINED FBGEMM_SOURCE_DIR)
     set(FBGEMM_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/fbgemm" CACHE STRING "FBGEMM source directory")
@@ -698,6 +696,7 @@ if(USE_FBGEMM)
 endif()
 
 if(USE_FBGEMM)
+  list(APPEND Caffe2_DEPENDENCY_LIBS fbgemm)
   caffe2_update_option(USE_FBGEMM ON)
 else()
   caffe2_update_option(USE_FBGEMM OFF)
@@ -1156,7 +1155,6 @@
     endif()
     set(TP_BUILD_LIBUV ON CACHE BOOL "" FORCE)
     add_compile_options(-DTORCH_USE_LIBUV)
-    include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../third_party/tensorpipe/third_party/libuv/include)
     set(TP_STATIC_OR_SHARED STATIC CACHE STRING "" FORCE)
 
     # Tensorpipe uses cuda_add_library
@@ -1676,11 +1676,9 @@
 
 # Include cpp-httplib
 add_library(httplib INTERFACE IMPORTED)
-target_include_directories(httplib SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/cpp-httplib)
 
 # Include nlohmann-json
 add_library(nlohmann INTERFACE IMPORTED)
-include_directories(nlohmann SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/nlohmann/include)
 
 # Include moodycamel
 add_library(moodycamel INTERFACE IMPORTED)
--- a/cmake/External/nnpack.cmake
+++ b/cmake/External/nnpack.cmake
@@ -56,7 +56,7 @@
   set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory")
   set(GOOGLETEST_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/googletest" CACHE STRING "Google Test source directory")
 
-  if(NOT TARGET nnpack)
+  if(FALSE)
     set(NNPACK_BUILD_TESTS OFF CACHE BOOL "")
     set(NNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "")
     set(NNPACK_LIBRARY_TYPE "static" CACHE STRING "")
--- a/aten/src/ATen/CMakeLists.txt	2025-02-27 14:23:02.402742165 +0100
+++ b/aten/src/ATen/CMakeLists.txt	2025-02-27 14:23:40.445850718 +0100
@@ -448,8 +448,6 @@
 if(USE_CUDA)
   list(APPEND ATen_CUDA_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/cuda)
   # Next two lines are needed because TunableOp uses third-party/fmt
-  list(APPEND ATen_CUDA_INCLUDE $<TARGET_PROPERTY:fmt::fmt-header-only,INTERFACE_INCLUDE_DIRECTORIES>)
-  list(APPEND ATen_CUDA_DEPENDENCY_LIBS fmt::fmt-header-only)
   list(APPEND ATen_CUDA_CU_SRCS
     ${cuda_cu}
     ${native_cuda_cu}
@@ -521,8 +519,6 @@
   endif()

   # Next two lines are needed because TunableOp uses third-party/fmt
-  list(APPEND ATen_HIP_INCLUDE $<TARGET_PROPERTY:fmt::fmt-header-only,INTERFACE_INCLUDE_DIRECTORIES>)
-  list(APPEND ATen_HIP_DEPENDENCY_LIBS fmt::fmt-header-only)
   if(USE_FLASH_ATTENTION AND USE_ROCM_CK_SDPA)
     list(APPEND ATen_HIP_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/native/transformers/hip/flash_attn/ck)
   endif()
--- a/torch/CMakeLists.txt
+++ b/torch/CMakeLists.txt
@@ -59,16 +59,10 @@
     ${CMAKE_BINARY_DIR}/aten/src
     ${CMAKE_BINARY_DIR}/caffe2/aten/src
     ${CMAKE_BINARY_DIR}/third_party
-    ${CMAKE_BINARY_DIR}/third_party/onnx
 
     ${TORCH_ROOT}/third_party/valgrind-headers
 
-    ${TORCH_ROOT}/third_party/gloo
-    ${TORCH_ROOT}/third_party/onnx
-    ${TORCH_ROOT}/third_party/flatbuffers/include
     "/usr/include/kineto"
-    ${TORCH_ROOT}/third_party/cpp-httplib
-    ${TORCH_ROOT}/third_party/nlohmann/include
 
     ${TORCH_SRC_DIR}/csrc
     ${TORCH_SRC_DIR}/csrc/api/include
--- a/cmake/FlatBuffers.cmake
+++ b/cmake/FlatBuffers.cmake
@@ -1,10 +1 @@
-set(FlatBuffers_Include ${PROJECT_SOURCE_DIR}/third_party/flatbuffers/include)
-file(GLOB FlatBuffers_Library_SRCS
-  ${FlatBuffers_Include}/flatbuffers/*.h
-)
 add_library(flatbuffers INTERFACE)
-target_sources(
-  flatbuffers
-  INTERFACE ${FlatBuffers_Library_SRCS}
-)
-target_include_directories(flatbuffers INTERFACE ${FlatBuffers_Include})
