programing

QMake .pro 파일에서 다른 디버그 / 릴리스 출력 디렉토리를 지정하는 방법

nasanasas 2020. 8. 14. 07:50
반응형

QMake .pro 파일에서 다른 디버그 / 릴리스 출력 디렉토리를 지정하는 방법


Qt 프로젝트가 있고 소스 트리 외부에 컴파일 파일을 출력하고 싶습니다.

현재 다음과 같은 디렉토리 구조가 있습니다.

/
|_/build
|_/mylib
  |_/include
  |_/src
  |_/resources

구성 (디버그 / 릴리스)에 따라 빌드 / 디버그 또는 빌드 / 릴리스 디렉토리 아래의 빌드 디렉토리에 결과 파일을 출력하고 싶습니다.

.pro 파일을 사용하여 어떻게 할 수 있습니까?


짧은 대답은 : 당신은하지 않습니다 .

빌드하려는 빌드 디렉토리에서 qmake다음을 실행해야합니다 make. 따라서 debug디렉토리에서 한 번 , 디렉토리에서 한 번 실행하십시오 release.

이것이 바로 프로젝트를 빌드하는 모든 사람이 작업을 기대하는 방식이며, Qt 자체가 빌드를 위해 설정되는 방식이며, Qt Creator가 .pro파일이 작동 할 것으로 예상하는 방식이기도합니다. 파일이 시작된 qmake다음 make대상이 선택한 구성을위한 빌드 폴더에 있습니다.

이러한 폴더를 만들고 그 안에 두 개 (또는 그 이상의) 빌드를 수행하려면 최상위 수준의 makefile이 필요합니다. 아마도 qmake를 통해 최상위 프로젝트 파일에서 생성 될 수 있습니다.

빌드 구성이 두 개 이상인 것은 드문 일이 아니므로 빌드와 릴리스를 구분하는 데 불필요하게 헌신하고 있습니다. 최적화 수준이 다른 빌드가있을 수 있습니다 . 디버그 / 릴리스 이분법은 편히 쉬는 것이 가장 좋습니다.


내 Qt 프로젝트의 경우 * .pro 파일에서이 체계를 사용합니다.

HEADERS += src/dialogs.h
SOURCES += src/main.cpp \
           src/dialogs.cpp

Release:DESTDIR = release
Release:OBJECTS_DIR = release/.obj
Release:MOC_DIR = release/.moc
Release:RCC_DIR = release/.rcc
Release:UI_DIR = release/.ui

Debug:DESTDIR = debug
Debug:OBJECTS_DIR = debug/.obj
Debug:MOC_DIR = debug/.moc
Debug:RCC_DIR = debug/.rcc
Debug:UI_DIR = debug/.ui

간단하지만 멋지다! :)


대상 dll / exe의 디렉토리를 변경하려면 pro 파일에서 다음을 사용하십시오.

CONFIG(debug, debug|release) {
    DESTDIR = build/debug
} else {
    DESTDIR = build/release
}

또한 객체 파일 및 moc 파일과 같은 다른 빌드 대상의 디렉토리를 변경할 수도 있습니다 ( 자세한 내용은 qmake 변수 참조 또는 qmake CONFIG () 함수 참조 ).


더 간결한 접근 방식이 있습니다.

release: DESTDIR = build/release
debug:   DESTDIR = build/debug

OBJECTS_DIR = $$DESTDIR/.obj
MOC_DIR = $$DESTDIR/.moc
RCC_DIR = $$DESTDIR/.qrc
UI_DIR = $$DESTDIR/.ui

이를 수행하는 올바른 방법은 다음과 같습니다 (QT 지원 팀에 감사드립니다).

CONFIG(debug, debug|release) {
    DESTDIR = build/debug
}
CONFIG(release, debug|release) {
    DESTDIR = build/release
}

OBJECTS_DIR = $$DESTDIR/.obj
MOC_DIR = $$DESTDIR/.moc
RCC_DIR = $$DESTDIR/.qrc
UI_DIR = $$DESTDIR/.u

추가 정보 : https://wiki.qt.io/Qt_project_org_faq#What_does_the_syntax_CONFIG.28debug.2Cdebug.7Crelease.29_mean_.3F_What_does_the_1st_argument_specify_and_similarly_what_is_the_2nd_.3F


나는 chalup이 제안한 것과 같은 방법을 사용합니다.

ParentDirectory = <your directory>

RCC_DIR = "$$ParentDirectory\Build\RCCFiles"
UI_DIR = "$$ParentDirectory\Build\UICFiles"
MOC_DIR = "$$ParentDirectory\Build\MOCFiles"
OBJECTS_DIR = "$$ParentDirectory\Build\ObjFiles"

CONFIG(debug, debug|release) { 
    DESTDIR = "$$ParentDirectory\debug"
}
CONFIG(release, debug|release) { 
    DESTDIR = "$$ParentDirectory\release"
}

Old question, but still worth an up-to-date answer. Today it's common to do what Qt Creator does when shadow builds are used (they are enabled by default when opening a new project).

For each different build target and type, the right qmake is run with right arguments in a different build directory. Then that is just built with simple make.

So, imaginary directory structure might look like this.

/
|_/build-mylib-qt5-mingw32-debug
|_/build-mylib-qt5-mingw32-release
|_/build-mylib-qt4-msvc2010-debug
|_/build-mylib-qt4-msvc2010-release
|_/build-mylib-qt5-arm-debug
|_/build-mylib-qt5-arm-release
|_/mylib
  |_/include
  |_/src
  |_/resources

And the improtant thing is, a qmake is run in the build directory:

cd build-mylib-XXXX
/path/to/right/qmake ../mylib/mylib.pro CONFIG+=buildtype ...

Then it generates makefiles in build directory, and then make will generate files under it too. There is no risk of different versions getting mixed up, as long as qmake is never run in the source directory (if it is, better clean it up well!).

And when done like this, the .pro file from currently accepted answer is even simpler:

HEADERS += src/dialogs.h
SOURCES += src/main.cpp \
           src/dialogs.cpp

It's also useful to have a slightly different name for the output executable. You can't use something like:

release: Target = ProgramName
debug: Target = ProgramName_d

Why it doesn't work is not clear, but it does not. But:

CONFIG(debug, debug|release) {
    TARGET = ProgramName
} else {
    TARGET = ProgramName_d
}

This does work as long as the CONFIG += line precedes it.


The new version of Qt Creator also has a "profile" build option between debug and release. Here's how I'm detecting that:

CONFIG(debug, debug|release) {  DEFINES += DEBUG_MODE }
else:CONFIG(force_debug_info) { DEFINES += PROFILE_MODE }
else {                          DEFINES += RELEASE_MODE }

참고URL : https://stackoverflow.com/questions/2580934/how-to-specify-different-debug-release-output-directories-in-qmake-pro-file

반응형