Coder Social home page Coder Social logo

OSX qmake support about ycm-generator HOT 9 CLOSED

rdnetto avatar rdnetto commented on July 29, 2024
OSX qmake support

from ycm-generator.

Comments (9)

rdnetto avatar rdnetto commented on July 29, 2024

Have you tried running it with -v?

from ycm-generator.

IngoMeyer441 avatar IngoMeyer441 commented on July 29, 2024

I've tried the following command in a very simple demo project (with macx-clang):

config_gen.py -F ycm -v --qt-version 5 .

and get the following output:

Running qmake in '/var/folders/2y/5g7w8vc53mn0xfymbbxg3pxm000lj5/T/tmpuopyft' with Qt 5...
$ qmake /Users/heimbach/tmp/qt5/src/src.pro
Info: creating stash file /private/var/folders/2y/5g7w8vc53mn0xfymbbxg3pxm000lj5/T/tmpuopyft/.qmake.stash

Running make...
$ make -i -j8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wall -W -fPIC -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/heimbach/tmp/qt5/src -I. -I/Users/heimbach/tmp/qt5/src -I/usr/local/qt-5.5/lib/QtWidgets.framework/Headers -I/usr/local/qt-5.5/lib/QtGui.framework/Headers -I/usr/local/qt-5.5/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/qt-5.5/mkspecs/macx-clang -F/usr/local/qt-5.5/lib -o main.o /Users/heimbach/tmp/qt5/src/main.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wl,-rpath,/usr/local/qt-5.5/lib -o src.app/Contents/MacOS/src main.o   -F/usr/local/qt-5.5/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL

Cleaning up...

Build completed in 2.77 sec

Collected 0 relevant entries for C compilation (0 discarded).
Collected 0 relevant entries for C++ compilation (0 discarded).
()
ERROR: No commands were logged to the build logs (C: /var/folders/2y/5g7w8vc53mn0xfymbbxg3pxm000lj5/T/tmpszxdwD, C++: /var/folders/2y/5g7w8vc53mn0xfymbbxg3pxm000lj5/T/tmp4eQNDK).
Your build system may not be compatible.

So, there are enough arguments that could be collected.

from ycm-generator.

rdnetto avatar rdnetto commented on July 29, 2024
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

This indicates that instead of invoking YCM-Gen's toolchain, your build system is invoking the system toolchain. I'm not hugely familiar with qmake, but this typically happens because the build file isn't respecting the CXX variable and has hardcoded the compiler. You should take a look at your .pro file to see if this is the case.

I've also pushed a change to fix OSX Qmake support - please checkout develop and confirm that it works.

from ycm-generator.

IngoMeyer441 avatar IngoMeyer441 commented on July 29, 2024

My .pro file was auto generated with qmake -project and has only the following contents:

TEMPLATE = app
TARGET = src
INCLUDEPATH += .

QT += core
QT += widgets

# Input
SOURCES += main.cpp

Till now, I was not able to figure out why the wrong toolchain is used.
Your commit looks fine (I will test it as soon as my CXX configuration works). On Mac OSX there is an additional -F switch for framework search paths that should be collected like -I. So I think line 333 (on develop)

flags_whitelist = ["-[iID].*", "-W[^,]*", "-std=[a-z0-9+]+", "-(no)?std(lib|inc)", "-m[0-9]+"]

should be altered to

flags_whitelist = ["-[iIDF].*", "-W[^,]*", "-std=[a-z0-9+]+", "-(no)?std(lib|inc)", "-m[0-9]+"]

Is that the only location where new flags must be added?

from ycm-generator.

IngoMeyer441 avatar IngoMeyer441 commented on July 29, 2024

Qmake behavior on OSX is a bit strange. Whatever I set as CXX variable in the qmake project has no effect on the generated Makefile. I always get the following line in the generated output:

CXX           = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

Therefore, I wrote a litte helper function that patches the generated Makefile after the qmake run:

    def patch_qmake_makefile_osx(makefile_path):
        compilers = {
            'CC': 'clang',
            'CXX': 'clang++'
        }
        patched_makefile_lines = []
        with open(makefile_path, 'r') as f:
            for line in f:
                line = line.rstrip()
                for variable_name, compiler in compilers.items():
                    if re.match('\s*{}\s*='.format(variable_name), line):
                        line = re.sub('=.*', '= {}'.format(compiler), line)
                        break
                patched_makefile_lines.append(line)
        with open(makefile_path, 'w') as f:
            f.write('\n'.join(patched_makefile_lines))

It's a bit hacky but the collection of flags does work now. However now I get another error:

 Running qmake in '/var/folders/2y/5g7w8vc53mn0xfymbbxg3pxm000lj5/T/tmpBBZ2fG' with Qt 5...
$ qmake /Users/heimbach/tmp/qt5/src/src.pro
Info: creating stash file /private/var/folders/2y/5g7w8vc53mn0xfymbbxg3pxm000lj5/T/tmpBBZ2fG/.qmake.stash

Running make...
$ make -i -j8
clang++ -c -pipe -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wall -W -fPIC -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/heimbach/tmp/qt5/src -I. -I/Users/heimbach/tmp/qt5/src -I/usr/local/qt-5.5/lib/QtWidgets.framework/Headers -I/usr/local/qt-5.5/lib/QtGui.framework/Headers -I/usr/local/qt-5.5/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/AGL.framework/Headers -I/usr/local/qt-5.5/mkspecs/macx-clang -F/usr/local/qt-5.5/lib -o main.o /Users/heimbach/tmp/qt5/src/main.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wl,-rpath,/usr/local/qt-5.5/lib -o src.app/Contents/MacOS/src main.o   -F/usr/local/qt-5.5/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL
clang: error: no such file or directory: 'main.o'
make: [src.app/Contents/MacOS/src] Error 1 (ignored)

Cleaning up...

Build completed in 1.14 sec

Collected 0 relevant entries for C compilation (0 discarded).
Collected 1 relevant entries for C++ compilation (0 discarded).
Created YCM config file with 15 C++ flags

Usually, YCM-Generator does not try to do a linking step, does it?

from ycm-generator.

rdnetto avatar rdnetto commented on July 29, 2024

YCM-Generator skips the linking step by specifying its own linker (which is just a symlink to the equivalent of /bin/true). This is normally done by appending fake-toolchain/Unix to PATH, so that it takes precedence over the installed compiler/linker.

Take a look at /usr/lib64/qt5/mkspecs/macx-clang/qmake.conf (and the included files) - they might give some hints as to which variables to override. QMAKE_CXX and QMAKE_LINK seem particularly promising, but I'd like to make sure that there aren't any downstream changes to them that might hardcode the compiler.

The reason it's failing is that you haven't replaced all the instances of clang++ - the line immediately before the error is calling the system compiler.

from ycm-generator.

IngoMeyer441 avatar IngoMeyer441 commented on July 29, 2024

Setting QMAKE_CXX and QMAKE_LINK to clang++ directly has no effect unfortunately. The compiler and linker path is always expanded to an absolute path to the executables of the Xcode installation. I browsed through the mkspecs files but could not find any clue yet where the expansion occurs.

from ycm-generator.

rdnetto avatar rdnetto commented on July 29, 2024

Hmmm, in that case the simplest solution might be to just modify the generated makefile before invoking it.

from ycm-generator.

zhongke avatar zhongke commented on July 29, 2024

Is there any update about this issue? I have the same issue in my Qt environment. I am eager to know your solution. Thanks.
Brs/Kevin

from ycm-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.