Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QMake project dependencies not detecting changes in static libs

QMake project dependencies not detecting changes in static libs

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
18 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    If memory serves well, it should be PRE_TARGETDEPS that you are looking for.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • alik_coA Offline
      alik_coA Offline
      alik_co
      wrote on last edited by
      #3

      PRE_TARGETDEPS is not helping so far. With project files shown below, even with "rebuild" of MyDll, MyStaticLib doesn't get built. And with any source changes in MyStaticLib, MyDll doesn't get rebuilt either. Here is what I have:

      **.\MyStaticLib\MyStaticLib.pro**
      TARGET = MyStaticLib
      TEMPLATE = lib
      CONFIG += staticlib
      CONFIG -= qt
      SOURCES += ...
      HEADERS += ...
      
      **.\MyDll\MyDll.pro**
      TARGET = MyDll
      TEMPLATE = lib
      CONFIG -= qt
      INCLUDEPATH += ../MyStaticLib
      SOURCES += ...
      HEADERS += ...
      PRE_TARGETDEPS += ../MyStaticLib
      LIBS += -lMyStaticLib
      
      

      Is there something I'm not doing right?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        If memory serves well, you need to list the actual library not the project.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • alik_coA Offline
          alik_coA Offline
          alik_co
          wrote on last edited by alik_co
          #5

          No luck with this experiment either. Building MyDll doesn't trigger building MyStaticLib, and I'm getting "dependent D:\ROOT\output\bin\x64\Debug\MyStaticLib.lib does not exist". But if I build MyStaticLib explicitly, then MyDll builds OK.
          BTW, adding TARGET.depends makes no difference either.
          Note that I'm placing all generated files (objs, libs, bins) outside of the source tree. Is there a chance that qmake dependency tracking system assumes default locations for the generated files?

          **.\MyStaticLib\MyStaticLib.pro**
          TARGET = MyStaticLib
          TEMPLATE = lib
          CONFIG += staticlib
          CONFIG -= qt
          SOURCES += ...
          HEADERS += ...
          
          **.\MyDll\MyDll.pro**
          TARGET = MyDll
          TEMPLATE = lib
          CONFIG -= qt
          INCLUDEPATH += ../MyStaticLib
          SOURCES += ...
          HEADERS += ...
          PRE_TARGETDEPS += D:\ROOT\output\bin\x64\Debug\MyStaticLib.lib
          TARGET.depends += ../MyStaticLib
          LIBS += -lMyStaticLib
          
          SGaistS 1 Reply Last reply
          0
          • alik_coA alik_co

            No luck with this experiment either. Building MyDll doesn't trigger building MyStaticLib, and I'm getting "dependent D:\ROOT\output\bin\x64\Debug\MyStaticLib.lib does not exist". But if I build MyStaticLib explicitly, then MyDll builds OK.
            BTW, adding TARGET.depends makes no difference either.
            Note that I'm placing all generated files (objs, libs, bins) outside of the source tree. Is there a chance that qmake dependency tracking system assumes default locations for the generated files?

            **.\MyStaticLib\MyStaticLib.pro**
            TARGET = MyStaticLib
            TEMPLATE = lib
            CONFIG += staticlib
            CONFIG -= qt
            SOURCES += ...
            HEADERS += ...
            
            **.\MyDll\MyDll.pro**
            TARGET = MyDll
            TEMPLATE = lib
            CONFIG -= qt
            INCLUDEPATH += ../MyStaticLib
            SOURCES += ...
            HEADERS += ...
            PRE_TARGETDEPS += D:\ROOT\output\bin\x64\Debug\MyStaticLib.lib
            TARGET.depends += ../MyStaticLib
            LIBS += -lMyStaticLib
            
            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            There's no reason for the build of MyDLL to trigger other builds unless you are using a SUBDIRS project where you explicitly state the dependencies between projects.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • alik_coA Offline
              alik_coA Offline
              alik_co
              wrote on last edited by alik_co
              #7

              Thanks! Full list of dependencies in the top level project did enable changes detection in the static library.

              ** MyProject.pro **
              TEMPLATE = subdirs
              SUBDIRS += MyStaticLib \
                         MyDLL       \
                         MyApp
              MyDLL.depends = MyStaticLib
              MyApp.depends = MyDLL
              

              One problem remains: how to get full path to the static lib binary when we have only project name. I have $${DESTDIR}, but I don't know how to get output file name (MyStaticLib.lib vs libMyStaticLib.a)

              BTW, inability to get full path to the TARGET output file is a big issue for writing QMAKE_POST_LINK. I'm using workaround by manually adding "lib" prefix and file extension depending on platform, but this is definitely a limitation.

              Thanks again,

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mchinand
                wrote on last edited by
                #8

                I find the dependency handling between sub-projects better/easier with CMake over qmake's .pro projects.

                alik_coA 1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  The OUT_PWD variable allows you to get the path to where you will find the build artifacts.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • alik_coA Offline
                    alik_coA Offline
                    alik_co
                    wrote on last edited by alik_co
                    #10

                    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?

                    1 Reply Last reply
                    0
                    • M mchinand

                      I find the dependency handling between sub-projects better/easier with CMake over qmake's .pro projects.

                      alik_coA Offline
                      alik_coA Offline
                      alik_co
                      wrote on last edited by
                      #11

                      @mchinand Transition to CMake is in future plans. Right now we need to deal with QMake.

                      1 Reply Last reply
                      1
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        If memory serves well, you can use qtLibraryTarget(your_library_name)

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • alik_coA Offline
                          alik_coA Offline
                          alik_co
                          wrote on last edited by alik_co
                          #13

                          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
                          
                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            Do you have the same result with Qt 5 ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • alik_coA Offline
                              alik_coA Offline
                              alik_co
                              wrote on last edited by
                              #15

                              I don't have Qt5 installed anymore. And frankly, it's irrelevant - we're not moving the project back to Qt5 just for this.

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mchinand
                                wrote on last edited by mchinand
                                #16

                                Have you tried using QMAKE_EXTENSION_SHLIB and QMAKE_EXTENSION_STATICLIB?

                                alik_coA 1 Reply Last reply
                                0
                                • M mchinand

                                  Have you tried using QMAKE_EXTENSION_SHLIB and QMAKE_EXTENSION_STATICLIB?

                                  alik_coA Offline
                                  alik_coA Offline
                                  alik_co
                                  wrote on last edited by
                                  #17

                                  @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.

                                  1 Reply Last reply
                                  0
                                  • alik_coA Offline
                                    alik_coA Offline
                                    alik_co
                                    wrote on last edited by
                                    #18

                                    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
                                    
                                    
                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved