]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Read architecture name from binary in detect-arch.
authorNathan Moinvaziri <nathan@nathanm.com>
Sat, 17 Jan 2026 18:10:49 +0000 (10:10 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 24 Jan 2026 20:48:57 +0000 (21:48 +0100)
cmake/detect-arch.cmake

index 3f8e2c4da59bd921ec5d97203ab5ea186a58e910..d98243fc8f6337d86fa05a0a02565525a44c5ded 100644 (file)
@@ -11,15 +11,18 @@ elseif(EMSCRIPTEN)
 elseif(CMAKE_CROSSCOMPILING)
     set(ARCH ${CMAKE_C_COMPILER_TARGET})
 else()
-    # Compile and run detect-arch.c which prints architecture name to stderr
-    try_run(
-        run_result_unused
-        compile_result_unused
+    # Compile detect-arch.c and read the architecture name from the binary
+    try_compile(
+        COMPILE_RESULT
         ${CMAKE_CURRENT_BINARY_DIR}
         ${CMAKE_CURRENT_LIST_DIR}/detect-arch.c
         CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
-        RUN_OUTPUT_VARIABLE RAWOUTPUT
+        COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/detect-arch.bin
     )
+    if(COMPILE_RESULT)
+        file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/detect-arch.bin
+            RAWOUTPUT REGEX "archfound [a-zA-Z0-9_]+")
+    endif()
 
     # Find archfound tag, and extract the arch word into ARCH variable
     string(REGEX REPLACE ".*archfound ([a-zA-Z0-9_]+).*" "\\1" ARCH "${RAWOUTPUT}")