conan-io / conan

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

Conan on Mac can't recognize compiler correctly #2231

Closed zamazan4ik closed 6 years ago

zamazan4ik commented 6 years ago

Hello, https://travis-ci.org/procxx/kepka/jobs/322618396

on the link you can see that Conan recognize compiler as gcc 4.2 on Travis, but it's not true.

memsharded commented 6 years ago

I think it might be because conan detects the compiler version executing: gcc --version, and in your case it might be that only g++ is configured as the default one. Can you output in your script the output of gcc --version, or better, configure gcc 8.1 as the default gcc too?

berkus commented 6 years ago

@memsharded on osx, gcc and g++ are system aliases for clang.

memsharded commented 6 years ago

To further clarify why not g++ is used in the detection, the rationale is that there are many projects that contain a mixture of C and C++, so both compilers are used. Sometimes in different libraries, but sometimes also in the same library or package. As it seems quite important to maintain consistency, there is single settings.compiler=gcc setting (not g++), and a single settings.compiler.version value in the default settings.

berkus commented 6 years ago

I tried passing -s compiler.version=7.2 to force detection override, subsequently cmake fails because conan generates invalid compiler identification:

-- Current conanbuildinfo.cmake directory: /Users/travis/build/procxx/kepka/_build_
CMake Error at _build_/conanbuildinfo.cmake:474 (message):
  Incorrect 'gcc', is not the one detected by CMake: 'AppleClang'
Call Stack (most recent call first):
  _build_/conanbuildinfo.cmake:173 (conan_check_compiler)
  CMakeLists.txt:30 (conan_basic_setup)
memsharded commented 6 years ago

Ok, I think I get the issue. This code is in detect.py:

cc = os.environ.get("CC", "")
cxx = os.environ.get("CXX", "")
if cc or cxx:  # Env defined, use them
        output.info("CC and CXX: %s, %s " % (cc or "None", cxx or "None"))
        command = cc or cxx
        if "clang" in command.lower():
              return _clang_compiler(output, command)

Setting the CXX env var to "clang++" instead of "g++" might workaround the issue, while better detection is developed.

memsharded commented 6 years ago

If you are overriding in command line, you have also to override the compiler, that is not gcc:

$ conan install . -s compiler=apple-clang -s compiler.version=7.3 -s ...

Beware 7.2 is not a default compiler.version for apple-clang. You can check the default settings values in settings.yml file.

berkus commented 6 years ago

So I reckon there's no portable way to set this up... ok, i will use different per-platform invocations then.

memsharded commented 6 years ago

I am defining this as an improvement, lets aim to do this for 1.1, but also low priority, if 1.1 is packed, it might be delayed. Thanks very much for the feedback!

pvicente commented 6 years ago

Hi @ZaMaZaN4iK ,

We've been investigating the issue and it was happening in conan 0.30.3 see https://travis-ci.org/procxx/kepka/jobs/322618395#L1364. I've tried to reproduce the issue with latest conan version 1.0.4 https://travis-ci.org/pvicente/kepka/jobs/342041385#L1959 but the behaviour detecting the compiler is ok.

Now it looks like you have another problem but not related with conan,

-- Performing Test WNCE_FLAG_SUPPORTED - Success
-- Found framework /System/Library/Frameworks/Cocoa.framework
-- Found framework /System/Library/Frameworks/CoreFoundation.framework
-- Found framework /System/Library/Frameworks/CoreServices.framework
-- Found framework /System/Library/Frameworks/ApplicationServices.framework
-- Found framework /System/Library/Frameworks/CoreText.framework
-- Found framework /System/Library/Frameworks/CoreGraphics.framework
-- Found framework /System/Library/Frameworks/Foundation.framework
-- Found framework /System/Library/Frameworks/OpenGL.framework
-- Found framework /System/Library/Frameworks/QuartzCore.framework
-- Found framework /System/Library/Frameworks/AGL.framework
-- Found framework /System/Library/Frameworks/Security.framework
-- Found framework /System/Library/Frameworks/SystemConfiguration.framework
-- Found framework /System/Library/Frameworks/Carbon.framework
-- Found framework /System/Library/Frameworks/CoreAudio.framework
-- Found framework /System/Library/Frameworks/AudioToolbox.framework
-- Found framework /System/Library/Frameworks/AudioUnit.framework
-- Found framework /System/Library/Frameworks/AppKit.framework
-- Found framework /System/Library/Frameworks/CoreWLAN.framework
-- Found framework /System/Library/Frameworks/IOKit.framework
-- C CXX target Telegram cotired without unity build excluding 18 files.
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/travis/build/pvicente/kepka/_build_
+cmake --build . -- -v
ninja: error: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AudioToolbox.framework', needed by 'bin/Telegram.app/Contents/MacOS/Telegram', missing and no known rule to make it
+exit 1

If you don't mind I'm going to close the issue but feel free to reopen it if you can see any problem with conan.

Cheers, Pedro

pvicente commented 6 years ago

Sorry @ZaMaZaN4iK ,

I've reproduced the same error with the latest version of conan 1.0.4.

https://travis-ci.org/pvicente/kepka/jobs/342447099

Working on a proper fix to make it more "portable".

memsharded commented 6 years ago

I have been asking and investigating:

@berkus

on osx, gcc and g++ are system aliases for clang.

That is not totally accurate. The OSX gcc/g++ are actually gnu gcc frontends using the apple-clang llvm backend. https://stackoverflow.com/questions/19535422/os-x-10-9-gcc-links-to-clang

There is some ongoing work in https://github.com/conan-io/conan/pull/2487.

But I think the logic should probably be: Skip the gcc (as clang frontend) in OSX in the default conan detection of compiler. So in OSX, conan will be able to detect normal "apple-clang" clang compiler, and maybe "gcc", but as complete gcc, not that clang frontend.

berkus commented 6 years ago

JFYI: The "GCC" that came with 10.8 was really GCC front-end with LLVM back-end.

Starting from 10.9, gcc is just an alias running clang, gcc has been dropped completely by Apple.