Results 1 to 5 of 5

Thread: qmake set arbitrary makefile variable from qmake

  1. #1
    Join Date
    Oct 2011
    Location
    Australia
    Posts
    29
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default qmake set arbitrary makefile variable from qmake

    Hi.

    I want to set some arbitrary variable in the makefile generated by qmake. How can I do this? I can't imaging this can't be done but can't find mention of it anywhere.

    Use case; I want to generate a makefile compatible with the GNU stds, which entails defining vars in the make file such as "prefix" that can be overridden when running the make file. So for example my .pro would look like:

    Qt Code:
    1. TEMPLATE = app
    2. TARGET = foo
    3. CONFIG += ...
    4. CCFLAGS += -g
    5. prefix=/usr/local/
    6. exec_prefix=$(prefix)
    7. bindir=$(exec_prefix)/bin
    8. datarootdir=$(prefix)/share
    9. datadir=$(datarootdir)
    10. libdir=$(exec_prefix)/lib
    11. ...
    To copy to clipboard, switch view to plain text mode 

    But I need most of those variables exported to the Makefile.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qmake set arbitrary makefile variable from qmake

    Hmm, since your example is prefix, that is usually passed to qmake.
    qmake, like e.g. configure, preforms the build configuration step, which generates a Makefile that is then "executed" by make.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2011
    Location
    Australia
    Posts
    29
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: qmake set arbitrary makefile variable from qmake

    Thx for the reply.

    So your saying I should use qmake like configure and do something like `qmake "prefix=/usr/local"`. The particular reason I wanted to set in the make file is that its going to be more compatible with trying to build a debian package from the source with `dh`, rather than the dh seeing hardcoded /usr/local/ prefixes, it can set the prefix(s) itself. I think these issues can be worked around by dh anyway, and I'm finding the way to go about packaging Qt apps with dh is to make dh work with qmake not qmake work for dh.

    Still, I would like to know if its possible to set variables in the qmake generated Makefile directly.
    Last edited by 33333; 7th July 2014 at 00:45.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qmake set arbitrary makefile variable from qmake

    Quote Originally Posted by 33333 View Post
    So your saying I should use qmake like configure and do something like `qmake "prefix=/usr/local"`.
    yes, qmake PREFIX=/somepath actually, if I remember qmake's built-in variables correctly.

    Quote Originally Posted by 33333 View Post
    The particular reason I wanted to set in the make file is that its going to be more compatible with trying to build a debian package from the source with `dh`
    Ah, but wouldn't that also point to using the configure stage?
    Usually make is only invoked with make arguments, no?


    Quote Originally Posted by 33333 View Post
    I think these issues can be worked around by dh anyway, and I'm finding the way to go about packaging Qt apps with dh is to make dh work with qmake not qmake work for dh.
    There are plenty of Qt applications in the Debian repository, so that must be a solved problem

    Quote Originally Posted by 33333 View Post
    Still, I would like to know if its possible to set variables in the qmake generated Makefile directly.
    More precisely you want qmake to generate variables and you want to set them through make.

    Since it is not very common to set variables at make (usually done during configure), I am not sure if qmake's generator can do that.

    You can add custom targets though: http://qt-project.org/doc/qt-5/qmake...ced-usage.html

    Cheers,
    _

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

    33333 (7th July 2014)

  6. #5
    Join Date
    Oct 2011
    Location
    Australia
    Posts
    29
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: qmake set arbitrary makefile variable from qmake

    anda_skao, you are right it is a solved problem. I sort of waded into it without thinking too much and then discovered this inability to pass variables on to make files. You are also right in that "PREFIX" seems to be the convention for passing the "prefix" onto qmake, and that you can't pass variables on to make (I don't think!! Still don't no for sure).

    Just to cover off on the debian packages: I have found `dh` already has automatic handling for qmake project files! `dh_auto_build` does this in the configure stage by default:

    Qt Code:
    1. qmake -makefile -nocache QMAKE_STRIP=: PREFIX=$prefix
    To copy to clipboard, switch view to plain text mode 

    So qmake projects with an INSTALL rule will build with `dh` automatically in most cases. In my case I also needed configure, so I'm calling qmake as shown but from a configure script.

    Thanks for the help.

Similar Threads

  1. Replies: 2
    Last Post: 28th June 2014, 07:21
  2. Replies: 2
    Last Post: 27th June 2014, 00:36
  3. Replies: 1
    Last Post: 31st March 2011, 18:38
  4. makefile without using QMake
    By Rayven in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2010, 22:04
  5. Qmake for subdirs w/ custom makefile name
    By Frank J. Lhota in forum Qt Tools
    Replies: 1
    Last Post: 10th June 2009, 00:59

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.