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. [Moved] How to set Sources Directory in QMake
QtWS25 Last Chance

[Moved] How to set Sources Directory in QMake

Scheduled Pinned Locked Moved Qt Creator and other tools
18 Posts 10 Posters 42.9k 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.
  • R Offline
    R Offline
    raulgd
    wrote on last edited by
    #1

    Hi everyone...

    I want to order my project files this way:

    @
    / *root
    /myproject.pro
    /include *the .h files
    /src *the .cpp files
    @

    Is there a way I can do this with qmake? because as I see in qmake, I can set the includes folder with the INCLUDEPATH, but I can't find any variable in the documentation to set the SRC file. Any tips on this? As you can imagine, my .pro file is in root. I have thought about placing the .pro file in src, but I don't feel it's the usual project structure, usually you place the makefile in root, and then have a src, include and lib folders.

    Thanks!

    [EDIT: @-tags for formatting, Volker]

    Raul Guerrero
    http://jimi.mx

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

      You can use the relative path in the SOURCES variable in your .pro file (SOURCES += src/somefile.cpp)

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        ucomesdag
        wrote on last edited by
        #3

        You can use the "subdirs":http://doc.trolltech.com/4.7/qmake-variable-reference.html#subdirs variable in your pro file.

        My pro file looks like this for example:

        @TEMPLATE = subdirs
        CONFIG += ordered
        SUBDIRS += src@

        And in the sub directories the actual .pro file.

        Write “Qt”, not “QT” (QuickTime).

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raulgd
          wrote on last edited by
          #4

          @mlong - using relative path to SOURCES still doesn't change the fact that I'd have the src/ in the file path, that's exactly what I'm trying to avoid.

          @ucomesdag - the subdirs template would mean that I need to configure .pri files, so I'd have to setup a module, which is not a clean way of doing that

          Raul Guerrero
          http://jimi.mx

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            I don't believe there is a variable for setting the source path. As I recall, the INCLUDEPATH variable is used for resolving the #include locations in your source code at compile time, not for qmake to locate the headers' location in the source tree in your project. You'll still need to explicitly include the paths to the headers in the HEADERS variable (HEADERS += include/foo.h).

            No matter which way you go, the SOURCES and HEADERS variables need to explicitly point to the files you're using, either in a subdirectory or in the working directory.

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Thanatos.jsse
              wrote on last edited by
              #6

              Well Raul, try to add "DEPENDPATH":http://doc.qt.nokia.com/latest/qmake-variable-reference.html#dependpath variable to *.pro file.

              @#Something like this
              ...
              DEPENDPATH += $$PWD/src
              ...@

              Good luck...

              1 Reply Last reply
              0
              • R Offline
                R Offline
                raulgd
                wrote on last edited by
                #7

                @mlong - yeah, I guess you're right, there is no other way to go, I'll just have to settle and have the src/ and include/ in my project files, thanks :)

                @thanatos.jsse - on you DEPENDPATH, instead of using $$PWD/src you could use ./src instead, relative paths are allowed that way, just so you know ;)

                Raul Guerrero
                http://jimi.mx

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  leon.anavi
                  wrote on last edited by
                  #8

                  Hi Raul,

                  I had the same problem and honestly did not find a good solution. You can use the following code at the pro file to include all files from a given directory to the source:

                  @SOURCES += src/*
                  @

                  This idea will not avoid the the src/ in the file path but at least you will not to add a list of all files and paths to them at the pro file.

                  Best regards,
                  Leon

                  http://anavi.org/

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    florent.revelut
                    wrote on last edited by
                    #9

                    If you want to split the file names and their location, you can use
                    @
                    VPATH += ./src
                    SOURCES += files1.cpp file2.cpp
                    @

                    VPATH is somehow the equivalent for source files of nclude path for makefiles.

                    You can have a look at "qmake doc":http://doc.qt.nokia.com/4.7/qmake-variable-reference.html#vpath

                    1 Reply Last reply
                    1
                    • R Offline
                      R Offline
                      raulgd
                      wrote on last edited by
                      #10

                      @florent.revelut - cool thanks! that's almost what I need, too bad that Qt Creator still shows me the src and include as folders in the "sources" and "headers" section in the project tree, it would be nice if Qt Creator could dismiss that and use the vpath paths as root folders for sources.

                      Thanks!

                      Raul Guerrero
                      http://jimi.mx

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #11

                        [quote author="Raul" date="1301293630"]@florent.revelut - cool thanks! that's almost what I need, too bad that Qt Creator still shows me the src and include as folders in the "sources" and "headers" section in the project tree, it would be nice if Qt Creator could dismiss that and use the vpath paths as root folders for sources.

                        Thanks![/quote]

                        Hmmm... no thanks to that feature, if you ask me. I actually like that the separation into folders is preserved. Perhaps we organize our projects in different ways, but for me Creator just putting them on the same level would be going backwards.

                        1 Reply Last reply
                        0
                        • F Offline
                          F Offline
                          florent.revelut
                          wrote on last edited by
                          #12

                          André : well, I don't agree 100% percent with you.

                          Personnally, I like when I can split physical organisation and logical organisation.

                          Physical organisation has to deal with constraint, dependencies, configuration management (e.g. some part of code delivered by another team, from open source project, from other repository).

                          Logical organisation is how you want to display it in your UI, which is "human related"

                          Exemple:

                          • you can organise your code per layer in terms of configuration management (applicative, c++, C/ASM)
                          • you want to display your code per feature (i.e. per vertical slices of the layer)

                          Sometime, having 1 sub-project per folder just messes around with your ide.

                          From my point of view, he cleanest is to have a way to split representation from build, a bit like cmake allows to do it.

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            giesbert
                            wrote on last edited by
                            #13

                            I agree that this would be a nice feature.
                            I use it a lot in MSVS, to organize the used files in logical groups.

                            Nokia Certified Qt Specialist.
                            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                            1 Reply Last reply
                            0
                            • mzimmersM Offline
                              mzimmersM Offline
                              mzimmers
                              wrote on last edited by
                              #14

                              I can't believe I haven't had to ask this yet, but...

                              ...what's the recommended technique for adding a directory to the header path? I want to start using the QDeclarativeView.h file, but my makefile doesn't know where to find it. Do I alter my UNIX $PATH variable? Manually edit the .pro file? Change some settings that I currently can't seem to find?

                              Thanks.

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                goetz
                                wrote on last edited by
                                #15

                                mzimmers: add to your .pro file:

                                @QT += declarative@

                                http://www.catb.org/~esr/faqs/smart-questions.html

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  andre
                                  wrote on last edited by
                                  #16

                                  You need to edit the .pro file to add the declarative module to your project. Then the relevant headers will also be found.

                                  1 Reply Last reply
                                  0
                                  • mzimmersM Offline
                                    mzimmersM Offline
                                    mzimmers
                                    wrote on last edited by
                                    #17

                                    Thanks, guys. A very minor follow-up question: is there a convention for the ordering of stuff in the .pro file? In other words, is there a particular place I "should" put this line?

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      andre
                                      wrote on last edited by
                                      #18

                                      Near the top, but that is just me I guess.

                                      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