My project structure is currently this:
-project
|--apps
|--app1
|--test
|--libs
|--lib1_subdir
|--lib1_lib
|--lib1_test
|--test1
|--test2
|--lib1_examples
...
It works fine and dependencies are easily managed with simples
libs.pro
libs2.depends = lib1
libs1.pro
tests.depends = lib
is there a way to structure the project as follow keeping a clean dependencies structure?
-project
|--app
|--app1
|--lib
|--lib1
|--lib2
|--tests
|--test_lib1
|--test_lib2
|--test_lib3
|--examples
|--ex_lib1
|--ex_app1
...
subdir project can specify dependencies only for the same directory, cmake is not an option.
subdir project can specify dependencies only for the same directory
Of course, no. Simply use another level of indirection:
SUBDIRS = lib1 lib2 lib1_tests
lib1_tests.depends = lib1
lib1_tests.subdir = ../tests/test_lib1
# and so on
Related
I am creating a function in a .pri file that will be included in a .pro file with the intent of being able to do:
template(subdirs)
addMyProject(libA)
addMyProject(libB)
addMyProject(libC)
instead of
template(subdirs)
SUBDIRS += libA
libA.path = source/
SUBDIRS += libB
libB.path = source/
SUBDIRS += libC
libC.path = source/
Same problem if I want to use the depend keyword.
My current implementation is the following one:
defineTest(addMyProject) {
library_name = $$1
SUBDIRS += $$library_name
export(SUBDIRS)
{$$library_name}.file = {$$library_name}/source/{$$library_name}.pro
QMAKE_EXTRA_TARGETS += {$$library_name}
export(QMAKE_EXTRA_TARGETS)
}
The SUBDIRS part is ok. I have tried to make it work for the .file part in different ways, but still I have not found a solution.
Any hints?
[EDIT]
Each library contains different sub-projects, and the goal is to let Qt creator see only one of them (the one at the path source/libraryname.pro).
The issue is that all the libraries are correctly displayed, but also all the other sub-projects. Basically, only the SUBDIRS variable is recognised, but not the .file keyword)
OK, I have read existing answers about this question.
But no one is tolerable.
See how-to-copy-qt-runtime-dlls-to-project-output
But $$QMAKE_LIBDIR_QT doesn't contain any dll files. All dlls are located in the "bin" directory in qt installation. On the other hand, QMAKE_LIBDIR_QT refers to "lib" directory.
So, this method doesn't work.
Do anybody have a working method of doing this thing?
I do
QMAKE_DLLDIR_QT = $$QMAKE_LIBDIR_QT/../bin
but since 5.0 they no longer define QMAKE_LIBDIR_QT
my quick solution is:
isEmpty(QMAKE_LIBDIR_QT) : {
SPLITED=$$section(QMAKESPEC, "/", 0, -3)
QMAKE_LIBDIR_QT = $$SPLITED/lib
}
but
https://bugreports.qt-project.org/browse/QTBUG-28901
suggest we should use other method
PS: LIBDIR contains static lirbaries used for linker
I have a .pro file which looks like:
SOURCES += myfolder/source1.cpp \
myfolder/source2.cpp
HEADERS += myfolder/header1.h\
myfolder/header2.h
FORMS += myfolder/form1.ui\
myfolder/form2.ui
And everything works great. However, if I try to use an asterisk to include all the files, i.e.:
SOURCES += myfolder/*.cpp
HEADERS += myfolder/*.h
FORMS += myfolder/*.ui
qmake throws a file-not-found-error:
WARNING: Failure to find: myfolder\*.cpp
[...]
:-1: error: No rule to make target `myfolder/*.cpp', needed by `release/source1.o'. Stop.
In both cases, Qt-Creator can find the files.
Is there a way to use the asterisk? It's annoying to type the files manually.
Thank you!
[EDIT: Qt 4.8.4, Windows 7, Qt-Creator 2.6.1. Sry for forgetting this thought it isnt needed.]
[EDIT: Found solution: http://qt-project.org/forums/viewthread/1127 . Thank you anyway!]
In qmake 3.0, at least, it's possible to use something like:
SOURCES = $$files(*.cpp, true)
HEADERS = $$files(*.h, true)
The true argument will cause the files function to recursively find all files matching the pattern given by the first argument.
At first, using asterisk is bad practice - despite that qmake allows it, QtCreator cannot edit such *.pro correctly on adding new, renaming or deleting file. So try to add new files with "New file" or "Add existing files" dialogs.
QMake has for loop and function $$files(directory_path: String). Also append files to SOURCES or HEADERS variable respectively.
Brief example, which adds all files, but not directories, to variable FILES (not affect build or project tree):
files = $$files($$PWD/src)
win32:files ~= s|\\\\|/|g
for(file, files):!exists($$file/*):FILES += $$file
If you want to check if file is *.cpp, try to use contains($$file, ".cpp").
files = $$files($$PWD/src)
win32:files ~= s|\\\\|/|g
for(file, files):!exists($$file/*):contains($$file, ".cpp"):SOURCES += $$file
My project has top-level directory proj with subdirectories runtime and test. Basically, test depends on runtime, but it's a little more complicated.
Expected behavior: If you modify a file in runtime, then make runtime, then make test, this should rebuild test.
Actual behavior: For test, you get "make: Nothing to be done for `first'."
Here are the relevant excerpts from the project files.
proj.pro:
test.depends = runtime
runtime.pro:
TEMPLATE = lib
CONFIG = no_link target_predeps staticlib
TARGET =
# Avoid building libruntime.a
QMAKE_AR_CMD = #true
QMAKE_RANLIB = #true
include(../proj.pri)
RUNTIME_SOURCES += \
foo.c
bar.c
proj.pri:
CLANG_RUNTIME_FLAGS = -emit-llvm
runtime.input = RUNTIME_SOURCES
runtime.output = lib${QMAKE_FILE_IN_BASE}.bc
runtime.commands = $$CLANG $$CLANG_RUNTIME_FLAGS -c ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
QMAKE_EXTRA_COMPILERS += runtime
In runtime's Makefile, there is a rule for target compiler_runtime_make_all that seems to correspond to the QMAKE_EXTRA_COMPILERS. The files built by this rule (foo.bc and bar.bc) are in the OBJECTS list, so they get built when you make this Makefile.
In test's Makefile, there is also a rule for target compiler_runtime_make_all, but it has no recipe and it's not referred to anywhere.
So how do I tell test that it should depend on the QMAKE_EXTRA_COMPILERS for runtime?
In the top-level proj.pro (which I assume is TEMPLATE = subdirs), specifying that test depends on runtime only affects the order in which the top-level make is run on the specified SUBDIRS. It does not introduce any additional dependencies in any of the subdirectories — those are all totally independent invocations of qmake and make.
So, to solve this, you'll need to have test.pro indicate the specific runtime files it depends on. See the POST_TARGETDEPS variable.
Or if you're using QMAKE_EXTRA_COMPILERS to build the sources in test.pro, you could add something like this:
test.depends = $${ROOT}/runtime/lib*.bc
Absolute paths are ridiculous. All we need - and all we are allowed, by the way - is to use a folder on the same level that the folder containing .pro file for shadow builds. There are bugs otherwise.
But you can't just specify ../mingw_debug for example. Yes, it is a relative path but relative to what? It turns out it is relative to current directory of Qt Creator, and this is completely meaningless.
%{sourceDir} is of no help either. %{sourceDir}/../mingw_debug dosen't work, at least on Windows. If there was a way to extract parent folder from sourceDir!
Does anybody know a way to solve the issue?
In Qt Creator 3.6.1 at least, this is fixed - relative paths work just fine. The resolved full path is shown in the tooltip. I don't know when in the past few years this was fixed.
Not exactly shadow builds as qt-creator defines them but I am using the following to get a neat build structure.
Excerpt from a pro-file for a library that I build for multiple targets and also
in test modes.
TARGET = ../lib/common
message("libcommon:")
contains(CONFIG,test){
message("Building Test")
DESTDIR = test
TARGET = $$TARGET-test
}else{
message("Building Program")
DESTDIR = program
TARGET = $$TARGET
}
contains(MEEGO_EDITION,harmattan){
message("Maemo Harmattan")
DESTDIR = $$DESTDIR-maemo6
TARGET = $$TARGET-maemo6
DEFINES += MAEMO MAEMO6
}
unix:!maemo5:!contains(MEEGO_EDITION,harmattan){#desktop
message("Desktop")
DESTDIR = $$DESTDIR-desktop
TARGET = $$TARGET-desktop
}
contains(CONFIG,test){
TEMPLATE = app
SOURCES += $$files(src_test/main.cpp)
HEADERS += $$files(src_test/*.h)
INCLUDEPATH += src_test
}else{
TEMPLATE = lib
CONFIG += staticlib
}
CONFIG(debug, debug|release) {
message("Debug")
DESTDIR = $$DESTDIR-debug
CONFIG += debug
DEFINES += DEBUG
TARGET = $$TARGET-debug
}else{
message("Release")
//DEFINES += QT_NO_DEBUG_OUTPUT
DESTDIR = $$DESTDIR-release
TARGET = $$TARGET-release
}
MOC_DIR = build/$${DESTDIR}/moc
OBJECTS_DIR = build/$${DESTDIR}/obj
UI_DIR = build/$${DESTDIR}/ui
So you get all your object,moc,gui files in separate directories (e.g libcommon/build/program-desktop-debug/moc) and your binaries in the same with different names. To trigger one build or another you simply set a CONFIG+= in the build target. And the best about it this structure only depends on the pro file and you can put parts of it in a common.pri and use it for all your projects. No need for shadow-build configuration anymore. By the way the pro file resides in libcommon/libcommon.pro as it should.
I'm using this code in *.pro file, it seems working fine.
CONFIG(debug, debug|release){
DESTDIR=$$shadowed($$ROOT_PWD)/debug
}else{
DESTDIR=$$shadowed($$ROOT_PWD)/release
}
There are several things that can be used to make this manageable:
$$_PRO_FILE_PWD_ (version >=4.5) variable contains the directory of the current pro file being read.
Use the .qmake.cache file in the root directory of the project, and define a variable for the directory:
PROJECT_DIR = $$PWD
Then use that to navigate around beginning from the root.