Talking about the shadow build of Qmake (that is, separating the source path from the build path)

Source: Internet
Author: User


Shadow Build


What is Shadow build? is to separate the source path and build path (that is, the generated makefile files and other products are not put into the source path), so as to ensure the clean source path.



It's not Qmake's original thing, CMake used it long ago.


CMake

Qmake

Note

In-source

CMake.

Qmake Project.pro

Execute under the source path

Out-of-source
(Shadow-build)

mkdir Build

CD Build
CMake. /project

mkdir Build

CD Build
Qmake. /project/project.pro

Create directory, execute under other paths (parameters point to Source path)

    • Attention:
    • Qmake Shadow build is still very imperfect, and cmake is not the same
    • Qmake Shadow build directory may not be a subdirectory of the source directory
Before


Before Shadow-build, in order to separate the generated and the source as much as possible, we would generally set a lot of qmake variables, such as:


DESTDIR = $ $PWD/bin

Destination file Drop Location

Dlldestdir = $$[Qt_install_bins]

Win under Copy dynamic library to qt installation path

Moc_dir = $ $PWD/temp

Where the product of the MOC is placed

Rcc_dir = $ $PWD/temp

Where the product of RCC is placed

Ui_dir = $ $PWD/temp

Where the products of UIC are placed

objects_dir =

Pwd / te mp / TARGET

 

compiler-generated. O (. obj) file placement


In this way, we put the extended part of QT (MOC/RCC/UIC) and the intermediate product of the compiler into a temp subdirectory. The source is still relatively clean, but compared with out-of-source, or not very cool:


    • The generated makefile is still under the source path
    • If a set of source code to use msvc2008, msvc2008, MinGW separately compiled and not interfere with each other?


Create a build directory and then downgrade the directory with the appropriate qmake, and point to the project file under the source code to


Qmake. /project-sources/project.pro


An example of myself:


Suppose the project is stored under huang/called XXX


Shadow Directory and Huang are located at the same level called Huangbuild


We want to establish xxx-debug and xxx-release in Huangbuild to mark the Debug and release of XXX.


We need to enter the Huangbuild directory, if it is debug into the debug directory, this time qmake. /.. /huang/xxx.pro


Release is similar to this


Useful variables


As mentioned earlier, Qmake's Shadow-build function is not yet complete.


Pwd

The directory where the file (. Pro or. pri) of the variable is used, notice the comparison to the next

_pro_file_pwd_

The directory where the pro file is located (note: Even if it is used within a PRI file, it also refers to the directory where the pro file contains it)

_pro_file_

Full path to Pro file

Out_pwd

The path where the generated makefile file is located, and the_pro_file_pwd_corresponds


When built with shadow build, Out_pwd and_pro_file_pwd_are the same, so that we can determine what constructs are used, and then take different actions:



!contains(_PRO_FILE_PWD_, $${OUT_PWD}) {
#do something when using shadow build
}
#It's better to use equals directly, but manual doesn't explain it (so I don't know if your qmake supports it, at least it will be supported after qt4.5)
!equals(_PRO_FILE_PWD_, OUT_PWD) {
#do something when using shadow build
}


For example, when using Out-of-source build, we may need to copy some files from the source directory to the build directory, when using CMake, this is easy to do, but in Qmake, it seems that the lack of a common way, a simple demo is as follows:


    • Note: All files to be copied can only be specified with a relative path (you can help to improve it, I did not find the appropriate function)
    • This code needs to be placed in the pro file, or within the PRI file of the same directory


FILES_COPY_SRC = $$SOURCES /
                 dbzhang800.txt /
                 images/abc.png /
                 i18n/abcd.qm

win32{
    COPY = copy /y
    MKDIR = mkdir
}else{
    COPY = cp
    MKDIR = mkdir -p
}
!equals(_PRO_FILE_PWD_, OUT_PWD) {
    for(f, FILES_COPY_SRC){
        dist_file = $$OUT_PWD/$$f
        dist = $$dirname(dist_file)
        win32:dist = $$replace(dist, /, //)
        !exists($$dist):system($$MKDIR $$dist)
        !exists($$dist_file):system($$COPY $$f $$dist)
    }
}


Or write a little explanation, it may be helpful to everyone, but also to prevent their long time will forget.


    • Under Windows, you must first replace the path separator with "/"
    • The destination directory does not exist and the directory is created.
    • The destination file does not exist, copy the file.
Some of my operations,


http://blog.csdn.net/ac_huang/article/details/23867443



Talking about the shadow build of Qmake (that is, separating the source path from the build path)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.