Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED]How to set options with qmake?

    General and Desktop
    3
    7
    5021
    Loading More Posts
    • 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
      samkpo last edited by

      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 Reply Quote 0
      • L
        leppa last edited by

        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 Reply Quote 0
        • Z
          ZapB last edited by

          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 Reply Quote 0
          • L
            leppa last edited by

            [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 Reply Quote 0
            • Z
              ZapB last edited by

              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 Reply Quote 0
              • L
                leppa last edited by

                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 Reply Quote 0
                • S
                  samkpo last edited by

                  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 Reply Quote 0
                  • First post
                    Last post