[libc-commits] [libc] [libc] Add base for target config within cmake (PR #72318)

via libc-commits libc-commits at lists.llvm.org
Tue Nov 14 17:33:05 PST 2023


================
@@ -249,40 +249,43 @@ include(CMakeParseArguments)
 include(LLVMLibCCheckCpuFeatures)
 include(LLVMLibCRules)
 
-if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt")
-  set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt")
-elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt")
-  set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt")
-else()
-  message(FATAL_ERROR "entrypoints.txt file for the target platform '${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}' not found.")
-endif()
-include(${entrypoint_file})
-
-if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt")
-  include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt")
-elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/headers.txt")
-  include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/headers.txt")
-endif()
-
+# If the user wants to provide their own list of entrypoints and headers
 if(LIBC_SYSTEM_CONFIG_FILE)
+  # Use the file provided by the user if it exists
   if(EXISTS "${LIBC_SYSTEM_CONFIG_FILE}")
     include("${LIBC_SYSTEM_CONFIG_FILE}")
   else()
     message(FATAL_ERROR "System Config File set to unavailable file '${LIBC_SYSTEM_CONFIG_FILE}'")
   endif()
+else()
+  # Else use the files in config/OS/CPU/ or config/OS/
+  if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt")
+    set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt")
+  elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt")
+    set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt")
+  else()
+    message(FATAL_ERROR "entrypoints.txt file for the target platform '${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}' not found.")
+  endif()
+  include(${entrypoint_file})
 
-  #TODO: Set up support for premade configs.
-
-  foreach(removed_entrypoint IN LISTS TARGET_LLVMLIBC_REMOVED_ENTRYPOINTS)
-    if(LIBC_CMAKE_VERBOSE_LOGGING)
-      message(STATUS "Removing entrypoint ${removed_entrypoint}")
-    endif()
-    list(REMOVE_ITEM TARGET_LLVMLIBC_ENTRYPOINTS ${removed_entrypoint})
-    list(REMOVE_ITEM TARGET_LIBC_ENTRYPOINTS ${removed_entrypoint})
-    list(REMOVE_ITEM TARGET_LIBM_ENTRYPOINTS ${removed_entrypoint})
-  endforeach()
+  if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt")
+    include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt")
+  elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/headers.txt")
+    include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/headers.txt")
+  endif()
 endif()
 
+# #TODO: Set up support for premade configs.
+
+# foreach(removed_entrypoint IN LISTS TARGET_LLVMLIBC_REMOVED_ENTRYPOINTS)
+#   if(LIBC_CMAKE_VERBOSE_LOGGING)
+#     message(STATUS "Removing entrypoint ${removed_entrypoint}")
+#   endif()
+#   list(REMOVE_ITEM TARGET_LLVMLIBC_ENTRYPOINTS ${removed_entrypoint})
+#   list(REMOVE_ITEM TARGET_LIBC_ENTRYPOINTS ${removed_entrypoint})
+#   list(REMOVE_ITEM TARGET_LIBM_ENTRYPOINTS ${removed_entrypoint})
+# endforeach()
+
----------------
lntue wrote:

WDYT of the following reorg:
```
if(NOT LIBC_CONFIG_PATH)
  if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}")
    set(LIBC_CONFIG_PATH "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}")
  elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}")
    set(LIBC_CONFIG_PATH "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}")
endif()

if(NOT LIBC_CONFIG_PATH)
  message(FATAL_ERROR "Configs for the platform '${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}' do not exist and LIBC_CONFIG_PATH is not set.")
elseif(LIBC_CMAKE_VERBOSE_LOGGING)
  message(STATUS "Path for config files is: ${LIBC_CONFIG_PATH}")
endif()

# Check entrypoints.txt
if(EXISTS "${LIBC_CONFIG_PATH}/entrypoints.txt")
    set(entrypoint_file "${LIBC_CONFIG_PATH}/entrypoints.txt")
else()
  message(FATAL_ERROR "${LIBC_CONFIG_PATH}/entrypoints.txt file not found.")
endif()

# Check header.txt
if(EXISTS "${LIBC_CONFIG_PATH}/headers.txt")
    include("${LIBC_CONFIG_PATH}/headers.txt")
endif()

# Check exclude.txt that appends to LIBC_EXCLUDE_ENTRYPOINTS list
if(EXISTS "${LIBC_CONFIG_PATH}/exclude.txt")
    include("${LIBC_CONFIG_PATH}/exclude.txt")
endif()

// Remove entry points:
foreach(removed_entrypoint IN LISTS LIBC_EXCLUDE_ENTRYPOINTS)
   ...
```

https://github.com/llvm/llvm-project/pull/72318


More information about the libc-commits mailing list