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. [SOLVED]How to set options with qmake?
QtWS25 Last Chance

[SOLVED]How to set options with qmake?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.5k Views
  • 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.
  • S Offline
    S Offline
    samkpo
    wrote on last edited by
    #1

    I want to enable/disable a feature using qmake, in this way:

    @qmake --enable-feature@

    but i can't find the way to do it.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leppa
      wrote on last edited by
      #2

      I don't know about how to do it the way you want, but I can suggest a slightly different one.

      If you run
      @qmake CONFIG+=myfeature@

      Then you can test for myfeature in a project file and conditionally include source code or add definitions like this:
      @myfeature {
      # rules to execute when myfeature IS defined:
      DEFINES += MY_FEATURE_ENABLED
      HEADERS += src/additional_feature.h
      SOURCES += src/additional_feature.cpp
      } else {
      # rules to execute when myfeature NOT defined
      DEFINES += MY_FEATURE_DISABLED
      }@

      Actually, I use it in my project to enable/disable SVG support. But be careful about naming myfeature - don't name it like any of the files in mkspecs/features folder of Qt source.

      --
      With best regards,
      Oleksii Serdiuk <contacts[at]oleksii[dot]name>
      https://oleksii.name/

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #3

        Another option is to write a very simple configure script that writes out to a .pri file that is included by your .pro file. Sometimes it can also be useful to have such a script generate a header file that contains useful #defines or other declarations. For one project I have done something like this:

        @
        #!/bin/bash

        if [ "$1" = "crypto" ]; then
        echo Enabling cryptographic support
        echo "#define MAPS_CRYPTO" > src/mapscore/mapscore_config.h
        echo "CONFIG += crypto" > src/mapscore/mapscore_config.pri
        echo Wrote src/mapscore/mapscore_config.h and src/mapscore/mapscore_config.pri
        elif [ "$1" = "nocrypto" ]; then
        echo Disabling cryptographic support
        echo "#undef MAPS_CRYPTO" > src/mapscore/mapscore_config.h
        echo "CONFIG -= crypto" > src/mapscore/mapscore_config.pri
        echo Wrote src/mapscore/mapscore_config.h and src/mapscore/mapscore_config.pri
        else
        echo "usage: configure [mode]"
        echo "modes:"
        echo " crypto enable cryptographic support"
        fi
        @

        Then in the .pro file I include the .pri file with:

        @include( mapscore_config.pri )@

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leppa
          wrote on last edited by
          #4

          [quote author="ZapB" date="1301298762"]Another option is to write a very simple configure script that writes out to a .pri file that is included by your .pro file. Sometimes it can also be useful to have such a script generate a header file that contains useful #defines or other declarations.[/quote]
          This way isn't very portable: you'll have to write separate scripts for separate platforms (e.g., Linux vs Windows). You can workaround this by writing your configure script in some interpreted language, available for all target platforms (Perl, Python, PHP, etc.). But it will introduce additional dependency and anybody who wishes to compile your app will need to install this language (if it's not already included on their platform).

          Anyway, this option is still good if you only target similar platforms.

          --
          With best regards,
          Oleksii Serdiuk <contacts[at]oleksii[dot]name>
          https://oleksii.name/

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #5

            Yeah I know. We write a similar script for Windows too. As you say perl/pythin etc would be better. cmake might be a better option here.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leppa
              wrote on last edited by
              #6

              You're right, by the way, cmake might be an option, too. Everything depends on how advanced the conditional rules have to be. My solution is good for trivial tests, like include this if condition is true. If you need some advanced tests, like include this if condition is true and this library is available (+ test for library fetures) or the other library is available and additional conditions are set, then it's better to write a configure script or use a build system like cmake.

              --
              With best regards,
              Oleksii Serdiuk <contacts[at]oleksii[dot]name>
              https://oleksii.name/

              1 Reply Last reply
              0
              • S Offline
                S Offline
                samkpo
                wrote on last edited by
                #7

                Thanks guys, the way Lёppa posted at the beginning is what i was looking for.
                what i did was:

                @webp_support {
                # rules to execute when myfeature IS defined:
                DEFINES += WEBP_SUPPORT
                #HEADERS += src/additional_feature.h
                #SOURCES += src/additional_feature.cpp
                } else {
                # rules to execute when myfeature NOT defined
                #DEFINES += MY_FEATURE_DISABLED
                }@

                and in main.cpp added:

                @#ifdef WEBP_SUPPORT
                //if i do qmake CONFIG+=webp_support
                qDebug()<<"webp support";
                #else
                qDebug()<<"not webp support";
                #endif@

                to test it

                1 Reply Last reply
                0

                • Login

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