Results 1 to 2 of 2

Thread: conditional includes in pro file

  1. #1
    Join Date
    Oct 2011
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default conditional includes in pro file

    Hi,

    My application has been written in such a manner that a stripped back 'lite' version can be compiled simply by not including the extra .h and .cpp files.
    As far as I understand it this can be achieved in the .pro file like so:
    Qt Code:
    1. CONFIG += full_version
    2.  
    3. SOURCES += core.cpp
    4. HEADERS += core.h
    5.  
    6. full_version {
    7. SOURCES += extra.cpp
    8. HEADERS += extra.h
    9. .....
    10. }
    To copy to clipboard, switch view to plain text mode 
    The first time I compiled and ran this I got the full application in the exe. However if I make a change to the pro file, say, comment out the Config line, effectively asking for a 'lite' version I still get the full application. I thought possibly something was getting cached somewhere so I deleted the makefile, makefile.debug, makefile.release and everything in the debug and release folders, cleaned the project, ran qmake and built the project again. But I still got the full application. I repeated this a couple of times and on the last time I got my lite version. So I uncommented the config line again and now cannot get the full version back!

    I believe the code is right in the .pro file but am I missing something when making changes to it?
    Thanks, C.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: conditional includes in pro file

    Here is a simple way to have conditional .pro file options:
    Qt Code:
    1. // *.pro
    2. contains(opt,x) {
    3. SOURCES += x_file.cpp
    4. ....
    5. } else {
    6. SOURCES += no_x_file.cpp
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 
    When building your project, you can simply activate the "x" option by using qmake parameter:
    Qt Code:
    1. // this will cause x_file.cpp to be compiled
    2. qmake opt=x
    3.  
    4. // this will skip x_file.cpp and add no_x_file.cpp
    5. qmake
    6. // or
    7. qmake opt=<anything but x>
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 27th July 2011, 17:59
  2. How Does One Put a Conditional For Embedded Linux into a .pro file?
    By cloaked_and_coastin in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 27th July 2010, 16:48
  3. Replies: 2
    Last Post: 1st March 2010, 18:58
  4. Conditional linkage
    By TorAn in forum General Programming
    Replies: 1
    Last Post: 22nd December 2009, 22:10
  5. Replies: 3
    Last Post: 8th July 2008, 20:37

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.