diff --git a/ports/vcpkg-make/vcpkg_make.cmake b/ports/vcpkg-make/vcpkg_make.cmake index 757b2bd7fdf565..9f995c453a2537 100644 --- a/ports/vcpkg-make/vcpkg_make.cmake +++ b/ports/vcpkg-make/vcpkg_make.cmake @@ -120,8 +120,8 @@ endfunction() function(z_vcpkg_make_get_configure_triplets out) cmake_parse_arguments(PARSE_ARGV 1 arg - "" - "COMPILER_NAME" + "AVOID_BUILD_TRIPLET" + "COMPILER_NAME;CONFIG_DIR" "" ) z_vcpkg_unparsed_args(FATAL_ERROR) @@ -140,7 +140,7 @@ function(z_vcpkg_make_get_configure_triplets out) set(build_triplet_opt "--build=${BUILD_ARCH}-pc-mingw32") endif() - set(host_triplet "") + set(host_triplet_opt "") if(VCPKG_CROSSCOMPILING) if(VCPKG_TARGET_IS_WINDOWS) if(NOT TARGET_ARCH MATCHES "${BUILD_ARCH}" OR NOT CMAKE_HOST_WIN32) @@ -158,6 +158,41 @@ function(z_vcpkg_make_get_configure_triplets out) endif() endif() + if (host_triplet_opt AND NOT build_triplet_opt AND NOT arg_AVOID_BUILD_TRIPLET) + # According to the autoconf manual, when specifying --host, one should always also specify + # --build. It is mentioned that this was due to historic reasons and that it will be fixed + # in some future version but for now, we should do exactly as recommended. + if (arg_CONFIG_DIR) + cmake_path(ABSOLUTE_PATH "config.guess" BASE_DIRECTORY "${arg_CONFIG_DIR}" OUTPUT_VARIABLE config_guess_file) + endif() + + if (EXISTS "${config_guess_file}") + if (CMAKE_HOST_WIN32) + vcpkg_execute_required_process( + COMMAND ${base_cmd} -c "${config_guess_file}" + LOGNAME "config.guess-${TARGET_TRIPLET}" + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE BUILD_TRIPLET + ) + else() + vcpkg_execute_required_process( + COMMAND "${config_guess_file}" + LOGNAME "config.guess-${TARGET_TRIPLET}" + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE BUILD_TRIPLET + ) + endif() + + set(build_triplet_opt "--build=${BUILD_TRIPLET}") + elseif (VCPKG_HOST_IS_WINDOWS) + set(build_triplet_opt "--build=${BUILD_ARCH}-pc-mingw32") + elseif (VCPKG_HOST_IS_LINUX) + set(build_triplet_opt "--build=${BUILD_ARCH}-pc-linux") + elseif (VCPKG_HOST_IS_IOS OR VCPKG_HOST_IS_OSX) + set(build_triplet_opt "--build=${BUILD_ARCH}-apple-darwin") + endif() + endif() + set(output "${build_triplet_opt};${host_triplet_opt}") string(STRIP "${output}" output) set("${out}" "${output}" PARENT_SCOPE) diff --git a/ports/vcpkg-make/vcpkg_make_configure.cmake b/ports/vcpkg-make/vcpkg_make_configure.cmake index 57ce70d9333684..859d22dd5ffa88 100644 --- a/ports/vcpkg-make/vcpkg_make_configure.cmake +++ b/ports/vcpkg-make/vcpkg_make_configure.cmake @@ -50,9 +50,6 @@ function(vcpkg_make_configure) if(DEFINED VCPKG_MAKE_BUILD_TRIPLET) set(BUILD_TRIPLET "${VCPKG_MAKE_BUILD_TRIPLET}") endif() - if(NOT DEFINED BUILD_TRIPLET) - z_vcpkg_make_get_configure_triplets(BUILD_TRIPLET COMPILER_NAME "${ccname}") - endif() if(NOT arg_DISABLE_MSVC_WRAPPERS AND "${frontend}" STREQUAL "MSVC" ) # Lets assume that wrappers are only required for MSVC like frontends. @@ -92,6 +89,10 @@ function(vcpkg_make_configure) set(relative_build_path ".") endif() + if(NOT DEFINED BUILD_TRIPLET) + z_vcpkg_make_get_configure_triplets(BUILD_TRIPLET COMPILER_NAME "${ccname}" CONFIG_DIR "${target_dir}") + endif() + z_vcpkg_make_prepare_programs(configure_env ${prepare_flags_opts} CONFIG "${configup}" BUILD_TRIPLET "${BUILD_TRIPLET}") set(opts "") diff --git a/scripts/cmake/vcpkg_configure_make.cmake b/scripts/cmake/vcpkg_configure_make.cmake index a3fe6826bfde63..73d94f956eadb2 100644 --- a/scripts/cmake/vcpkg_configure_make.cmake +++ b/scripts/cmake/vcpkg_configure_make.cmake @@ -754,39 +754,6 @@ function(vcpkg_configure_make) message(STATUS "Finished generating configure for ${TARGET_TRIPLET}") endif() - if ((arg_BUILD_TRIPLET MATCHES "--host") AND NOT (arg_BUILD_TRIPLET MATCHES "--build")) - # --host option specified but --build has been left out. According to the autoconf manual, - # whenever --host is set, --build must be too (for historical reasons). - # See https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Specifying-Target-Triplets.html - # -> Use config.guess to determine build triplet - if (EXISTS "config.guess") - if (CMAKE_HOST_WIN32) - vcpkg_execute_required_process( - COMMAND ${base_cmd} -c "./config.guess" - WORKING_DIRECTORY "${src_dir}" - LOGNAME "config.guess-${TARGET_TRIPLET}" - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE BUILD_TRIPLET - ) - else() - vcpkg_execute_required_process( - COMMAND "./config.guess" - WORKING_DIRECTORY "${src_dir}" - LOGNAME "config.guess-${TARGET_TRIPLET}" - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE BUILD_TRIPLET - ) - endif() - - string(APPEND arg_BUILD_TRIPLET " --build=${BUILD_TRIPLET}") - else() - # For the time being we'll assume that for projects that don't have a config.guess - # file, target triplets aren't that important and hence we can get away with not - # defining --build in addition to --host - debug_message("vcpkg will run configure with the --host option but without --build, which may cause issues") - endif() - endif() - if (arg_PRERUN_SHELL) message(STATUS "Prerun shell with ${TARGET_TRIPLET}") if (CMAKE_HOST_WIN32)