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

[boost-modular-build-helper] B2 ignores C/CXX/LDFLAGS when toolchain is not MSVC or GCC #11132

Closed
psfrolov opened this issue May 2, 2020 · 3 comments
Assignees
Labels
category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist

Comments

@psfrolov
Copy link
Contributor

psfrolov commented May 2, 2020

Problem

In user-config.jam we have:

if "@VCPKG_PLATFORM_TOOLSET@" != "external"
{
    using msvc : : cl.exe
        :
        <setup>"@NOTHING_BAT@"
        @TOOLSET_OPTIONS@
        ;
}
else
{
    using gcc : 5.4.1 : @CMAKE_CXX_COMPILER@
        :
        <ranlib>@CMAKE_RANLIB@
        <archiver>@CMAKE_AR@
        @CXXFLAGS@
        @CFLAGS@
        @LDFLAGS@
        # MINGW here causes b2 to not run cygpath
        <flavor>mingw
        ;
}

That said if toolset is not msvc we are going else route with toolset set to gcc 54.1. This mostly works but have subtle side effects if compiler we are building with is not in fact GCC. For example, if we are building with Clang then using gcc makes B2 to ignore all the options in using block because clang is not gcc. Thus no compiler/linker options from Vcpkg code and user triplets are passed to build.

Proposed solution

  1. Make toolset and version in user-config.jam configurable:
using @VCPKG_B2_COMPILER_ID@ : @CMAKE_CXX_COMPILER_VERSION@ : @CMAKE_CXX_COMPILER@
  1. In CMakeLists.txt map CMake toolchain ID to B2 toolchain ID:
# Determine compiler ID to use in user-config.jam
# CMake compiler IDs: https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
# B2 compiler IDs: https://boostorg.github.io/build/manual/master/index.html#bbv2.reference.tools.compilers
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    set(VCPKG_B2_COMPILER_ID gcc)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")  # AppleClang, Clang, XLClang
    set(VCPKG_B2_COMPILER_ID clang)
elseif(...)
    ...
else()
    # Either hard fail or fallback to GCC and issue a warning.
    # Hard fail is better because alternative is undefined behaviour.
endif()

I consider also adding -d 2 to b2 invocation to capture compiler and linker command lines in B2 logs so such kind of issues can be debugged more easly.

@psfrolov psfrolov added the category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist label May 2, 2020
@vejmartin
Copy link
Contributor

Possibly fixed by #18529.

@yurybura
Copy link
Contributor

@PhoebeHui This issue has been fixed already. Could you close it?

@PhoebeHui
Copy link
Contributor

@yurybura, thank you for confirming this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist
Projects
None yet
Development

No branches or pull requests

4 participants