Skip to content

Commit

Permalink
[vcpkg scripts] Crosscompiling fixes (#26617)
Browse files Browse the repository at this point in the history
* test osx stuff

* deactivate most of ci

* get trace output

* add required flags to the linker flags

* also look for --sysroot

* Link_args are always shared

* fix ar flags

* setup FOR_BUILD vars.

* try tricking the build.... but man configure scripts are stupid sometimes...

* try 2

* major meson rewrite

* fix duplicates

* revert --trace-expand

* update port version

* revert pipeline changes

* v db

* bump version

* v db

* set flags for rc compilers

* a few more ios fixes.

* v db

* fix osx/ios logic

* documentation and don't fatal_error in build/host machine entry calculation.

* add android/compiler target stuff from #26570

* remove extra endif

* v db

* add target param to linker flags.

* target in cpp flags

* Make vcpkg-cmake-get-vars more ios compatible

* Update scripts/get_cmake_vars/CMakeLists.txt

Co-authored-by: Matthias Kuhn <[email protected]>

* More ios fixes

* fix target adding

* Fix broken loop

* v db

* v db

* bump date

* v db

* v db

* v db

* remove port-version 1

* v db

Co-authored-by: JackBoosY <[email protected]>
Co-authored-by: Matthias Kuhn <[email protected]>
  • Loading branch information
3 people authored Oct 13, 2022
1 parent 6800713 commit d8e60ef
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 285 deletions.
5 changes: 5 additions & 0 deletions docs/users/triplets.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ This field is optional.

Also available as build-type specific `VCPKG_MESON_CONFIGURE_OPTIONS_DEBUG` and `VCPKG_MESON_CONFIGURE_OPTIONS_RELEASE` variables.

### VCPKG_MESON_(CROSS|NATIVE)_FILE(_RELEASE|_DEBUG)
Provide an additional (configuration dependent) file as a meson cross/native file. Can be used to override settings provided by vcpkg since it will be passed after vcpkg's generated cross/native files are passed.

Especially usefull to provide your own build_machine and host_machine entries.

### VCPKG_CMAKE_CONFIGURE_OPTIONS
Set additional CMake configure options that are appended to the configure command (in [`vcpkg_cmake_configure`](../maintainers/vcpkg_cmake_configure.md)).

Expand Down
33 changes: 18 additions & 15 deletions ports/vcpkg-cmake-get-vars/cmake_get_vars/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_CROSSCOMPILING
CMAKE_SIZEOF_VOID_P
MSVC
MSVC_VERSION)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if(APPLE)
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_SYSROOT)
endif()
Expand All @@ -33,7 +33,8 @@ foreach(_lang IN LISTS VCPKG_LANGUAGES)
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_STANDARD)
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_COMPILE_FEATURES)
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_EXTENSION)
# Probably never required since implicit.
list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_COMPILER_TARGET)
# Probably never required since implicit.
#list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES)
#list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_IMPLICIT_INCLUDE_DIRECTORIES)
#list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_${_lang}_IMPLICIT_LINK_DIRECTORIES)
Expand Down Expand Up @@ -101,18 +102,18 @@ if(APPLE)
string(APPEND EXTRA_FLAGS " -arch ${arch}")
endforeach()
if(CMAKE_OSX_DEPLOYMENT_TARGET)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
string(APPEND EXTRA_FLAGS " -mios-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
string(APPEND EXTRA_FLAGS " -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()
list(GET VCPKG_LANGUAGES 0 lang)
string(APPEND EXTRA_FLAGS " ${CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG}${CMAKE_OSX_DEPLOYMENT_TARGET}")
unset(lang)
endif()
endif()
if(CMAKE_CXX_COMPILER_TARGET)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
string(APPEND EXTRA_FLAGS " \"${CMAKE_CXX_COMPILE_OPTIONS_TARGET}${CMAKE_CXX_COMPILER_TARGET}\"")
elseif(CMAKE_CXX_COMPILE_OPTIONS_TARGET)
string(APPEND EXTRA_FLAGS " ${CMAKE_CXX_COMPILE_OPTIONS_TARGET} \"${CMAKE_CXX_COMPILER_TARGET}\"")
set(target_param "")
list(GET VCPKG_LANGUAGES 0 lang)
if(CMAKE_${lang}_COMPILER_TARGET)
if (CMAKE_${lang}_COMPILER_ID STREQUAL Clang)
set(target_param "${CMAKE_${lang}_COMPILE_OPTIONS_TARGET}${CMAKE_${lang}_COMPILER_TARGET}")
elseif(CMAKE_${lang}_COMPILE_OPTIONS_TARGET)
set(target_param "${CMAKE_${lang}_COMPILE_OPTIONS_TARGET} ${CMAKE_${lang}_COMPILER_TARGET}")
endif()
endif()
if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
Expand All @@ -126,12 +127,14 @@ if(CMAKE_SYSROOT AND CMAKE_CXX_COMPILE_OPTIONS_SYSROOT)
string(APPEND EXTRA_FLAGS " \"${CMAKE_CXX_COMPILE_OPTIONS_SYSROOT}${CMAKE_SYSROOT}\"")
endif()

foreach(flags CXX C SHARED_LINKER EXE_LINKER)
set(${flags}_FLAGS "${CMAKE_${flags}_FLAGS} ${CMAKE_${flags}_FLAGS_${VCPKG_CONFIGS}} ${EXTRA_FLAGS}")
foreach(flags ${VCPKG_LANGUAGES} SHARED_LINKER EXE_LINKER STATIC_LINKER MODULE_LINKER)
set(${flags}_FLAGS "${target_param} ${CMAKE_${flags}_FLAGS} ${CMAKE_${flags}_FLAGS_${VCPKG_CONFIGS}} ${EXTRA_FLAGS}")
string(STRIP ${flags}_FLAGS "${${flags}_FLAGS}")
endforeach()

foreach(flags STATIC_LINKER RC)
set(${flags}_FLAGS "${CMAKE_${flags}_FLAGS} ${CMAKE_${flags}_FLAGS_${VCPKG_CONFIGS}}")
string(STRIP ${flags}_FLAGS "${${flags}_FLAGS}")
endforeach()

foreach(incdir IN LISTS CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES)
Expand All @@ -142,7 +145,7 @@ foreach(incdir IN LISTS CMAKE_C_STANDARD_INCLUDE_DIRECTORIES)
string(APPEND C_FLAGS " \"${CMAKE_INCLUDE_FLAG_C}${incdir}\"")
endforeach()

foreach(flag CXX C SHARED_LINKER EXE_LINKER STATIC_LINKER RC)
foreach(flag ${VCPKG_LANGUAGES} SHARED_LINKER EXE_LINKER STATIC_LINKER MODULE_LINKER RC)
# When using MSVC, maybe transform /flags to -flags.
# When cross compiling, "/flags" may be an absolute path starting with /, so don't transform.
# Otherwise, transform to improve compatibility with scripts interpreting "/flags" as a path.
Expand Down
3 changes: 1 addition & 2 deletions ports/vcpkg-cmake-get-vars/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "vcpkg-cmake-get-vars",
"version-date": "2022-05-10",
"port-version": 1,
"version-date": "2022-09-04",
"documentation": "https://vcpkg.io/en/docs/README.html",
"license": "MIT",
"dependencies": [
Expand Down
2 changes: 1 addition & 1 deletion ports/vcpkg-cmake/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vcpkg-cmake",
"version-date": "2022-09-13",
"version-date": "2022-09-26",
"documentation": "https://vcpkg.io/en/docs/maintainers/ports/vcpkg-cmake.html",
"license": "MIT"
}
42 changes: 42 additions & 0 deletions scripts/buildsystems/meson/meson.template.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[binaries]
cmake = ['@CMAKE_COMMAND@']
python = ['@PYTHON3@']
ninja = ['@NINJA@']
pkgconfig= ['@PKGCONFIG@']
@MESON_MT@
@MESON_AR@
@MESON_RC@
@MESON_C@
@MESON_C_LD@
@MESON_CXX@
@MESON_CXX_LD@
@MESON_OBJC@
@MESON_OBJC_LD@
@MESON_OBJCPP@
@MESON_OBJCPP_LD@
@MESON_FC@
@MESON_FC_LD@
@MESON_WINDRES@
@MESON_ADDITIONAL_BINARIES@
[properties]
cmake_toolchain_file = '@SCRIPTS@/buildsystems/vcpkg.cmake'
[cmake]
VCPKG_TARGET_TRIPLET = '@TARGET_TRIPLET@'
VCPKG_HOST_TRIPLET = '@_HOST_TRIPLET@'
VCPKG_CHAINLOAD_TOOLCHAIN_FILE = '@VCPKG_CHAINLOAD_TOOLCHAIN_FILE@'
VCPKG_CRT_LINKAGE = '@VCPKG_CRT_LINKAGE@'
_VCPKG_INSTALLED_DIR = '@_VCPKG_INSTALLED_DIR@'
@MESON_HOST_MACHINE@
@MESON_BUILD_MACHINE@
[built-in options]
default_library = '@MESON_DEFAULT_LIBRARY@'
werror = false
@MESON_CFLAGS@
@MESON_CXXFLAGS@
@MESON_FCFLAGS@
@MESON_OBJCFLAGS@
@MESON_OBJCPPFLAGS@
# b_vscrt
@MESON_VSCRT_LINKAGE@
# c_winlibs/cpp_winlibs
@MESON_WINLIBS@
21 changes: 16 additions & 5 deletions scripts/cmake/vcpkg_configure_make.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ macro(z_vcpkg_determine_autotools_target_arch_mac out_var)
endmacro()

macro(z_vcpkg_extract_cpp_flags_and_set_cflags_and_cxxflags flag_suffix)
string(REGEX MATCHALL "( |^)-D[^ ]+" CPPFLAGS_${flag_suffix} "${VCPKG_DETECTED_CMAKE_C_FLAGS_${flag_suffix}}")
string(REGEX MATCHALL "( |^)-D[^ ]+" CXXPPFLAGS_${flag_suffix} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_${flag_suffix}}")
string(REGEX MATCHALL "( |^)(-D|-isysroot|--sysroot=|-isystem|-m?[Aa][Rr][Cc][Hh]|--target=|-target) ?[^ ]+" CPPFLAGS_${flag_suffix} "${VCPKG_DETECTED_CMAKE_C_FLAGS_${flag_suffix}}")
string(REGEX MATCHALL "( |^)(-D|-isysroot|--sysroot=|-isystem|-m?[Aa][Rr][Cc][Hh]|--target=|-target) ?[^ ]+" CXXPPFLAGS_${flag_suffix} "${VCPKG_DETECTED_CMAKE_CXX_FLAGS_${flag_suffix}}")
list(JOIN CXXPPFLAGS_${flag_suffix} "|" CXXREGEX)
if(CXXREGEX)
list(FILTER CPPFLAGS_${flag_suffix} INCLUDE REGEX "(${CXXREGEX})")
Expand Down Expand Up @@ -384,7 +384,7 @@ function(vcpkg_configure_make)
# Currently needed for arm because objdump yields: "unrecognised machine type (0x1c4) in Import Library Format archive"
list(APPEND arg_OPTIONS lt_cv_deplibs_check_method=pass_all)
endif()
elseif(NOT VCPKG_TARGET_IS_OSX)
else()
# Because OSX dosn't like CMAKE_C(XX)_COMPILER (cc) in CC/CXX and rather wants to have gcc/g++
function(z_vcpkg_make_set_env envvar cmakevar)
set(prog "${VCPKG_DETECTED_CMAKE_${cmakevar}} ${ARGN}")
Expand Down Expand Up @@ -432,7 +432,7 @@ function(vcpkg_configure_make)
endif()

# macOS - cross-compiling support
if(VCPKG_TARGET_IS_OSX)
if(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS)
if (requires_autoconfig AND NOT arg_BUILD_TRIPLET OR arg_DETERMINE_BUILD_TRIPLET)
z_vcpkg_determine_autotools_host_arch_mac(BUILD_ARCH) # machine you are building on => --build=
z_vcpkg_determine_autotools_target_arch_mac(TARGET_ARCH)
Expand All @@ -441,7 +441,7 @@ function(vcpkg_configure_make)
# --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
if(NOT "${TARGET_ARCH}" STREQUAL "${BUILD_ARCH}") # we don't need to specify the additional flags if we build natively.
if(NOT "${TARGET_ARCH}" STREQUAL "${BUILD_ARCH}" OR NOT VCPKG_TARGET_IS_OSX) # we don't need to specify the additional flags if we build natively.
set(arg_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: ${arg_BUILD_TRIPLET}")
Expand Down Expand Up @@ -754,10 +754,14 @@ function(vcpkg_configure_make)

# Setup environment
set(ENV{CPPFLAGS} "${CPPFLAGS_${current_buildtype}}")
set(ENV{CPPFLAGS_FOR_BUILD} "${CPPFLAGS_${current_buildtype}}")
set(ENV{CFLAGS} "${CFLAGS_${current_buildtype}}")
set(ENV{CFLAGS_FOR_BUILD} "${CFLAGS_${current_buildtype}}")
set(ENV{CXXFLAGS} "${CXXFLAGS_${current_buildtype}}")
#set(ENV{CXXFLAGS_FOR_BUILD} "${CXXFLAGS_${current_buildtype}}") -> doesn't exist officially
set(ENV{RCFLAGS} "${VCPKG_DETECTED_CMAKE_RC_FLAGS_${current_buildtype}}")
set(ENV{LDFLAGS} "${LDFLAGS_${current_buildtype}}")
set(ENV{LDFLAGS_FOR_BUILD} "${LDFLAGS_${current_buildtype}}")
if(ARFLAGS_${current_buildtype} AND NOT (arg_USE_WRAPPERS AND VCPKG_TARGET_IS_WINDOWS))
# Target windows with wrappers enabled cannot forward ARFLAGS since it breaks the wrapper
set(ENV{ARFLAGS} "${ARFLAGS_${current_buildtype}}")
Expand All @@ -767,6 +771,13 @@ function(vcpkg_configure_make)
# and libtool tries to avoid versioning for shared libraries and no symbolic links are created.
if(VCPKG_TARGET_IS_ANDROID)
set(ENV{LDFLAGS} "-avoid-version $ENV{LDFLAGS}")
set(ENV{LDFLAGS_FOR_BUILD} "-avoid-version $ENV{LDFLAGS_FOR_BUILD}")
endif()

if(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS)
# configure not using all flags to check if compiler works ...
set(ENV{CC} "$ENV{CC} $ENV{CPPFLAGS} $ENV{CFLAGS}")
set(ENV{CC_FOR_BUILD} "$ENV{CC_FOR_BUILD} $ENV{CPPFLAGS} $ENV{CFLAGS}")
endif()

if(LINK_ENV_${current_buildtype})
Expand Down
Loading

0 comments on commit d8e60ef

Please sign in to comment.