Setting up a SUBDIRS project correctly
-
Using qmake in Qt Creator 18.0.2, I'm investigating the different possibilities of setting up the global "Default Build Directory" in Qt Creator settings (in "Preferences/Build & Run") to facilitate doing out-of-source builds. I see many wildcards I can use, such as
"%{BuildConfig:Name}"and"%{Project:Name}", but I can't find anything that would allow inserting the contents of the qmakeTEMPLATE.The project consists of one main SUBDIRS project file, calling this "MyApp.pro", an "App.pro" with TEMPLATE=app and two subprojects, each of which have TEMPLATE=lib. These "lib" subprojects are responsible for generating one static library each. The source code is organized like this -- the folders marked with "SCM" are under source code management, and any build folders or binary files, should be placed outside of these:
MyApp ├── 3rd_party <== SCM 'REPO_THIRD' │ ├── lib_1 │ │ └── src │ └── lib_2 │ └── src └── App <== SCM 'REPO_APP' ├── include ├── qrc ├── src ├── translations └── ui App.pro MyApp.pro Lib_1.pro Lib_2.proI know that it is unusual to have all of the .pro files in the same folder as the main project, but this works out well. I can get
MyApp.proto build the application correctly with this as my default build in "Preferences":../build/%{Project:Name}/%{Qt:Version}/%{BuildConfig:Name}This results in the following shadowed build folder after opening the main "MyApp" project file in Qt Creator when I click on "Projects" in the task bar:
MyApp/build/MyApp/6.10.2/Debugusing a kit for Qt 6.10.2, for example, building in Debug mode. I create a "lib" folder parallel to the "build" folder in the library projects by setting DESTDIR and TARGET appropriately.
Since I would eventually like to migrate the qmake build to CMake (or at least offer a CMake build as an alternative to the qmake build), the folder structure should end up looking something like this:
MyApp ├── build │ ├── appbuild │ │ ├── Debug │ │ └── Release │ └── libbuild │ ├── Debug │ └── Release ├── 3rd_party <== SCM 'REPO_THIRD' │ ├── Lib_1 │ │ └── src │ └── Lib_2 │ └── src └── App <== SCM 'REPO_APP' (etc.)That way, the "build" subfolder can be created in the traditional (?) CMake fashion either in Creator or by doing
cmake -B buildfrom the project directory.But what is the trick for getting the strings "appbuild" and "libbuild" into the "Default Build Directory" setting? I don't want to have to manually edit the shadow build directory for each configuration. Ideally, one should be able to write
%{Project:Template}to achieve this, but i couldn't find anything. -
C Christian Ehrlicher moved this topic from General and Desktop
-
I have solved this by defining everything under the "build" folder in the different *.pro files. It seems that if a subproject is configured individually, i.e. outside of the SUBDIRS project, whatever configuration is overridden by the SUBDIRS main project configuration.
I put the "TEMPLATE=lib" subproject files into the "3rd_party" folder. The only drawback is then that the different
Makefiles.*and.qmake.stashfiles used in building the libraries are also generated in that folder which is under source code management. However, these can be ignored by the SCM by applying the corresponding settings necessary for ignoring certain files. -
R Robert Hairgrove has marked this topic as solved