Solved QMake project dependencies not detecting changes in static libs
-
The OUT_PWD variable allows you to get the path to where you will find the build artifacts.
-
There is no problem with the output directory, the problem is with the file name.
Project MyStaticLib produces MyStaticLib.lib on Windows, and libMyStaticLib.a on Linux and Mac.
Project MyDLL produces MyDLL.dll on Windows, libMyDLL.so.1.0.0 on Linux, libMyDLL.1.0.0.dylib on Mac.
Is there a way to get these names without ugly workaround of manually adding prefix and extensions? -
@mchinand Transition to CMake is in future plans. Right now we need to deal with QMake.
-
If memory serves well, you can use
qtLibraryTarget(your_library_name)
-
qtLibraryTarget doesn't work for me as expected (in Qt 6.3)
**.\MyStaticLib\MyStaticLib.pro** TARGET = MyStaticLib TEMPLATE = lib CONFIG += staticlib CONFIG -= qt SOURCES += ... HEADERS += ... message($$qtLibraryTarget($$TARGET))
While running qmake, I'm getting (on Windows)
Project MESSAGE: MyStaticLib Project MESSAGE: MyStaticLibd Project MESSAGE: MyStaticLib
-
Do you have the same result with Qt 5 ?
-
I don't have Qt5 installed anymore. And frankly, it's irrelevant - we're not moving the project back to Qt5 just for this.
-
Have you tried using QMAKE_EXTENSION_SHLIB and QMAKE_EXTENSION_STATICLIB?
-
@mchinand QMAKE_EXTENSION_STATICLIB could help, but it's defined only in context of MyStaticLib project, while I need it in context of another project that references MyStaticLib through PRE_TARGETDEPS.
Is there any way to export a variable from a project and make it visible on SUBDIRS level? export(variable) didn't work for me.
QMAKE_EXTENSION_SHLIB is less useful since in returns "so" and "dylib", while actual extensions are ".so.1.0.0" and ".1.0.0.dylib". So you still have to have platform specific hacks, which diminishes the whole purpose of this variable. -
Thanks @SGaist and @mchinand for the detailed discussion, let's wrap this up.
Summary
- PRE_TARGETDEPS helps detect changes in static libraries.
- QMake implements MyModule .depends, but it's missing MyModule. target_full_path which makes it inconvenient to use PRE_TARGETDEPS, and especially QMAKE_POST_LINK. Some platform specific hacks are necessary.
Working solution
Here is an example of a complete solution which detects source changes in all modules, including static libraries. The solution uses a project wide hack, which is not that bad after all.=== ./.qmake.conf === # # QMake will find .qmake.conf automatically. # PROJECT_ROOT = $$PWD === ./static_libs.conf === # # Assumes DESTDIR is configured project-wide so all binaries are written to one place. # windows { MyStaticLib_FULL_PATH = $$shell_path($$DESTDIR/MyStaticLib.lib) # ... Other static libraries in the project } else { MyStaticLib_FULL_PATH = $$shell_path($$DESTDIR/libMyStaticLib.a) # ... Other static libraries in the project } === ./MyStaticLib/MyStaticLib.pro === TARGET = MyStaticLib TEMPLATE = lib CONFIG += staticlib SOURCES += ... HEADERS += ... === ./MySharedLib/MySharedLib.pro === TARGET = MySharedLib TEMPLATE = lib INCLUDEPATH += ../MyStaticLib SOURCES += ... HEADERS += ... win32:DEF_FILE = MySharedLib.def LIBS += -lMyStaticLib # # NOTE the below 2 lines. # include($$PROJECT_ROOT/static_libs.conf) PRE_TARGETDEPS += MyStaticLib_FULL_PATH === ./MyApp/MyApp.pro === TARGET = MyApp TEMPLATE = app INCLUDEPATH += ../MySharedLib SOURCES += ... HEADERS += ... LIBS += -lMySharedLib === ./MyProject.pro === TEMPLATE = subdirs SUBDIRS += MyStaticLib \ MySharedLib \ MyApp MySharedLib.depends = MyStaticLib MyApp.depends = MySharedLib