Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I setup a cross-compile environment. #13436

Closed
Nemirtingas opened this issue Sep 9, 2020 · 3 comments
Closed

How do I setup a cross-compile environment. #13436

Nemirtingas opened this issue Sep 9, 2020 · 3 comments
Assignees
Labels
category:question This issue is a question

Comments

@Nemirtingas
Copy link
Contributor

Nemirtingas commented Sep 9, 2020

Hi,
I'm trying to setup a cross-compile environment to build macosx and windows apps/libraries on an Ubuntu CI/CD docker image.
I'm using clang-cl as a cross compiler for windows and osxcross for macosx.

I'd like to be able to use vcpkg's ports with my CMake projects.

I've created a custom triplet to do that:

set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_BUILD_TYPE release)

# For clang_windows toolchain
set(ENV{HOST_ARCH} ${VCPKG_TARGET_ARCHITECTURE})

set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE /clang_windows_sdk/clang-cl-msvc.cmake)

But now that I've set the VCPKG_CHAINLOAD_TOOLCHAIN_FILE , the VCPKG_CRT_LINKAGE doesn't seem to be applied to ports.

I think that might be because of
scripts/cmake/vcpkg_configure_cmake.cmake:

    if(NOT VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
        if(NOT DEFINED VCPKG_CMAKE_SYSTEM_NAME OR _TARGETTING_UWP)
            set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/windows.cmake")

We can see in that windows.cmake file that it sets the C runtime link type:

    set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG ${VCPKG_CRT_LINK_FLAG_PREFIX}d /Z7 /Ob0 /Od /RTC1 ${VCPKG_CXX_FLAGS_DEBUG}" CACHE STRING "")
    set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG ${VCPKG_CRT_LINK_FLAG_PREFIX}d /Z7 /Ob0 /Od /RTC1 ${VCPKG_C_FLAGS_DEBUG}" CACHE STRING "")
    set(CMAKE_CXX_FLAGS_RELEASE "${VCPKG_CRT_LINK_FLAG_PREFIX} /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_CXX_FLAGS_RELEASE}" CACHE STRING "")
    set(CMAKE_C_FLAGS_RELEASE "${VCPKG_CRT_LINK_FLAG_PREFIX} /O2 /Oi /Gy /DNDEBUG /Z7 ${VCPKG_C_FLAGS_RELEASE}" CACHE STRING "")

My cmake toolchain works and can build cmake projects for windows, macos and linux, I could use it without vcpkg but then I always have to setup and debug any library I want to add. And its even more complex when cross-compiling for example openssl that is already integrated in vcpkg. Thats why I'd like to make it work.

I've included windows.cmake in my toolchain and now it seems to work fine, I'm still testing things:
include(/vcpkg/scripts/toolchains/windows.cmake)

Is this the right way to use vcpkg to cross-compile ?

@Nemirtingas
Copy link
Contributor Author

Made my own documentation: https://github.com/Nemirtingas/windowscross_vcpkg/blob/msvc2019_win10.0.18362.0/README.md

@PhoebeHui
Copy link
Contributor

@Nemirtingas, sorry for no being able to help, and thanks for sharing the docs here!

@Nemirtingas
Copy link
Contributor Author

@Nemirtingas, sorry for no being able to help, and thanks for sharing the docs here!

Np, I understand this isn't the priority of this project. I also prefer native builds but sometimes, you just can't. Thats why I put my HowTo here. Maybe someone will find it usefull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:question This issue is a question
Projects
None yet
Development

No branches or pull requests

3 participants