[Qt-creator] CMake and include paths

Tamás Kiss tkiss80 at gmail.com
Wed Mar 10 14:15:53 CET 2010


Wow, thank you! I didn't know there was a FIND_PACKAGE module for
libxml2. This makes things much easier. And Creator seems to recognize
the INCLUDE_DIRECTORIES command, so it parses the header files. For
the record, my experimental CMakeLists.txt looks like this:

CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
PROJECT (foobar)

SET (SRCS main.cpp)
ADD_EXECUTABLE (foobar "${SRCS}")

FIND_PACKAGE (LibXml2 REQUIRED)
INCLUDE_DIRECTORIES (SYSTEM "${LIBXML2_INCLUDE_DIR}")
ADD_DEFINITIONS ("${LIBXML2_DEFINITIONS}")
TARGET_LINK_LIBRARIES (foobar "${LIBXML2_LIBRARIES}")

I encountered something strange though: I saved everything and rebuilt
the project, and autocompletion still didn't offer the xmlParseFile()
function (it's in <libxml/parser.h>), although some of the other
symbols showed up from the header file. I tried Tools > C++ > Update
code model, but nothing happened. So I opened the header file in the
editor then closed it, and that solved the problem: the completion
list became complete. (I don't know if it counts, but the declaration
of xmlParseFile() is inside an #ifdef block in the header file).

Qt Creator version: 1.3.0 (from revision 932f460d25).

Again, thanks for the help!

-- 
Tamás

2010/3/10 Peter Kümmel <syntheticpp at gmx.net>:
> Am Mittwoch, den 10.03.2010, 03:27 +0100 schrieb Tamás Kiss:
>> Hi!
>>
>> I tried to create a CMake project to experiment with libxml2 on Linux,
>> and I ran into the following problem:
>>
>> The libxml2 header files are in the /usr/include/libxml2/ directory
>> which is not among the default system include paths, so I had to feed
>> the CMAKE_CXX_FLAGS variable with the output of the "xml2-config
>> --cflags" command (this generates "-I/usr/include/libxml2"). The
>> problem is that the IDE is unaware of this new include path, so it
>> doesn't find the libxml2 header files. Because of this, the editor
>> underlines everything as undeclared identifier, code completion
>> doesn't work, so it's actually much harder to work in Creator than in
>> a plain text editor. (Compilation works fine).
>>
>> My question: is there a way to tell the IDE where to look for the
>> header files? Or in CMake projects this is not implemented yet?
>>
>> Thanks,
>
> Add 'include_directories(usr/include/libxml2)' to you CMakeLists.txt.
>
> When you use the 'find_package' command to find libxml2 then there is
> a variable which points to the headers.
>
> Peter
>
>
>
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-creator
>




More information about the Qt-creator-old mailing list