qt creator of all aspects of the source code analysis (3-5)

qtcreatorlibrary.pri

The previous section, we introduced src.pro, here take this opportunity to all project files in the src directory are introduced again. First is qtcreatorlibrary.pri.

Use Case

In order to analyze this document, we find examples of the use of the pri, the source directory \ src \ libs \ cplusplus \ cplusplus.pro

DEFINES += NDEBUG
unix:QMAKE_CXXFLAGS_DEBUG += -O2
win32:QMAKE_CXXFLAGS_DEBUG += -O2

include(../../qtcreatorlibrary.pri)
include(cplusplus-lib.pri)

And dependencies, the source directory \ src \ libs \ cplusplus \ cplusplus_dependencies.pri

QTC_LIB_NAME = CPlusPlus
QTC_LIB_DEPENDS += \
    utils
INCLUDEPATH *= $$IDE_SOURCE_TREE/src/libs/3rdparty

Here we can see, you set the library name QTC_LIB_NAME and dependent library name QTC_LIB_DEPENDS, will be used when it resolves dependencies in qtcreator.pri in.

Upper half

Below, we analyze qtcreatorlibrary.pri, here it is divided into two parts to introduce.

The upper half of the following

include($$replace(_PRO_FILE_PWD_, ([^/]+$), \\1/\\1_dependencies.pri))
TARGET = $$QTC_LIB_NAME

include(../qtcreator.pri)

# use precompiled header for libraries by default
isEmpty(PRECOMPILED_HEADER):PRECOMPILED_HEADER = $$PWD/shared/qtcreator_pch.h

win32 {
    DLLDESTDIR = $$IDE_APP_PATH
}

DESTDIR = $$IDE_LIBRARY_PATH

DLLDESTDIR

Note: This variable is only available for Windows goals.

To specify the target dll copy to the location.

Confiscation

Specify the placement of the target file.

E.g:

DESTDIR = ../../lib

Note: The list of supported character may depend on the build tool. In particular, the brackets do not apply to make tools.

  1. Obtains the corresponding pro file name according to the dependence file, comprising performed.

    _PRO_FILE_PWD_ pro file that contains the path to the folder where pri, ([^ /] + $) represents the path behind the last delimiter string, \ 1 reverse references, representative of the first matching the acquired references.

    Example: _PRO_FILE_PWD_ source directory / src / libs / cplusplus, comprising the source file directory /src/libs/cplusplus/cplusplus_dependencies.pri, a match for cplusplus.

  2. Set library file name.

    Example: CPlusPlus.

  3. Load qtcreator.pri.

    The specific content of the article to see qt creator of all aspects of the source code analysis (3-2) .

    Highlights at this, the first step to load the dependent files, set up QTC_LIB_DEPENDS, then qtcreator.pri will be dependent parse (utils library), and contain.

  4. Add precompiled headers.

    Example: source directory /src/shared/qtcreator_pch.h. Content is some common unified Qt header files.

  5. DLL set the destination folder.

    If win32 platform, and the goal is to generate dll, put the dll copied to IDE_APP_PATH, i.e. build directory / bin.

  6. Set the destination folder.

    The target generated output to IDE_LIBRARY_PATH, i.e. build directory / lib / qtcreator.

Lower half

The lower half of the following

osx {
    QMAKE_LFLAGS_SONAME = -Wl,-install_name,@rpath/Frameworks/
    QMAKE_LFLAGS += -compatibility_version $$QTCREATOR_COMPAT_VERSION
}
include(rpath.pri)

TARGET = $$qtLibraryTargetName($$TARGET)

TEMPLATE = lib
CONFIG += shared dll

contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols

win32 {
    dlltarget.path = $$INSTALL_BIN_PATH
    INSTALLS += dlltarget
} else {
    target.path = $$INSTALL_LIBRARY_PATH
    INSTALLS += target
}
  1. osx settings and rpath.pri, set compiler options slightly.

  2. Set the output destination file name.

    Here called qtLibraryTargetName () function qtcreator.pri defined, in fact, add character d in debug mode, to distinguish release mode. Function analysis, see qt creator of all aspects of the source code analysis (3-2) .

  3. Set the output type, as a shared library lib.

  4. Set hidden export symbols option.

  5. Set the installation path.

result

In the build directory, we find the library compiled obtained in two places and DLLDESTDIR DESTDIR specified.

image-20200303205410364

We include in cplusplus.pro qtcreatorlibrary.pri, loaded cplusplus_dependencies.pri in pri then load qtcreator.pri, and in which the resolution of dependencies, the final load utils_dependencies.pri, project directory schema results are as follows.

image-20200303205704054


原创造福大家,共享改变世界

献出一片爱心,温暖作者心灵


Guess you like

Origin www.cnblogs.com/codeForFamily/p/qt-creator-ide-source-learn-3-5.html