[libc-commits] [libc] [libc] Find Python 3 in standalone (PR #118871)

Tristan Ross via libc-commits libc-commits at lists.llvm.org
Thu Dec 5 13:11:15 PST 2024


https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/118871

`Python3_Executable` wasn't defined when libc is trying to be built in standalone mode. Also adds a `project` define so CMake quits complaining.

>From 275a03ceec1c91cb27dfd3dcf60156f6af4eaacd Mon Sep 17 00:00:00 2001
From: Tristan Ross <tristan.ross at midstall.com>
Date: Thu, 5 Dec 2024 13:09:03 -0800
Subject: [PATCH] [libc] Find Python 3 in standalone

---
 libc/CMakeLists.txt | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 5196735bef4e76..cfe3e347980a37 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -8,6 +8,13 @@ endif()
 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
   NO_POLICY_SCOPE)
 
+# If we are not building as a part of LLVM, build libc as an
+# standalone project, using LLVM as an external library:
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+  project(libc)
+  set(LIBC_BUILT_STANDALONE TRUE)
+endif()
+
 if (LIBC_CMAKE_VERBOSE_LOGGING)
   get_directory_property(LIBC_OLD_PREPROCESSOR_DEFS COMPILE_DEFINITIONS)
   foreach(OLD_DEF ${LIBC_OLD_PREPROCESSOR_DEFS})
@@ -30,6 +37,11 @@ endif()
 # Default to C++17
 set(CMAKE_CXX_STANDARD 17)
 
+if(LIBC_BUILT_STANDALONE)
+  find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
+    COMPONENTS Interpreter)
+endif()
+
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
 
 # The top-level source directory.



More information about the libc-commits mailing list