Search code examples
qtqmake

How to make a target depend on another target's QMAKE_EXTRA_COMPILERS


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?


Solution

  • 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