Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qmake: editing global configuration for a SUBDIRS project

Qmake: editing global configuration for a SUBDIRS project

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
15 Posts 4 Posters 1.7k 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on 3 Jul 2023, 18:14 last edited by Violet Giraffe 7 Mar 2023, 18:29
    #1

    I have a SUBDIRS project with somewhat non-trivial structure and configuration needs. Is there any way I can affect the global configuration for the whole SUBDIRS project, e. g. for all of its sub-targets, from a single place?

    At this point I just want to signal to the sub-projects that the parent wants them built a certain way. CONFIG += MY_CONF, DEFINES += MY_CONF, MY_VAR = MY_CONF - either of these will do, anything that I can check in the .pro files. But it has to be done in a file that I can commit to the repo, e. g. qmake -r CONFIG+=MY_CONF is not a desired solution.

    For example, I tried CONFIG += MY_CONF in the root .pro file, and it has no effect on the children. Same for declaring a variable.

    I also tried .qmake.cache. The docs say: "When qmake is run, it looks for a file called .qmake.cache in parent directories of the current directory". I placed a .qmake.cache file one folder above the SUBDIRS .pro file, and it is picked up by the root .pro file, but it's not picked up by the children .pro files, probably because the .cache file is not in the children's root. I don't want it to be in their root because then it will affect other project as well which defeats the point.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Jul 2023, 18:27 last edited by
      #2

      Hi,

      If memory serves well, you can put a .qmake.conf in your project's root folder and it's content should be available in all sub-folders .pro file.

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

      V 1 Reply Last reply 3 Jul 2023, 18:32
      1
      • S SGaist
        3 Jul 2023, 18:27

        Hi,

        If memory serves well, you can put a .qmake.conf in your project's root folder and it's content should be available in all sub-folders .pro file.

        V Offline
        V Offline
        Violet Giraffe
        wrote on 3 Jul 2023, 18:32 last edited by Violet Giraffe 7 Mar 2023, 18:33
        #3

        @SGaist, hi! do you mean .qmake.cache? I just edited my question to say it doesn't seem to work in a useful way (it does work in principle, it just doesn't do the right thing).

        S 1 Reply Last reply 3 Jul 2023, 19:09
        0
        • V Violet Giraffe
          3 Jul 2023, 18:32

          @SGaist, hi! do you mean .qmake.cache? I just edited my question to say it doesn't seem to work in a useful way (it does work in principle, it just doesn't do the right thing).

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Jul 2023, 19:09 last edited by
          #4

          No no, it's really .qmake.conf that I was suggesting.

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

          V 1 Reply Last reply 3 Jul 2023, 19:28
          0
          • S SGaist
            3 Jul 2023, 19:09

            No no, it's really .qmake.conf that I was suggesting.

            V Offline
            V Offline
            Violet Giraffe
            wrote on 3 Jul 2023, 19:28 last edited by
            #5

            @SGaist, then I don't understand how to use it, it's not documented for this use case. After renaming .qmake.cache to .qmake.conf it doesn't look like it's picked up at all. cache was picked up.

            S 1 Reply Last reply 3 Jul 2023, 19:43
            0
            • V Violet Giraffe
              3 Jul 2023, 19:28

              @SGaist, then I don't understand how to use it, it's not documented for this use case. After renaming .qmake.cache to .qmake.conf it doesn't look like it's picked up at all. cache was picked up.

              S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 3 Jul 2023, 19:43 last edited by
              #6

              Where do you have that file located ?
              What is in it ?

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

              V 1 Reply Last reply 3 Jul 2023, 20:07
              0
              • S SGaist
                3 Jul 2023, 19:43

                Where do you have that file located ?
                What is in it ?

                V Offline
                V Offline
                Violet Giraffe
                wrote on 3 Jul 2023, 20:07 last edited by Violet Giraffe 7 Mar 2023, 20:10
                #7

                @SGaist
                It's located one directory above the SUBREPOS .pro file. The contents is as follows. There is no message, and no config or variable in the sub-projects.

                CONFIG += my_config
                MY_VAR=12345678
                message(CACHE!!!)
                
                P 1 Reply Last reply 4 Jul 2023, 01:18
                0
                • V Violet Giraffe
                  3 Jul 2023, 20:07

                  @SGaist
                  It's located one directory above the SUBREPOS .pro file. The contents is as follows. There is no message, and no config or variable in the sub-projects.

                  CONFIG += my_config
                  MY_VAR=12345678
                  message(CACHE!!!)
                  
                  P Offline
                  P Offline
                  Pixelgrease
                  wrote on 4 Jul 2023, 01:18 last edited by Pixelgrease 7 Apr 2023, 01:32
                  #8

                  @Violet-Giraffe I hope I can provide useful input. @SGaist gave me advice on a different problem and while I haven't resolved my problem, I think I see the behavior you want to achieve; my .qmake.conf adds a value to CONFIG that propagates to all subfolder projects.

                  I have a root SUBDIRS project. In that project folder, I have a .qmake.conf file containing:

                  CONFIG += my_velociraptor
                  

                  I added message() statements to each of my .pro files such as:

                  contains(CONFIG, my_velociraptor): message(root SUBDIRS .pro file: \
                      my_velociraptor found in $$_PRO_FILE_)
                  

                  My output:

                  Project MESSAGE: root SUBDIRS .pro file: my_velociraptor found in E:/Dev/QtTestPlay/QtTestPlay.pro
                  Project MESSAGE: my_velociraptor found in E:/Dev/QtTestPlay/TestName-1/TestName-1.pro
                  Project MESSAGE: my_velociraptor found in E:/Dev/QtTestPlay/AutoTestProject-2/AutoTestProject-2.pro
                  

                  Each .pro file confirms the presence of the CONFIG value I added in the .qmake.conf file in the same folder as the .pro file containing TEMPLATE = subdirs.

                  BTW, I had to touch my .pro files before running qmake, otherwise I didn't get the message() output. Might be obvious, but I thought I'd mention it incase you run into that.

                  V 1 Reply Last reply 4 Jul 2023, 09:07
                  1
                  • P Pixelgrease
                    4 Jul 2023, 01:18

                    @Violet-Giraffe I hope I can provide useful input. @SGaist gave me advice on a different problem and while I haven't resolved my problem, I think I see the behavior you want to achieve; my .qmake.conf adds a value to CONFIG that propagates to all subfolder projects.

                    I have a root SUBDIRS project. In that project folder, I have a .qmake.conf file containing:

                    CONFIG += my_velociraptor
                    

                    I added message() statements to each of my .pro files such as:

                    contains(CONFIG, my_velociraptor): message(root SUBDIRS .pro file: \
                        my_velociraptor found in $$_PRO_FILE_)
                    

                    My output:

                    Project MESSAGE: root SUBDIRS .pro file: my_velociraptor found in E:/Dev/QtTestPlay/QtTestPlay.pro
                    Project MESSAGE: my_velociraptor found in E:/Dev/QtTestPlay/TestName-1/TestName-1.pro
                    Project MESSAGE: my_velociraptor found in E:/Dev/QtTestPlay/AutoTestProject-2/AutoTestProject-2.pro
                    

                    Each .pro file confirms the presence of the CONFIG value I added in the .qmake.conf file in the same folder as the .pro file containing TEMPLATE = subdirs.

                    BTW, I had to touch my .pro files before running qmake, otherwise I didn't get the message() output. Might be obvious, but I thought I'd mention it incase you run into that.

                    V Offline
                    V Offline
                    Violet Giraffe
                    wrote on 4 Jul 2023, 09:07 last edited by Violet Giraffe 7 May 2023, 10:09
                    #9

                    @Pixelgrease, thanks a lot for the detailed answer!

                    Does it so happen that for your project this qmake.conf file is in one of the parent directories relative to the sub-projects? My desired folder hierarchy is like so:

                    ..
                    |--lib1
                    |--lib2
                    |--projects
                               |--prj1
                                     |--prj1.pro
                               |--prj2
                                     |--prj2.pro
                    

                    As you can see, if I want to supply separate configs for prj1.pro and prj2.pro, there doesn't seem to be a way. Both projects use lib1 and lib2 as SUBDIRS (in reality there's 10+ libs, but otherwise it's like this).

                    S 1 Reply Last reply 5 Jul 2023, 03:44
                    0
                    • V Violet Giraffe
                      4 Jul 2023, 09:07

                      @Pixelgrease, thanks a lot for the detailed answer!

                      Does it so happen that for your project this qmake.conf file is in one of the parent directories relative to the sub-projects? My desired folder hierarchy is like so:

                      ..
                      |--lib1
                      |--lib2
                      |--projects
                                 |--prj1
                                       |--prj1.pro
                                 |--prj2
                                       |--prj2.pro
                      

                      As you can see, if I want to supply separate configs for prj1.pro and prj2.pro, there doesn't seem to be a way. Both projects use lib1 and lib2 as SUBDIRS (in reality there's 10+ libs, but otherwise it's like this).

                      S Offline
                      S Offline
                      stan.m
                      wrote on 5 Jul 2023, 03:44 last edited by
                      #10

                      @Violet-Giraffe My .qmake.conf is in the same folder as the topmost .pro file with a SUBDIRS directive.

                      I just followed repeated my steps in another project and I got logging output in the QC "General Messages" tab each time I saved a modified .pro file after adding the message() directive from my previous post.

                      Based on your tree diagram, you have 3 subfolders (lib1, lib2, and projects) within the same folder.

                      If that folder has a topmost_project.pro containing SUBDIRS += lib1 lib2 projects then that is where the .qmake.conf belongs. The variables declared or modified in that file will be available to every .pro file below them.

                      If instead you put it in the same folder as your projects.pro having SUBDIRS += prj1 prj2 then the CONFIG change will only be available to them.

                      V 1 Reply Last reply 5 Jul 2023, 10:09
                      0
                      • S stan.m
                        5 Jul 2023, 03:44

                        @Violet-Giraffe My .qmake.conf is in the same folder as the topmost .pro file with a SUBDIRS directive.

                        I just followed repeated my steps in another project and I got logging output in the QC "General Messages" tab each time I saved a modified .pro file after adding the message() directive from my previous post.

                        Based on your tree diagram, you have 3 subfolders (lib1, lib2, and projects) within the same folder.

                        If that folder has a topmost_project.pro containing SUBDIRS += lib1 lib2 projects then that is where the .qmake.conf belongs. The variables declared or modified in that file will be available to every .pro file below them.

                        If instead you put it in the same folder as your projects.pro having SUBDIRS += prj1 prj2 then the CONFIG change will only be available to them.

                        V Offline
                        V Offline
                        Violet Giraffe
                        wrote on 5 Jul 2023, 10:09 last edited by
                        #11

                        @stan-m
                        And that is the problem. prj1.pro is one top-most project. prj2.pro is another one. Both use lib1.pro and lib2.pro, but they require different configuration.

                        P 1 Reply Last reply 5 Jul 2023, 15:51
                        0
                        • V Violet Giraffe
                          5 Jul 2023, 10:09

                          @stan-m
                          And that is the problem. prj1.pro is one top-most project. prj2.pro is another one. Both use lib1.pro and lib2.pro, but they require different configuration.

                          P Offline
                          P Offline
                          Pixelgrease
                          wrote on 5 Jul 2023, 15:51 last edited by
                          #12

                          @Violet-Giraffe Your first sentences in the OP says there is a "SUBDIRS project". Where is it?

                          Are there two? Then put custom .qmake.conf files in those folders: every project below them will get the customizations.

                          V 1 Reply Last reply 5 Jul 2023, 16:35
                          0
                          • P Pixelgrease
                            5 Jul 2023, 15:51

                            @Violet-Giraffe Your first sentences in the OP says there is a "SUBDIRS project". Where is it?

                            Are there two? Then put custom .qmake.conf files in those folders: every project below them will get the customizations.

                            V Offline
                            V Offline
                            Violet Giraffe
                            wrote on 5 Jul 2023, 16:35 last edited by
                            #13

                            @Pixelgrease
                            prj1.pro and prj2.pro are two separate SUBDIRS projects. That need different customization. And this per-project customization needs to be applied to lib1 and lib2 as well. lib1 and lib2 should compile differently based on the needs of the parent top-most project.

                            P S 2 Replies Last reply 5 Jul 2023, 17:53
                            0
                            • V Violet Giraffe
                              5 Jul 2023, 16:35

                              @Pixelgrease
                              prj1.pro and prj2.pro are two separate SUBDIRS projects. That need different customization. And this per-project customization needs to be applied to lib1 and lib2 as well. lib1 and lib2 should compile differently based on the needs of the parent top-most project.

                              P Offline
                              P Offline
                              Pixelgrease
                              wrote on 5 Jul 2023, 17:53 last edited by Pixelgrease 7 May 2023, 17:54
                              #14

                              @Violet-Giraffe Are the lib projects built by the separate prj* SUBDIRS .pro files? If so, I suspect that even though they are higher in the folder structure than the main .pro project they would get the customizations.

                              I'm too busy at work to test this... Monday I was working on a similar problem but today I'm on something completely different and don't have time to build test projects.

                              If it works, you would put your .qmake.conf files in each of the prj*.pro folders. You could use an include directive to reference a shared .pri in the projects folder and have only customizations in the .qmake.conf file.

                              My uncertainty is lack of experience with .qmake.conf -- I only learned about it on Monday. .qmake.conf looks like magic. I wish I knew about it 4 years ago when I started my unit tests project. Now I have over 100 unit test project folders across multiple levels of SUBDIRS .pro files that all use the same libraries; I would have used this.

                              Have you tried using .qmake.conf ? It took me 2 minutes to verify behavior in a completely separate project, but I knew how .qmake.conf works. Getting it to work the first time can be frustrating.

                              1 Reply Last reply
                              0
                              • V Violet Giraffe
                                5 Jul 2023, 16:35

                                @Pixelgrease
                                prj1.pro and prj2.pro are two separate SUBDIRS projects. That need different customization. And this per-project customization needs to be applied to lib1 and lib2 as well. lib1 and lib2 should compile differently based on the needs of the parent top-most project.

                                S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 5 Jul 2023, 18:20 last edited by
                                #15

                                @Violet-Giraffe how did you setup your subdirs project ?

                                It seems you have a "reverse setup" (for lack of a better name) issue meaning that a lower-level project should influence the build of a higher level one.

                                If I understood correctly it seem that prj1 and prj2 should in fact each define the whole subdirs structure by being "pseudo top level" projects including the higher level folders in their definition. Your top level pro file would then just contain prj1 and prj2. Note that I currently don't know if would be working that way.

                                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

                                1/15

                                3 Jul 2023, 18:14

                                • Login

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