Using qmake and LibTooling

Hi,

trying to setup my dev env under Windows, one of my goals is to use Qt as a Frontend for my tools.
And QtCreator as an IDE for the whole thing. I could get cmake to build with the mingw supplied by Qt, also I could build the cbp Version with cmake, so I can open LLVM in CodeBlocks or QtCreator. Its even compiling.

So actually, I'm ready to start, my first goal is to this running with qmake. Just to have a start to work from. So, I've searched the list and the net, and have not found anything on this. So, I thought, its maybe a good Idea to ask on the list. Has someone else got this running with QMake under Windows with QtCreator?

So actually, I'm ready to start, my first goal is to build the PrintFunctionName Example with qmake. But it seems not to be enough to hand the include directories and the libraries to qmake to make it compile. Some minor issues I could resolve, but I'm stuck on this:

DataTypes.h:
/* Handle incorrect definition of uint64_t as u_int64_t */
#ifndef HAVE_UINT64_T
#ifdef HAVE_U_INT64_T
typedef u_int64_t uint64_t;
#else
# error "Don't have a definition for uint64_t on this platform"//
#endif
#endif

This fails always, I have a stdint.h which defines uint64_t, but in this case, the header fails to detect this. Tried already to define HAVE_UINT_64_T etc.
Now, note, that I can build for exact compiler with cmake and qmake should not be so different. My current qmake file:

#DEFINES += HAVE_STDINT_H

#INCLUDEPATH += C:/qt/2010.03/mingw/include // doesnt need it, just a try
INCLUDEPATH += C:/cpp/boost_1_49_0 //for boost/cstdint.hpp
INCLUDEPATH += C:/cpp/llvm/tools/clang/include
INCLUDEPATH += C:/cpp/llvm/include

// linker yet not invoked, may some missing here, but I know which...
LIBS += C:/cpp/llvm/mybuild/lib/libclangTooling.a

// when using not boost/cstdint need to define them here
DEFINES += __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS __STDC_LIMIT_MACROS _GNU_SOURCE

Has someone expierence with getting this setup to run?
How is CMake setting the environment up? I've read through the generated makefiles, but could not find any difference which explains this.
The other 535 Errors I think are probably also from some config/setup problems.

kind regards,

Jens Weller

I'm pretty sure this is a QtC related question - Someone here may know, but if you don't get a response try there.

-------- Original-Nachricht --------

Datum: Tue, 14 Aug 2012 21:39:45 +0700
Von: "C. Bergström" <cbergstrom@pathscale.com>
An: Jens Weller <JensWeller@gmx.de>
CC: cfe-dev@cs.uiuc.edu
Betreff: Re: [cfe-dev] Using qmake and LibTooling

I'm pretty sure this is a QtC related question - Someone here may know,
but if you don't get a response try there.

Who should know better about this then the people on this list?
QtC just uses qmake, I will also ask in Qt Community too, but I think this is rather cmake/clang related.

kind regards,

Jens Weller

If all you need is to use Qt in your clang-based tools, I think you should stick to CMake. It both supports Qt out of the box and is supported as a build system for Clang tools. You can use it within Qt Creator as well.

If you want to use LibTooling with qmake-based builds, you need to implement CompilationDatabase support for qmake which is not trivial.

Datum: Tue, 14 Aug 2012 19:44:36 +0400
Von: Konstantin Tokarev <annulen@yandex.ru>
An: Jens Weller <jensweller@gmx.de>
CC: "cfe-dev@cs.uiuc.edu" <cfe-dev@cs.uiuc.edu>
Betreff: Re: [cfe-dev] Using qmake and LibTooling

If all you need is to use Qt in your clang-based tools, I think you should
stick to CMake. It both supports Qt out of the box and is supported as a
build system for Clang tools. You can use it within Qt Creator as well.

If you want to use LibTooling with qmake-based builds, you need to
implement CompilationDatabase support for qmake which is not trivial.

I usually stick to the QtSDK, and I'm right now not so familiar with cmake.
Also both uses the same compiler, shouldn't be to hard to get this setup running.
I have build the libs with the right mingw version, should be able to use them with qmake.

CompilationDatabase? Isn't this a type with in the library?
Why should that have any influence on the make system?

regards,

Jens Weller

Update on this one.

Current qmake file:
DEFINES += __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS __STDC_LIMIT_MACROS _GNU_SOURCE

INCLUDEPATH += C:/cpp/boost_1_49_0
INCLUDEPATH += C:/cpp/llvm/tools/clang/include
INCLUDEPATH += C:/cpp/llvm/include
INCLUDEPATH += C:/cpp/llvm/mybuild/tools/clang/include
INCLUDEPATH += C:/cpp/llvm/mybuild/include

LIBS += C:/cpp/llvm/mybuild/lib/libclangTooling.a

This resolves ALL other Errors, so why is the llvm/Support/DataTypes Header not finding uint64_t in this special case?

//line 73 ff
/* Handle incorrect definition of uint64_t as u_int64_t */
#ifndef HAVE_UINT64_T
#ifdef HAVE_U_INT64_T
typedef u_int64_t uint64_t;
#else
# error "Don't have a definition for uint64_t on this platform"
#endif
#endif

kind regards,

Jens Weller

šDatum: Tue, 14 Aug 2012 19:44:36 +0400
šVon: Konstantin Tokarev <annulen@yandex.ru>
šAn: Jens Weller <jensweller@gmx.de>
šCC: "cfe-dev@cs.uiuc.edu" <cfe-dev@cs.uiuc.edu>
šBetreff: Re: [cfe-dev] Using qmake and LibTooling

šIf all you need is to use Qt in your clang-based tools, I think you should
šstick to CMake. It both supports Qt out of the box and is supported as a
šbuild system for Clang tools. You can use it within Qt Creator as well.

šIf you want to use LibTooling with qmake-based builds, you need to
šimplement CompilationDatabase support for qmake which is not trivial.

I usually stick to the QtSDK, and I'm right now not so familiar with cmake.

And I guess folks here are not familiar with qmake.

If you are willing to get qmake working for you, rebuild PrintFunctionNames with cmake
and check which compiler options were used (you may need to use make VERBOSE=1),
then reproduce them in qmake project.

Also both uses the same compiler, shouldn't be to hard to get this setup running.
I have build the libs with the right mingw version, should be able to use them with qmake.

I don't doubt about it :slight_smile:

CompilationDatabase? Isn't this a type with in the library?
Why should that have any influence on the make system?

Well, if your tool will run on 1 source file per invocation, it doesn't influence indeed...

Hi,

SOLVED! Still some linker issues left, but I know that I have to link to a few more libraries.

Actually, llvm/Support/DataTypes.h is the WRONG one.

New qmake file:
SOURCES += main.cpp

DEFINES += __STDC_LIMIT_MACROS __STDC_CONSTANT_MACROS __STDC_LIMIT_MACROS _GNU_SOURCE

INCLUDEPATH += C:/cpp/boost_1_49_0
INCLUDEPATH += C:/cpp/llvm/mybuild/include
INCLUDEPATH += C:/cpp/llvm/tools/clang/include
INCLUDEPATH += C:/cpp/llvm/include
INCLUDEPATH += C:/cpp/llvm/mybuild/tools/clang/include

LIBS += C:/cpp/llvm/mybuild/lib/libclangTooling.a

Note, that the llvm include from the cmake build comes first, this replaces the DataTypes.h of the regular one. Then, this setup should acutally work, Qt is linked under the same mingw compiler.
mybuild contains a cmake build of llvm with "cmake -G "MinGW Makefiles" C:\cpp\llvm"

Now, I have to think which tool to build first :wink:

kind regards,

Jens Weller

Datum: Tue, 14 Aug 2012 19:44:36 +0400
Von: Konstantin Tokarev <annulen@yandex.ru>
An: Jens Weller <jensweller@gmx.de>
CC: "cfe-dev@cs.uiuc.edu" <cfe-dev@cs.uiuc.edu>
Betreff: Re: [cfe-dev] Using qmake and LibTooling

If all you need is to use Qt in your clang-based tools, I think you should
stick to CMake. It both supports Qt out of the box and is supported as a
build system for Clang tools. You can use it within Qt Creator as well.

If you want to use LibTooling with qmake-based builds, you need to
implement CompilationDatabase support for qmake which is not trivial.

I usually stick to the QtSDK, and I'm right now not so familiar with cmake.
Also both uses the same compiler, shouldn't be to hard to get this setup running.
I have build the libs with the right mingw version, should be able to use them with qmake.

CompilationDatabase? Isn't this a type with in the library?
Why should that have any influence on the make system?

CompilationDatabase is how clang tools figure out how to run clang on
a source file.
In general you have 2 options to get this running with a new build system:
1. make the build system output a compilation_database.json file as
part of its configuration step - for meta build systems, this is the
preferred way (that's what we did to CMake); see
http://clang.llvm.org/docs/JSONCompilationDatabase.html
2. write your own CompilationDatabase implementation that can detect
the build files for your project, parse them, and provide the compile
command lines

Cheers,
/Manuel

Yes, but still I don't wanna use clang with qmake, or be able to build clang with qmake.
I can build clang with cmake, and thats fine in that way.
All I need is to make use of the libraries provided by clang such as LibTooling, to build Tools that use Qt as a Frontend. And this works now.

kind regards,

Jens Weller

-------- Original-Nachricht --------

Yes, but still I don't wanna use clang with qmake, or be able to build clang with qmake.
I can build clang with cmake, and thats fine in that way.
All I need is to make use of the libraries provided by clang such as LibTooling, to build Tools that use Qt as a Frontend. And this works now.

The question is: do you want to *run* those tools over code that uses qmake?

Cheers,
/Manuel

-------- Original-Nachricht --------

Datum: Tue, 14 Aug 2012 23:06:38 +0200
> Yes, but still I don't wanna use clang with qmake, or be able to build
clang with qmake.
> I can build clang with cmake, and thats fine in that way.
> All I need is to make use of the libraries provided by clang such as
LibTooling, to build Tools that use Qt as a Frontend. And this works now.

The question is: do you want to *run* those tools over code that uses
qmake?

Thats not my question at the moment. Right now I'm just interested to get an overview on what is possible with the APIs. Long term, yeah, would be kind a cool to be able to use clang tooling with Qt and QMake.
But I'm not an qmake-expert, so I'm the wrong guy to talk to about that.

kind regards,

Jens Weller

-------- Original-Nachricht --------

Datum: Tue, 14 Aug 2012 23:06:38 +0200
> Yes, but still I don't wanna use clang with qmake, or be able to build
clang with qmake.
> I can build clang with cmake, and thats fine in that way.
> All I need is to make use of the libraries provided by clang such as
LibTooling, to build Tools that use Qt as a Frontend. And this works now.

The question is: do you want to *run* those tools over code that uses
qmake?

Thats not my question at the moment. Right now I'm just interested to get an overview on what is possible with the APIs. Long term, yeah, would be kind a cool to be able to use clang tooling with Qt and QMake.
But I'm not an qmake-expert, so I'm the wrong guy to talk to about that.

That's where the confusion came from then. Now everything makes sense :0)

Happy hacking!