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 "contains" test function weird behaviour
Qt 6.11 is out! See what's new in the release blog

Qmake "contains" test function weird behaviour

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

    When I use the qmake "contains" test function and I have SOURCES += ... and HEADERS += ... in the scope of the function, the sources and header files get included into the project independently if the "contains" function is true or not. This is how I am using the contains function:

    @
    contains(MODULES, PLOT){
    message( "Add module: plot" )
    SOURCES += libraries/plot.cpp
    HEADERS += libraries/plot.h
    }
    @

    if MODULES is empty or does not contain "PLOT" it won't print the message but it will still include the sources and headers. These will even show in Qt Creator on the projects tree. I would expect this NOT to happen. Anything that I may missing here? Any other way I could selectively include files with a variable?

    The "contains" test function is described here: http://doc.qt.io/qt-5/qmake-test-function-reference.html

    1 Reply Last reply
    0
    • M Offline
      M Offline
      msue
      wrote on last edited by
      #2

      I use "contains" but always with a colon, though I am not sure whether this is the problem here:
      @ contains(MODULES, PLOT): {
      message( "Add module: plot" )
      SOURCES += libraries/plot.cpp
      HEADERS += libraries/plot.h
      }
      @

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Are you sure you are not adding these files somewhere else in your pro file ?

        Your code works fine

        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
        • S Offline
          S Offline
          spacemig
          wrote on last edited by
          #4

          So, it seems like Qt Creator in Windows will show all the files even if it won't use them to compile. On the other hand Qt Creator on the Mac will hide them (this is what I would expect).

          The other interesting "bug" is that when I add an "include" inside an "include" it will show a folder on the Project browser at the root level. It would be more convenient to show it in subfolders inside the first include.

          Example
          myproject.pro
          MODULES += DONTLOADLIB3DS
          include( thirdparty/thirdparty.pri )

          thirdparty.pri
          contains(MODULES, LIB3DS){
          message( "Add thirdparty module: LIB3DS" )
          # >> Qt Creator should not list these files because the MODULES variable is not set to LIB3DS
          include( thirdparty/lib3ds.pri )
          }

          Is this an expected behavior or a bug in Qt Creator?

          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