Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMake - define variable, check value inside project file
Forum Updated to NodeBB v4.3 + New Features

QMake - define variable, check value inside project file

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alexandros
    wrote on 9 Oct 2013, 17:22 last edited by
    #1

    In my program I want to alter some values in order to make my program compilable for different Desktop Environments. While I can check from pre-set values whether I am running under windows or linux, I am unable to determine the current DE that I am running so as to alter my code and adapt it to each DE every time.

    So, I decided to declare my own variables inside the configuration file.

    @DEFINES += "FOR_GNOME=0"
    DEFINES += "FOR_LUNA=1"
    DEFINES += "FOR_AERO=0"@

    Now I need to check whether a value from the above is true or not. I could just define a variable (e.g. FOR_GNOME) and then use defined() function and #ifdef inside the code in order to determine the target Desktop Environment, but, because of the fact that there are many DEs as targets, I don't want to have to memorize all these variable names (so as to remember what to place inside the .pro file at the "DEFINES +=" each time). So, I want to define all of them and give value 1 to the target DE.

    Now, I need to make preprocessor checks for each DE separately. For example, if I am under GNOME I need specific libraries to link via PKGCONFIG. So , this is what I imagine it to be:

    @DEFINES += "FOR_GNOME=0"
    DEFINES += "FOR_LUNA=1"
    DEFINES += "FOR_AERO=0"

    contains(FOR_GNOME, 1){
    #build for GNOME, link gio-2.0 so as to use the gsettings library
    CONFIG += link_pkgconfig
    PKGCONFIG += gio-2.0
    }

    contains(FOR_LUNA, 1){
    #do something else
    }@
    This is just example code of how I imagine it to be.

    Then, I want to use these inside my code:

    @#if FOR_GNOME
    //code
    #elif FOR_LUNA
    //more code
    ...
    #endif@

    The main problem is that contains() function does not work (while it should, as far as I correctly understand the documentation). Also, I tried:

    @FOR_GNOME {
    #build for GNOME, link gio-2.0 so as to use the gsettings library
    CONFIG += link_pkgconfig
    PKGCONFIG += gio-2.0
    }@

    but it didn't work either. With the 2nd way FOR_GNOME should be inside CONFIG, but then I don't know how to make it available in my code.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Oct 2013, 20:59 last edited by
      #2

      Hi,

      You could use something like this:

      @
      CONFIG += gnome
      contains(CONFIG, gnome) {
      DEFINES += FOR_GNOME
      //etc...
      }
      @

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexandros
        wrote on 9 Oct 2013, 21:03 last edited by
        #3

        Thanks for the answer. Yes, this seems to be what I am looking for :)

        1 Reply Last reply
        0

        1/3

        9 Oct 2013, 17:22

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved