Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -275,16 +275,26 @@ execute_process( COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path OUTPUT_VARIABLE ${var} + RESULT_VARIABLE result_xcodebuild OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_FILE /dev/null ) + if(result_xcodebuild) + # clear ${var} content if the return status is non-zero + set(${var}) + endif() if(${var} STREQUAL "") execute_process( COMMAND xcodebuild -version -sdk ${sdk_name} Path OUTPUT_VARIABLE ${var} + RESULT_VARIABLE result_xcodebuild OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_FILE /dev/null ) + if(result_xcodebuild) + # clear ${var} content if the return status is non-zero + set(${var}) + endif() endif() endmacro() Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -102,6 +102,20 @@ # 2) simple file can be successfully built. # If successful, saves target flags for this architecture. macro(test_target_arch arch def) + if(APPLE) + # set appropriate -arch flag in order to test only one architecture + if(${arch} MATCHES "x86_64") + set(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES x86_64) + elseif(${arch} MATCHES "i386|i686") + set(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES i386) + elseif(${arch} MATCHES "powerpc64|powerpc64le") + set(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES ppc64) + elseif(${arch} MATCHES "arm") + set(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES armv7) + elseif(${arch} MATCHES "aarch64") + set(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES arm64) + endif() + endif() set(TARGET_${arch}_CFLAGS ${ARGN}) set(argstring "") foreach(arg ${ARGN}) @@ -123,6 +137,10 @@ # Bail out if we cannot target the architecture we plan to test. message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}") endif() + if(APPLE) + # unset flag necessary for testing only one architecture + set(CMAKE_TRY_COMPILE_OSX_ARCHITECTURES) + endif() endmacro() # Add $arch as supported with no additional flags.