From 7115ef469d20bf4a3aba3dcfbb38629bcc57ac5b Mon Sep 17 00:00:00 2001 From: pastdue <30942300+past-due@users.noreply.github.com> Date: Thu, 28 Jan 2021 22:38:32 -0500 Subject: vcpkg_configure_make: Support macOS cross-compile (#15659) * vcpkg_configure_make: Support macOS cross-compile * Move compiler flags logic to get_cmake_vars * Better match the arch behavior of config.guess * Apply suggestions from code review Co-authored-by: Billy O'Neal Co-authored-by: Billy O'Neal --- scripts/cmake/vcpkg_configure_make.cmake | 43 ++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'scripts/cmake') diff --git a/scripts/cmake/vcpkg_configure_make.cmake b/scripts/cmake/vcpkg_configure_make.cmake index 122281f42..c30de38bd 100644 --- a/scripts/cmake/vcpkg_configure_make.cmake +++ b/scripts/cmake/vcpkg_configure_make.cmake @@ -139,6 +139,26 @@ macro(_vcpkg_determine_autotools_target_cpu out_var) endif() endmacro() +macro(_vcpkg_determine_autotools_host_arch_mac out_var) + set(${out_var} "${VCPKG_DETECTED_CMAKE_HOST_SYSTEM_PROCESSOR}") +endmacro() + +macro(_vcpkg_determine_autotools_target_arch_mac out_var) + list(LENGTH VCPKG_OSX_ARCHITECTURES _num_osx_archs) + if(_num_osx_archs GREATER_EQUAL 2) + set(${out_var} "universal") + else() + # Better match the arch behavior of config.guess + # See: https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD + if(VCPKG_OSX_ARCHITECTURES MATCHES "^(ARM|arm)64$") + set(${out_var} "aarch64") + else() + set(${out_var} "${VCPKG_OSX_ARCHITECTURES}") + endif() + endif() + unset(_num_osx_archs) +endmacro() + macro(_vcpkg_backup_env_variable envvar) if(DEFINED ENV{${envvar}}) set(${envvar}_BACKUP "$ENV{${envvar}}") @@ -407,6 +427,25 @@ function(vcpkg_configure_make) set(prefix_var "\${prefix}") endif() + # macOS - cross-compiling support + if(VCPKG_TARGET_IS_OSX) + if (_csc_AUTOCONFIG AND NOT _csc_BUILD_TRIPLET OR _csc_DETERMINE_BUILD_TRIPLET) + _vcpkg_determine_autotools_host_arch_mac(BUILD_ARCH) # machine you are building on => --build= + _vcpkg_determine_autotools_target_arch_mac(TARGET_ARCH) + # --build: the machine you are building on + # --host: the machine you are building for + # --target: the machine that CC will produce binaries for + # https://stackoverflow.com/questions/21990021/how-to-determine-host-value-for-configure-when-using-cross-compiler + # Only for ports using autotools so we can assume that they follow the common conventions for build/target/host + set(_csc_BUILD_TRIPLET "--build=${BUILD_ARCH}-apple-darwin") + if(NOT "${TARGET_ARCH}" STREQUAL "${BUILD_ARCH}") # we don't need to specify the additional flags if we build natively. + + list(APPEND _csc_BUILD_TRIPLET "--host=${TARGET_ARCH}-apple-darwin") # (Host activates crosscompilation; The name given here is just the prefix of the host tools for the target) + endif() + debug_message("Using make triplet: ${_csc_BUILD_TRIPLET}") + endif() + endif() + # Cleanup previous build dirs file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" @@ -671,8 +710,8 @@ function(vcpkg_configure_make) if (CMAKE_HOST_WIN32) set(command ${base_cmd} -c "${CONFIGURE_ENV} ./${RELATIVE_BUILD_PATH}/configure ${_csc_BUILD_TRIPLET} ${_csc_OPTIONS} ${_csc_OPTIONS_${_buildtype}}") else() - find_program(BASH bash REQUIRED) - set(command "${BASH}" "./${RELATIVE_BUILD_PATH}/configure" ${_csc_BUILD_TRIPLET} ${_csc_OPTIONS} ${_csc_OPTIONS_${_buildtype}}) + find_program(BASH bash REQUIRED) + set(command "${BASH}" "./${RELATIVE_BUILD_PATH}/configure" ${_csc_BUILD_TRIPLET} ${_csc_OPTIONS} ${_csc_OPTIONS_${_buildtype}}) endif() if(_csc_ADD_BIN_TO_PATH) set(PATH_BACKUP $ENV{PATH}) -- cgit v1.2.3