conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
7.97k stars 952 forks source link

[enhancement] QNX support for targets and standard library settings #5463

Open Johnnyxy opened 4 years ago

Johnnyxy commented 4 years ago

hi there, as Conan now starts to support QNX Neutrino, I would like to specify a more correct behaviour of Conan regarding compiler flags, etc.

architecture selection

As of now Conan does not seem to support selecting the correct architecture for QNX targets. The QCC command line needs the correct QNX named target to load the correct configuration for the later GCC invocation. This means one has to provide the parameter -V. I did not find any traces of such thing (by searching the repo for "-V" or "aarch64").

What Conan has to do is a mapping between Conan's arch setting and the correct QNX target:

Conan (arch) QNX (arch) QCC target (-V) Comment (confirmed)
armv7 armv7le gcc_ntoarmv7le QNX SDP 7.0 or later
armv8 aarch64le gcc_ntoaarch64le QNX SDP 7.0 or later
x86_64 x86_64 gcc_ntox86_64 QNX SDP 7.0 or later
x86 x86 gcc_ntox86 QNX SDP 6.5 or later
arm armle gcc_ntoarmle QNX SDP 6.5 - using ARMv4 instructions
sh4le shle gcc_ntoshle QNX SDP 6.5

The table shows only mappings to little endian targets (like armv7le). As the default QNX SDP (version 6.5 or later) does not provide support via the standard installation for any other targets which differentiate between endianess and little endian is a kinda standard for nix/BSD systems this could be the default for now. Anyway one could always introduce additional archs in the settings.yml.

runtime library

In the Conan code Conan sets compiler flags according to the libcxx setting. All compilers before QNX 7 (QNX 6.6 and lower) support selecting the library only by their setting -Y gpp or by directly choosing the exact target e.g. -Vgcc_ntox86_gpp (those can be a combination -> -Vgcc_ntox86 -Y_gpp). QNX SDP 6.5 compiler -> docs QNX SDP 6.6 compiler -> docs QNX SDP 7.0 compiler -> docs

The current implementation would be fine until (including) QNX SDP 6.6. https://github.com/conan-io/conan/blob/64adf71cc691ef9c53aaf1331b8a9db0a89abe84/conans/client/build/compiler_flags.py#L77

Now since QNX SDP 7 (QCC 5.4) the QCC learned the parameter stdlib analog to the common GCC parameter. This would mean Conan could use the normal GCC settings for QCC 5.4 or higher. The following code is adapted from code I would write in a recipe. As this is a Conan internal function (see code link above) this should be considered as pseudo-code.

-stdlib= -Y Library
libc++ _cxx LLVM C++
libstdc++ _gpp GNU C++
    elif str(compiler) == "qcc":
        if (tools.Version(str(compiler.version)) < "5.4"):
            return "-Y _%s" % str(libcxx)
        else:
            # libc++ = _cxx = LLVM C++
            # libstdc++ = _gpp = GNU C++
            return "-stdlib=%s" % str(libcxx)

Tthe settings.yml has to be extended to support the more common setting in the future for libc++ and libstdc++.

standard C/C++ dialect

QNX SDP 7.0 (QCC 5.4) learned another common setting from GCC (docs): std=language This means Conan can introduce the common setting cppstd in the settings.yml and provide that to the normal build-flow.

standard GCC comment
c++98 gnu++98 >= 3.3.6 supported at least since QNX SDP 6.4 with QCC/GCC 4.2.4
c++11 gnu++11 >= 5.1.0 supported since QNX SDP 7.0 with QCC/GCC 5.4
c++14 gnu++14 >= 5.1.0 supported since QNX SDP 7.0 with QCC/GCC 5.4

For GCC -std=language parameter Conan has a function here: https://github.com/conan-io/conan/blob/a050ed94034b27ae3d394b5abaeb815fac20f1b8/conans/client/build/cppstd_flags.py#L164

This means that Conan could introduce another function for QCC like _cppstd_qcc (what I think should be preferred and just call the GCC function then) or directly use the GCC function variant.

def _cppstd_qcc(qcc_version, cppstd):
    return _cppstd_gcc(qcc_version, cppstd)

Additionally the following line has to be added to the settings.yml to the compiler.qcc-section:

        cppstd: [None, 98, gnu98, 11, gnu11, 14, gnu14]
SSE4 commented 4 years ago

@Johnnyxy seems like you know all changes that are needed to be done. may be you can go ahead and create PR then?

Johnnyxy commented 4 years ago

Will do. At the moment I have to solve some other problems but I will head back for a PR.

derived-coder commented 4 years ago

Hi, is there any update here? I don't see the target architecture selection works...or am I doing something wrong? There is no -V provided.

@Johnnyxy How do you get everything running without changing the internal conan code?

Johnnyxy commented 4 years ago

Building for QNX with Conan does not necessarily need any changes to the Conan code base. Updating the code base would be nothing else than an enhancement.

As you already asked at the bincrafters' issue tracker, I will point you over there. The attached files and instructions in here (https://github.com/bincrafters/community/issues/1041#issuecomment-569460055) is everything one needs to build for QNX 7.0 with conan.

This issue here is still open and from my point of view pending as it is still a task on my worklist but with a low priority.