Results 1 to 7 of 7

Thread: configuring optional dependencies in qmake or cmake

  1. #1
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default configuring optional dependencies in qmake or cmake

    Hi,
    I have a program that I'm working on which has an optional dependency. In my code I have the appropriate #ifdef ENABLE_DEPENENCY ... #endif block, which works fine.

    However, I want to make a source package that I can distribute which will allow the user to do the equivalent of the normal "configure; make; make install" in which the presence or absence of the optional dependency is detected and #define is called (or not!) appropriately.

    I'm just not sure how to best do this in qmake. Can anyone point me to some documentation. Is it better to use cmake?

    Thanks, B.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: configuring optional dependencies in qmake or cmake

    Do you want to detect the dependency automatically?
    On which systems?

    Or do you want to have a parameter like "configure --with-my-dependency"?

  3. #3
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: configuring optional dependencies in qmake or cmake

    Quote Originally Posted by tbscope View Post
    Do you want to detect the dependency automatically?
    If possible, I'd like it to be detected automatically.

    On which systems?
    I work on Linux but if it is portable, that would be good too.

    Or do you want to have a parameter like "configure --with-my-dependency"?
    I would like to have the dependency inlcuded if it is found but offer a "--without-dependency" option.

    Thanks for the help, tbscope!

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: configuring optional dependencies in qmake or cmake

    For a simple on/off switch you can just use qmake and a scope:
    Qt Code:
    1. has_foo {
    2. message("Has foo")
    3. DEFINES += ENABLE_FOO
    4. INCLUDEPATH += ...
    5. LIBS += ...
    6. }
    7.  
    8.  
    9. TEMPLATE = app
    10. TARGET =
    11. DEPENDPATH += .
    12. INCLUDEPATH += .
    13.  
    14. # Input
    15. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 
    and then either
    Qt Code:
    1. $ qmake CONFIG+=has_foo
    2. OR
    3. $ qmake
    To copy to clipboard, switch view to plain text mode 

    On Linux platform you can often use pkg-config to test the availability of a given library and obtain the correct include and/or lib paths.
    Qt Code:
    1. $ pkg-config --exists QtGui && echo "QtGui exists"
    2. QtGui exists
    3. $ pkg-config --cflags QtGui
    4. -DQT_SHARED -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore
    5. $ pkg-config --libs QtGui
    6. -L/usr/lib/qt4 -lQtGui -lQtCore
    To copy to clipboard, switch view to plain text mode 

    You can combine that into the qmake pro file:
    Qt Code:
    1. system(pkg-config --exists foo) {
    2. message("Has foo")
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 2nd December 2010 at 06:28.

  5. The following user says thank you to ChrisW67 for this useful post:

    brixton (2nd December 2010)

  6. #5
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: configuring optional dependencies in qmake or cmake

    Thanks Chris, that's all very useful information. I've added a conditional check and it works fine.

    Out of curiosity, do most projects which are distributed by source use this method of configuring Makefiles?

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: configuring optional dependencies in qmake or cmake

    No, I think that most projects doing mass distribution of source code include an autoconf configure script. Cmake is becoming more common also. I've not had much to do with building Qt apps using either approach.

  8. #7
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: configuring optional dependencies in qmake or cmake

    OK, thanks for the help & info.

Similar Threads

  1. Replies: 3
    Last Post: 19th July 2010, 10:59
  2. qmake project dependencies
    By akos.maroy in forum Newbie
    Replies: 1
    Last Post: 15th June 2008, 13:52
  3. Qmake + Xcode + Dependencies?
    By amnesiac in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2008, 13:45
  4. Adding library dependencies to qmake
    By sadastronaut in forum Installation and Deployment
    Replies: 2
    Last Post: 18th March 2008, 17:06
  5. QMAKE: Specifying Build Dependencies
    By JohnSuykerbuyk in forum Qt Programming
    Replies: 1
    Last Post: 5th May 2006, 09:46

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.