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}")