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. reading #define from external header into .pro file
Forum Update on Monday, May 27th 2025

reading #define from external header into .pro file

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 2.1k 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.
  • N Offline
    N Offline
    nishajones171
    wrote on 5 Feb 2018, 17:17 last edited by
    #1

    I have a project file in which I need to be able to specify whether to include certain source and header files depending on the build configuration. Normally, I'd use a combination of CONFIG and DEFINES to do this. However, my problem is that the value of the configuration needs to come from a #define which is specified in a common header file which is shared across projects, some of which do not use qt. I've tried using infile & fromfile, but neither is returning what I expect - I'm pretty sure they're parsing with the expectation of DEFINES, not #define.

    Does anyone know if what I'm trying to do is possible? (Or can point me towards what I'm doing wrong?)

    ps - I haven't mucked about with .pro files very much, so please forgive any stupid or obvious mistakes.

    here's an example of what I'm trying
    defines.h:
    #define CONFIG_A 0
    #define CONFIG_B 1

    #define MODEL CONFIG_A

    MyProject.pro:
    QT += core gui widgets

    TARGET = MyProject
    TEMPLATE = app

    QMAKE_CXXFLAGS += -std=c++11 -Wall
    include(myProject.pri)
    test = fromfile(defines.h,MODEL)
    message(Build configuration detected: $$test)

    the build output I see (which is what makes me suspect it's not parsing the preprocessor #define the way I want it to) is:
    defines.h(4): Extra characters after test expression.
    defines.h(6): Assignment needs exactly one word on the left hand side.

    J 1 Reply Last reply 6 Feb 2018, 05:32
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 5 Feb 2018, 17:46 last edited by
      #2

      Hi and welcome to the forums
      Im not 100% sure but i think $$fromfile() only likes .pro file not a (c++) .h
      and hence it do not understand it.

      N 1 Reply Last reply 7 Feb 2018, 14:27
      1
      • N nishajones171
        5 Feb 2018, 17:17

        I have a project file in which I need to be able to specify whether to include certain source and header files depending on the build configuration. Normally, I'd use a combination of CONFIG and DEFINES to do this. However, my problem is that the value of the configuration needs to come from a #define which is specified in a common header file which is shared across projects, some of which do not use qt. I've tried using infile & fromfile, but neither is returning what I expect - I'm pretty sure they're parsing with the expectation of DEFINES, not #define.

        Does anyone know if what I'm trying to do is possible? (Or can point me towards what I'm doing wrong?)

        ps - I haven't mucked about with .pro files very much, so please forgive any stupid or obvious mistakes.

        here's an example of what I'm trying
        defines.h:
        #define CONFIG_A 0
        #define CONFIG_B 1

        #define MODEL CONFIG_A

        MyProject.pro:
        QT += core gui widgets

        TARGET = MyProject
        TEMPLATE = app

        QMAKE_CXXFLAGS += -std=c++11 -Wall
        include(myProject.pri)
        test = fromfile(defines.h,MODEL)
        message(Build configuration detected: $$test)

        the build output I see (which is what makes me suspect it's not parsing the preprocessor #define the way I want it to) is:
        defines.h(4): Extra characters after test expression.
        defines.h(6): Assignment needs exactly one word on the left hand side.

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 6 Feb 2018, 05:32 last edited by
        #3

        @nishajones171 It sounds strange if your build configuration is coming from a header file. Usually it is other way around - build system defines variables which then are used in the code.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • N Offline
          N Offline
          nishajones171
          wrote on 7 Feb 2018, 14:20 last edited by
          #4

          Agreed, it's a strange way to do it - it's done this way because it's a multiprocessor environment, and the other processor requires a completely separate IDE, and even within Eclipse, we have one QT project and one non-QT project, so using native CONFIG-type stuff won't work for the non-QT project.

          1 Reply Last reply
          0
          • M mrjj
            5 Feb 2018, 17:46

            Hi and welcome to the forums
            Im not 100% sure but i think $$fromfile() only likes .pro file not a (c++) .h
            and hence it do not understand it.

            N Offline
            N Offline
            nishajones171
            wrote on 7 Feb 2018, 14:27 last edited by
            #5

            @mrjj - yes, that's my understanding as well. And thanks :)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 7 Feb 2018, 14:36 last edited by
              #6

              Hi @nishajones171,

              If you could use environment variables: you can evalute them inside the .pro file by $$(VARIABLE)

              It should be possible to use environment variables in other build systems also.

              Qt has to stay free or it will die.

              N 1 Reply Last reply 8 Feb 2018, 01:17
              3
              • P Offline
                P Offline
                Pablo J. Rogina
                wrote on 7 Feb 2018, 15:51 last edited by
                #7

                @nishajones171 yes, as @aha_1980 mentioned, if you could use environment variables that could simplify things. The Qt project and the non-Qt project both will read and evaluate such variables. Just in case, see this entry for Qt qmake and this entry for Eclipse CDT (I assume you're using it as you mentioned "even Eclipse"

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                N 1 Reply Last reply 8 Feb 2018, 01:22
                4
                • A aha_1980
                  7 Feb 2018, 14:36

                  Hi @nishajones171,

                  If you could use environment variables: you can evalute them inside the .pro file by $$(VARIABLE)

                  It should be possible to use environment variables in other build systems also.

                  N Offline
                  N Offline
                  nishajones171
                  wrote on 8 Feb 2018, 01:17 last edited by
                  #8

                  @aha_1980 That might work - I'll have to run it by the rest of the team, as it's more of a process change, but it does seem like a potential solution. Thanks!

                  1 Reply Last reply
                  0
                  • P Pablo J. Rogina
                    7 Feb 2018, 15:51

                    @nishajones171 yes, as @aha_1980 mentioned, if you could use environment variables that could simplify things. The Qt project and the non-Qt project both will read and evaluate such variables. Just in case, see this entry for Qt qmake and this entry for Eclipse CDT (I assume you're using it as you mentioned "even Eclipse"

                    N Offline
                    N Offline
                    nishajones171
                    wrote on 8 Feb 2018, 01:22 last edited by
                    #9

                    @Pablo-J.-Rogina Appreciate the pointer towards how to do this in Eclipse - very helpful :) I looked around in the other IDE we use (an ancient flavor of IAR Embedded Workbench), and haven't found anything that'd read an environment variable, but it's possible they use a different name for it. In any case, thanks!

                    1 Reply Last reply
                    0

                    1/9

                    5 Feb 2018, 17:17

                    • Login

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