Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c279bf2
add VCPKG_ANDROID_NATIVE_API_LEVEL environment variable into triple f…
holmesconan Dec 4, 2021
70b610f
fix: ANDROID_PLATFORM
holmesconan Dec 4, 2021
b92e645
fix: vcpkg_configure_make cross-compile for Android.
holmesconan Dec 4, 2021
d3e7ecd
fix: remove CFLAGS_target, CXXFLAGS_target, just patch the VCPKG_DETE…
holmesconan Dec 6, 2021
32fe1d9
fix: check command PATH exists in current environment
holmesconan Dec 6, 2021
44b16b8
fix: regression error
holmesconan Dec 6, 2021
47cb665
fix: ensure the toolchain path is the first
holmesconan Dec 7, 2021
fa44824
fix: #21465 based on the NDK version
holmesconan Dec 7, 2021
c17c234
fix: move --target flag into get_cmake_vars
holmesconan Dec 9, 2021
4dcfd31
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 9, 2021
42a6154
fix: use full path of detected toolchain
holmesconan Dec 10, 2021
873e39b
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 10, 2021
7ed118c
fix: disable export detected toolchain into environment when target i…
holmesconan Dec 11, 2021
988682b
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 11, 2021
5b8af5c
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 13, 2021
522b2e3
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 14, 2021
07ee3b4
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 15, 2021
ee40c8c
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 18, 2021
d11d7a0
fix: Android r18 and older error message.
holmesconan Dec 20, 2021
1e9816f
refine VCPKG_ANDROID_NATIVE_API_LEVEL match logic
holmesconan Dec 20, 2021
02004ea
fix: install vcpkg_configure_make on arm-android/arm64-android for An…
holmesconan Dec 20, 2021
4ef9c8c
fix: use APPEND instead of PREPEND in get_cmake_vars to add --target …
holmesconan Dec 22, 2021
91a9620
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 22, 2021
206791a
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 23, 2021
c123f02
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 24, 2021
e226a27
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 28, 2021
ba49367
suggestion accept: merge vcpkg_backup_env_variables
holmesconan Dec 30, 2021
7e04a6b
suggestion accept: z_vcpkg_setup_detected_env
holmesconan Dec 30, 2021
e2015e1
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Dec 31, 2021
8742793
[skip actions] CI
holmesconan Jan 5, 2022
4281b88
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Jan 5, 2022
b6afd4b
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Jan 10, 2022
e2f9a86
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Jan 13, 2022
7ecb979
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Jan 15, 2022
b90a028
fix: add READELF to build python for android
holmesconan Jan 17, 2022
759f0f2
Merge branch 'master' of https://github.com/microsoft/vcpkg into enha…
holmesconan Mar 30, 2022
199b0d4
disabled the controversial code
holmesconan Mar 30, 2022
5d3e0e8
don't append ANDROID_NATIVE_API_LEVEL when it is there.
holmesconan Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions scripts/cmake/vcpkg_configure_make.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ macro(z_vcpkg_determine_autotools_host_cpu out_var)
endif()
if(host_arch MATCHES "(amd|AMD)64")
set(${out_var} x86_64)
elseif(host_arch MATCHES "(x|X)86_64")
set(${out_var} x86_64)
Comment thread
strega-nil-ms marked this conversation as resolved.
elseif(host_arch MATCHES "(x|X)86")
set(${out_var} i686)
elseif(host_arch MATCHES "^(ARM|arm)64$")
Expand Down Expand Up @@ -225,6 +227,14 @@ macro(z_convert_to_list input output)
string(REGEX MATCHALL "(( +|^ *)[^ ]+)" ${output} "${${input}}")
endmacro()

macro(z_vcpkg_setup_detected_env env_name cmake_var)
if(VCPKG_DETECTED_${cmake_var})
if(NOT VCPKG_TARGET_IS_OSX)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't know the details since my MBP is dead. This fix is provided because the regression error of x64_osx. And the regression error shows that cc is not available which is detected by CMake. So skip all toolchain tools detected by CMake for OSX to simply resolve the problem.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not okay with not getting a real explanation for this.

@m-kuhn m-kuhn Jun 9, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to investigate the issues here:

By using the detected env, e.g. CC is set via VCPKG_DETECTED_CMAKE_C_COMPILER detected by get_cmake_vars to "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"

Without the detected env, it's set to gcc

> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc --version
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

> gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@m-kuhn m-kuhn Jun 9, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildtrees/gettext/build-x64-osx-dbg-err.log
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/l10nflist.c:28:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/string.h:152:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_ssize_t.h:31:33: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_ssize_t        ssize_t;
                                ^
../config.h:1480:17: note: expanded from macro 'ssize_t'
#define ssize_t int
                ^
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/explodename.c:21:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/stdlib.h:66:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/wait.h:109:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/signal.h:156:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_uid_t.h:31:31: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_uid_t        uid_t;
                              ^
../config.h:1483:15: note: expanded from macro 'uid_t'
#define uid_t int
              ^
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/l10nflist.c:34:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/types.h:109:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_gid_t.h:31:25: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_gid_t  gid_t;
                        ^
../config.h:1392:15: note: expanded from macro 'gid_t'
#define gid_t int
              ^
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/l10nflist.c:34:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/types.h:128:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_uid_t.h:31:31: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_uid_t        uid_t;
                              ^
../config.h:1483:15: note: expanded from macro 'uid_t'
#define uid_t int
              ^
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/localcharset.c:26:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/stdio.h:342:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_ssize_t.h:31:33: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_ssize_t        ssize_t;
                                ^
../config.h:1480:17: note: expanded from macro 'ssize_t'
#define ssize_t int
                ^
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/plural-exp.c:23:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/stdlib.h:66:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/wait.h:109:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/signal.h:156:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_uid_t.h:31:31: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_uid_t        uid_t;
                              ^
../config.h:1483:15: note: expanded from macro 'uid_t'
#define uid_t int
              ^
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/localcharset.c:28:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/stdlib.h:66:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/wait.h:109:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/signal.h:156:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_uid_t.h:31:31: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_uid_t        uid_t;
                              ^
../config.h:1483:15: note: expanded from macro 'uid_t'
#define uid_t int
              ^
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/plural-exp.c:24:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/string.h:152:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_ssize_t.h:31:33: error: cannot combine with previous 'type-name' declaration specifier
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/explodename.c:22:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/string.h:152:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_ssize_t.h:31:33: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_ssize_t        ssize_t;
                                ^
../config.h:1480:17: note: expanded from macro 'ssize_t'
#define ssize_t int
                ^
typedef __darwin_ssize_t        ssize_t;
                                ^
../config.h:1480:17: note: expanded from macro 'ssize_t'
#define ssize_t int
                ^
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/explodename.c:23:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/types.h:109:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_gid_t.h:31:25: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_gid_t  gid_t;
                        ^
../config.h:1392:15: note: expanded from macro 'gid_t'
#define gid_t int
              ^
2 errors generated.
3 errors generated.
3 errors generated.
make[2]: *** [plural-exp.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
2 errors generated.
make[2]: *** [l10nflist.lo] Error 1
make[2]: *** [explodename.lo] Error 1
make[2]: *** [localcharset.lo] Error 1
In file included from .././../src/0.21-66fbad380c.clean/gettext-runtime/intl/threadlib.c:28:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/stdlib.h:66:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/wait.h:109:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/signal.h:156:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/_types/_uid_t.h:31:31: error: cannot combine with previous 'type-name' declaration specifier
typedef __darwin_uid_t        uid_t;
                              ^
../config.h:1483:15: note: expanded from macro 'uid_t'
#define uid_t int
              ^
1 error generated.
make[2]: *** [threadlib.lo] Error 1
make[1]: *** [all] Error 2
make: *** [build-intl] Error 2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the question is:
Is gcc a wrapper with additional include and -L paths being setup?
I see --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 which probably have an effect.
Is there a way to get these from CMake somehow?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, gcc is a wrapper (binary executable) that forwards tools that implicitly use gcc to clang.

When it tries to detect for uid_t, the test program fails with missing include sys/types.h which very much looks like a missing include folder. To be continued.

@m-kuhn m-kuhn Jun 12, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gettext-runtime/configure calls $CPP $CPPFLAGS conftest.$ac_ext which expands to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -E -DNDEBUG conftest.c. This way it does not find the include.

Adding -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk to this call fixes the include.

Hence adding this to CPPFLAGS should fix the issue too.

The following detected variables contain -isysroot

set(VCPKG_DETECTED_RAW_CMAKE_C_FLAGS " -fPIC -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk")
set(VCPKG_DETECTED_CMAKE_C_FLAGS_RELEASE "-fPIC -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -O3 -DNDEBUG")
set(VCPKG_DETECTED_RAW_CMAKE_CXX_FLAGS " -fPIC -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk")
set(VCPKG_DETECTED_CMAKE_CXX_FLAGS_RELEASE "-fPIC -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -O3 -DNDEBUG")

The question that I am not able to answer yet:

  • Is it correct to fixup CPPFLAGS? If yes with what?
  • Is gettext doing something wrong and should it also pass CXXFLAGS?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z_vcpkg_extract_cpp_flags_and_set_cflags_and_cxxflags in vcpkg_configure_make uses regex magic to extract CPPFLAGS from CMAKE_C_FLAGS and CMAKE_CXX_FLAGS.

https://github.com/microsoft/vcpkg/blob/7d2449c/scripts/cmake/vcpkg_configure_make.cmake#L76-L109

Looks like the same has been experienced elsewhere before

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set(ENV{${env_name}} "${VCPKG_DETECTED_${cmake_var}}")
endif()
endif()
endmacro()
Comment on lines +230 to +236

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be a macro:

Suggested change
macro(z_vcpkg_setup_detected_env env_name cmake_var)
if(VCPKG_DETECTED_${cmake_var})
if(NOT VCPKG_TARGET_IS_OSX)
set(ENV{${env_name}} "${VCPKG_DETECTED_${cmake_var}}")
endif()
endif()
endmacro()
function(z_vcpkg_setup_detected_env env_name cmake_var)
if(DEFINED VCPKG_DETECTED_${cmake_var})
if(NOT VCPKG_TARGET_IS_OSX)
set("ENV{${env_name}}" "${VCPKG_DETECTED_${cmake_var}}")
endif()
endif()
endfunction()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with you. I don't know why most vcpkg functions are declared as macros. I think it is because the very first function was declared as a macro, then the following contributors follow the convention. So let's follow the convention either. Although functions are better, macros work fine either.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most vcpkg functions are not declared as macros. This specifically should not be.


function(vcpkg_configure_make)
# parse parameters such that semicolons in options arguments to COMMAND don't get erased
cmake_parse_arguments(PARSE_ARGV 0 arg
Expand Down Expand Up @@ -282,8 +292,9 @@ function(vcpkg_configure_make)
# Backup environment variables
# CCAS CC C CPP CXX FC FF GC LD LF LIBTOOL OBJC OBJCXX R UPC Y
set(cm_FLAGS AS CCAS CC C CPP CXX FC FF GC LD LF LIBTOOL OBJC OBJXX R UPC Y RC)
set(cm_TOOLS CC CXX AR AS LD RANLIB READELF STRIP)
list(TRANSFORM cm_FLAGS APPEND "FLAGS")
vcpkg_backup_env_variables(VARS ${cm_FLAGS})
vcpkg_backup_env_variables(VARS ${cm_FLAGS} ${cm_TOOLS})


# FC fotran compiler | FF Fortran 77 compiler
Expand Down Expand Up @@ -469,6 +480,36 @@ function(vcpkg_configure_make)
endif()
endif()

# Android - cross-compiling support
if(VCPKG_TARGET_IS_ANDROID)
# This is temporarily disabled since it just avoid some warnings.
# if(VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# string(REPLACE "-static-libstdc++" "-lc++_static" VCPKG_DETECTED_CMAKE_CXX_STANDARD_LIBRARIES ${VCPKG_DETECTED_CMAKE_CXX_STANDARD_LIBRARIES})
# endif()

if(arg_DETERMINE_BUILD_TRIPLET OR NOT arg_BUILD_TRIPLET)
if(VCPKG_HOST_IS_WINDOWS)
z_vcpkg_determine_autotools_host_cpu(BUILD_ARCH)
z_vcpkg_determine_host_mingw(BUILD_MINGW)
set(arg_BUILD_TRIPLET "--build=${BUILD_ARCH}-pc-${BUILD_MINGW}")
elseif(VCPKG_HOST_IS_OSX)
z_vcpkg_determine_autotools_host_arch_mac(BUILD_ARCH)
set(arg_BUILD_TRIPLET "--build=${BUILD_ARCH}-apple-darwin")
else()
z_vcpkg_determine_autotools_host_cpu(BUILD_ARCH)
set(arg_BUILD_TRIPLET "--build=${BUILD_ARCH}-pc-linux-gnu")
endif()

z_vcpkg_determine_autotools_target_cpu(TARGET_ARCH)
if(TARGET_ARCH MATCHES "armv7-a")
string(APPEND arg_BUILD_TRIPLET " --host=arm-linux-androideabi")
else()
string(APPEND arg_BUILD_TRIPLET " --host=${TARGET_ARCH}-linux-android")
endif()
endif()
debug_message("Using make triplet: ${arg_BUILD_TRIPLET}")
endif()

# Linux - cross-compiling support
if(VCPKG_TARGET_IS_LINUX)
if (requires_autoconfig AND NOT arg_BUILD_TRIPLET OR arg_DETERMINE_BUILD_TRIPLET)
Expand Down Expand Up @@ -745,6 +786,13 @@ function(vcpkg_configure_make)
vcpkg_list(JOIN tmp " " "${var}")
endforeach()

foreach(tool IN ITEMS AR AS MT NM RANLIB READELF STRIP OBJDUMP DLLTOOL)
z_vcpkg_setup_detected_env(${tool} "CMAKE_${tool}")
endforeach()
z_vcpkg_setup_detected_env(CC CMAKE_C_COMPILER)
z_vcpkg_setup_detected_env(CXX CMAKE_CXX_COMPILER)
z_vcpkg_setup_detected_env(LD CMAKE_LINKER)

foreach(current_buildtype IN LISTS all_buildtypes)
foreach(ENV_VAR ${arg_CONFIG_DEPENDENT_ENVIRONMENT})
if(DEFINED ENV{${ENV_VAR}})
Expand Down Expand Up @@ -772,7 +820,6 @@ function(vcpkg_configure_make)
set(ENV{PKG_CONFIG_PATH} "${pkgconfig_installed_dir}${VCPKG_HOST_PATH_SEPARATOR}${pkgconfig_installed_share_dir}")
endif()

# Setup environment
set(ENV{CPPFLAGS} "${CPPFLAGS_${current_buildtype}}")
set(ENV{CFLAGS} "${CFLAGS_${current_buildtype}}")
set(ENV{CXXFLAGS} "${CXXFLAGS_${current_buildtype}}")
Expand Down Expand Up @@ -866,7 +913,7 @@ function(vcpkg_configure_make)
endif()

# Restore environment
vcpkg_restore_env_variables(VARS ${cm_FLAGS} LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)
vcpkg_restore_env_variables(VARS ${cm_FLAGS} ${cm_TOOLS} LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)

set(_VCPKG_PROJECT_SOURCE_PATH ${arg_SOURCE_PATH} PARENT_SCOPE)
set(_VCPKG_PROJECT_SUBPATH ${arg_PROJECT_SUBPATH} PARENT_SCOPE)
Expand Down
22 changes: 18 additions & 4 deletions scripts/get_cmake_vars/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ set(OUTPUT_STRING)
# Build default checklists
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_CROSSCOMPILING
CMAKE_SYSTEM_NAME
CMAKE_HOST_SYSTEM_NAME
CMAKE_SYSTEM_VERSION
CMAKE_SYSTEM_PROCESSOR
CMAKE_HOST_SYSTEM_NAME
CMAKE_HOST_SYSTEM_PROCESSOR)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_SYSROOT)
endif()
# Programs to check
set(PROGLIST AR RANLIB STRIP NM OBJDUMP DLLTOOL MT LINKER)
set(PROGLIST AR RANLIB READELF STRIP NM OBJDUMP DLLTOOL MT LINKER)
foreach(prog IN LISTS PROGLIST)
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${prog})
endforeach()
Expand Down Expand Up @@ -97,7 +98,6 @@ macro(_vcpkg_adjust_flags flag_var)
if("${flag_var}" IN_LIST VCPKG_LANG_FLAGS)
# macOS - append arch and isysroot if cross-compiling
if(NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}")

foreach(arch IN LISTS CMAKE_OSX_ARCHITECTURES)
string(APPEND ${flag_var} " -arch ${arch}")
endforeach()
Expand All @@ -108,6 +108,21 @@ macro(_vcpkg_adjust_flags flag_var)
endif()
endif()
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Android")
if("${flag_var}" MATCHES "CMAKE_(C|CXX)_FLAGS$")
if(ANDROID_NDK_MAJOR GREATER_EQUAL 23)
if (ANDROID_LLVM_TRIPLE MATCHES "[0-9]+")
string(APPEND ${flag_var} " ${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${ANDROID_LLVM_TRIPLE} ")
else()
string(APPEND ${flag_var} " ${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${ANDROID_LLVM_TRIPLE}${ANDROID_NATIVE_API_LEVEL} ")
endif()
elseif(ANDROID_NDK_MAJOR GREATER_EQUAL 19)
string(REGEX REPLACE "-march=[^ ]+" "" ${flag_var} "${${flag_var}}")
string(REGEX REPLACE "-mtune=[^ ]+" "" ${flag_var} "${${flag_var}}")
string(APPEND ${flag_var} " ${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${ANDROID_LLVM_TRIPLE} ")
endif()
endif()
endif()
endmacro()

foreach(flag IN LISTS VCPKG_FLAGS_TO_CHECK)
Expand All @@ -124,7 +139,6 @@ foreach(flag IN LISTS VCPKG_FLAGS_TO_CHECK)
endforeach()
endforeach()


file(WRITE "${VCPKG_OUTPUT_FILE}" "${OUTPUT_STRING}")

# Programs:
Expand Down
31 changes: 27 additions & 4 deletions scripts/toolchains/android.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
set(ANDROID_CPP_FEATURES "rtti exceptions" CACHE STRING "")
set(CMAKE_SYSTEM_NAME Android CACHE STRING "")
set(ANDROID_TOOLCHAIN clang CACHE STRING "")
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang CACHE STRING "")

if ($ENV{VCPKG_ANDROID_NATIVE_API_LEVEL} STREQUAL "detect")
set(ANDROID_NATIVE_API_LEVEL ${CMAKE_SYSTEM_VERSION} CACHE STRING "")
if(CMAKE_SYSTEM_VERSION MATCHES "^[0-9]+$")
set(ANDROID_PLATFORM android-${CMAKE_SYSTEM_VERSION} CACHE STRING "")
elseif ($ENV{VCPKG_ANDROID_NATIVE_API_LEVEL} MATCHES "^[1-3][0-9]$")
set(ANDROID_NATIVE_API_LEVEL $ENV{VCPKG_ANDROID_NATIVE_API_LEVEL} CACHE STRING "")
else()
set(ANDROID_PLATFORM ${CMAKE_SYSTEM_VERSION} CACHE STRING "")
message(FATAL_ERROR "$VCPKG_ANDROID_NATIVE_API_LEVEL should be two digits or \"detect\"")
endif()
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang CACHE STRING "")

if (VCPKG_TARGET_TRIPLET MATCHES "arm64-android")
set(ANDROID_ABI arm64-v8a CACHE STRING "")
Expand Down Expand Up @@ -48,6 +50,27 @@ if(NOT EXISTS "${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake")
message(FATAL_ERROR "Could not find android ndk. Searched at ${ANDROID_NDK_HOME}")
endif()

# Android NDK revision
file(READ "${ANDROID_NDK_HOME}/source.properties" ANDROID_NDK_SOURCE_PROPERTIES)

set(ANDROID_NDK_REVISION_REGEX
"^Pkg\\.Desc = Android NDK\nPkg\\.Revision = ([0-9]+)\\.([0-9]+)\\.([0-9]+)(-beta([0-9]+))?")
if(NOT ANDROID_NDK_SOURCE_PROPERTIES MATCHES "${ANDROID_NDK_REVISION_REGEX}")
message(SEND_ERROR "Failed to parse Android NDK revision: ${CMAKE_ANDROID_NDK}/source.properties.\n${ANDROID_NDK_SOURCE_PROPERTIES}")
endif()

set(ANDROID_NDK_MAJOR "${CMAKE_MATCH_1}")
#set(ANDROID_NDK_MINOR "${CMAKE_MATCH_2}")
#set(ANDROID_NDK_BUILD "${CMAKE_MATCH_3}")

if(ANDROID_NDK_MAJOR GREATER 20)
set(ANDROID_PLATFORM "${ANDROID_NATIVE_API_LEVEL}")
elseif(ANDROID_NDK_MAJOR GREATER 18)
set(ANDROID_PLATFORM "android-${ANDROID_NDK_MAJOR}")
else()
message(FATAL_ERROR "Android NDK r18 and older is not supported yet")
endif()

include("${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake")

if(NOT _VCPKG_ANDROID_TOOLCHAIN)
Expand Down
3 changes: 3 additions & 0 deletions triplets/community/arm-android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ set(VCPKG_TARGET_ARCHITECTURE arm)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
# If you need to specify the ANDROID_NATIVE_API_LEVEL,
# please use the overlay triplet and set the value below
set(ENV{VCPKG_ANDROID_NATIVE_API_LEVEL} "detect")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is "detect" handled?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$VCPKG_ROOT/scripts/toolchain/android.cmake, line 6

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably more obvious if that line 6 would actually check for "detect" instead of matching other values.

3 changes: 3 additions & 0 deletions triplets/community/arm-neon-android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ set(VCPKG_TARGET_ARCHITECTURE arm)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
# If you need to specify the ANDROID_NATIVE_API_LEVEL,
# please use the overlay triplet and set the value below
set(ENV{VCPKG_ANDROID_NATIVE_API_LEVEL} "detect")
3 changes: 3 additions & 0 deletions triplets/community/arm64-android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
# If you need to specify the ANDROID_NATIVE_API_LEVEL,
# please use the overlay triplet and set the value below
set(ENV{VCPKG_ANDROID_NATIVE_API_LEVEL} "detect")
3 changes: 3 additions & 0 deletions triplets/community/armv6-android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ set(VCPKG_TARGET_ARCHITECTURE arm)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
# If you need to specify the ANDROID_NATIVE_API_LEVEL,
# please use the overlay triplet and set the value below
set(ENV{VCPKG_ANDROID_NATIVE_API_LEVEL} "detect")
3 changes: 3 additions & 0 deletions triplets/community/x64-android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
# If you need to specify the ANDROID_NATIVE_API_LEVEL,
# please use the overlay triplet and set the value below
set(ENV{VCPKG_ANDROID_NATIVE_API_LEVEL} "detect")
3 changes: 3 additions & 0 deletions triplets/community/x86-android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Android)
# If you need to specify the ANDROID_NATIVE_API_LEVEL,
# please use the overlay triplet and set the value below
set(ENV{VCPKG_ANDROID_NATIVE_API_LEVEL} "detect")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this an environment variable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read this thread: #21847 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this entirely in the toolchain instead? setting environment variables in the triplet is Not Okay, imo