--- CMakeLists.txt 2026-07-17 03:53:40.000000000 +0800 +++ CMakeLists.txt 2026-07-24 18:30:29.000000000 +0800 @@ -244,38 +244,6 @@ endforeach() endif () -# Work around Apple issue with "argument list too long" when linking. -# Seen for DYNAMIC_ARCH when there are a _LOT_ of variants build, previously -# mostly with older versions on POWERPC or Intel CPUs, but with newer ARM -# CPUs and newer compilers this will also occur on ARM. -# -# This must happen before the add_library() calls, otherwise this will have -# no effect. -# -# Unfortunately, while this workaround will work for shared libraries (with -# either Ninja oder Unix Makefiles), but not for static libraries, as ar -# does not accept response files. So for the case where we (also) build -# static libraries we need an additional workaround, see below. (The -# generation of the response files by CMake must still be enabled, so this -# is required regardless.) -if(APPLE) - set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS ON) - set(CMAKE_C_USE_RESPONSE_FILE_FOR_LIBRARIES ON) - if(NOT NOFORTRAN) - set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS ON) - set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_LIBRARIES ON) - # NAG Fortran does not support the GCC-specific -x f95-cpp-input flag - # used in the shared library link rule below. Override - # CMAKE_Fortran_CREATE_SHARED_LIBRARY early (before targets are defined) - # to use the C compiler link rule instead; the shared library contains - # only C and assembler objects so this is safe. - if(CMAKE_Fortran_COMPILER_ID MATCHES "NAG") - set(CMAKE_Fortran_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY}) - endif() - endif() - set(CMAKE_NINJA_FORCE_RESPONSE_FILE ON) -endif() - # add objects to the openblas lib if(NOT NO_LAPACK) add_library(LAPACK_OVERRIDES OBJECT ${LA_SOURCES}) @@ -341,22 +309,20 @@ endif() endif() -# Second part of "Argument list too long" fix when static libraries are -# built. See above for details. -if(APPLE AND BUILD_STATIC_LIBS) +# Fix "Argument list too long" for macOS - mostly seen with older OS versions on POWERPC or Intel CPUs +if(APPLE AND "${CMAKE_GENERATOR}" MATCHES ".*Makefiles") + # Use response files to get around the ARG_MAX limit, unless using the Ninja generator + set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1) # Always build static library first - set(STATIC_PATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${OpenBLAS_LIBNAME}.a") - # Handle differences in how many response files are generated and/or where - # they are stored for Ninja / Unix Makefiles. - if("${CMAKE_GENERATOR}" MATCHES "Ninja") - set(CREATE_STATIC_LIBRARY_COMMAND - "sh -c 'cat ${CMAKE_BINARY_DIR}/CMakeFiles/openblas_static.rsp | xargs -n 1024 ${CMAKE_AR} -ru ${STATIC_PATH} && exit 0' " - "sh -c '${CMAKE_AR} -rs ${STATIC_PATH} ${CMAKE_BINARY_DIR}/driver/others/CMakeFiles/driver_others.dir/xerbla.c.o && exit 0' ") - else() - set(CREATE_STATIC_LIBRARY_COMMAND - "sh -c 'cat ${CMAKE_BINARY_DIR}/CMakeFiles/${OpenBLAS_LIBNAME}_static.dir/objects*.rsp | xargs -n 1024 ${CMAKE_AR} -ru ${STATIC_PATH} && exit 0' " - "sh -c '${CMAKE_AR} -rs ${STATIC_PATH} ${CMAKE_BINARY_DIR}/driver/others/CMakeFiles/driver_others.dir/xerbla.c.o && exit 0' ") + if(BUILD_STATIC_LIBS) + set(STATIC_PATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${OpenBLAS_LIBNAME}.a") + else() + add_library(${OpenBLAS_LIBNAME}_static STATIC ${TARGET_OBJS} ${OpenBLAS_DEF_FILE}) + set(STATIC_PATH "lib${OpenBLAS_LIBNAME}.a") endif() + set(CREATE_STATIC_LIBRARY_COMMAND + "sh -c 'cat ${CMAKE_BINARY_DIR}/CMakeFiles/${OpenBLAS_LIBNAME}_static.dir/objects*.rsp | xargs -n 1024 ${CMAKE_AR} -ru ${STATIC_PATH} && exit 0' " + "sh -c '${CMAKE_AR} -rs ${STATIC_PATH} ${CMAKE_BINARY_DIR}/driver/others/CMakeFiles/driver_others.dir/xerbla.c.o && exit 0' ") if(BUILD_SHARED_LIBS) add_dependencies(${OpenBLAS_LIBNAME}_shared ${OpenBLAS_LIBNAME}_static) set(SHARED_PATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libopenblas.${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}.dylib") @@ -367,6 +333,7 @@ set(OMP_LIB "") endif() if(NOT NOFORTRAN) + set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1) set(CMAKE_Fortran_CREATE_STATIC_LIBRARY ${CREATE_STATIC_LIBRARY_COMMAND}) if(BUILD_SHARED_LIBS) if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")