Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Proper way to make a cmake project (pri) dependent on another cmake project (pri)



  • I have 2 cmake projects that provide me with .a libs and headers when compiled. However, one is dependent on the other. I am struggling to make one see everything from the other. Here is what I have so far:
    open62541.pri:

    OPEN62541_SRC = $$PWD/open62541
    OPEN62541_BUILD = $$OBJECTS_DIR/open62541
    OPEN62541_OPTS = -DUA_ENABLE_ENCRYPTION=ON -DUA_ENABLE_HISTORIZING=ON
    OPEN62541_LIBS = $$PWD/$$OBJECTS_DIR/mbedtls/lib
    OPEN62541_INCLUDES = $$PWD/$$OBJECTS_DIR/mbedtls/include
    OPEN62541_MBEDTLS = $$PWD/$$OBJECTS_DIR/mbedtls
    MBETLS_PATHS = -DMBEDTLS_INCLUDE_DIRS=$$OPEN62541_INCLUDES -DMBEDCRYPTO_LIBRARY=$$OPEN62541_LIBS -DMBEDTLS_LIBRARY=$$OPEN62541_LIBS -DMBEDX509_LIBRARY=$$OPEN62541_LIBS
    open62541.target = $$OPEN62541_BUILD/lib/libopen62541.a
    open62541.commands  = mkdir -p $$OPEN62541_BUILD
    open62541.commands += && cd $$OPEN62541_BUILD
    #open62541.depends += mbedtls
    #contains(QMAKE_HOST.arch, arm.*):{
    message(QMAKESPEC $$QMAKESPEC)
    contains(QMAKESPEC, .*linux-arm.*) {
        message("arm gcc chosen")
        open62541.commands += && cmake -DCMAKE_PREFIX_PATH=$$[QT_INSTALL_LIBS]/cmake -DCMAKE_INSTALL_PREFIX=\$\$(pwd) -DCMAKE_INSTALL_LIBDIR=lib $$MBETLS_PATHS -DCMAKE_INCLUDE_PATH=$$OPEN62541_INCLUDES -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc $$OPEN62541_OPTS $$OPEN62541_SRC
    }else{
        message("x86 gcc chosen")
        open62541.commands += && cmake -DCMAKE_PREFIX_PATH=$$[QT_INSTALL_LIBS]/cmake -DCMAKE_INSTALL_PREFIX=\$\$(pwd) -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_LIBRARY_PATH=$$OPEN62541_LIBS -DCMAKE_INCLUDE_PATH=$$OPEN62541_INCLUDES -DQT_QMAKE_EXECUTABLE=\$(QMAKE) $$OPEN62541_OPTS $$OPEN62541_SRC
    }
    open62541.commands += && make install
    QMAKE_EXTRA_TARGETS += open62541
    
    PRE_TARGETDEPS += $$open62541.target
    INCLUDEPATH += $$OPEN62541_BUILD/include
    LIBS += -L$$OPEN62541_BUILD/lib -lopen62541
    
    QMAKE_DISTCLEAN += "$$OBJECTS_DIR/open62541" -r
    

    mbedtls.pri:

    MBEDTLS_SRC = $$PWD/mbedtls
    MBEDTLS_BUILD = $$OBJECTS_DIR/mbedtls
    mbedtls.target = $$MBEDTLS_BUILD/lib/libmbedtls.a
    mbedtls.commands  = mkdir -p $$MBEDTLS_BUILD
    mbedtls.commands += && cd $$MBEDTLS_BUILD
    contains(QMAKESPEC, .*linux-arm.*) {
        mbedtls.commands += && cmake -DCMAKE_PREFIX_PATH=$$[QT_INSTALL_LIBS]/cmake -DCMAKE_INSTALL_PREFIX=\$\$(pwd)  -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc $$MBEDTLS_OPTS $$MBEDTLS_SRC
    }else{
        mbedtls.commands += && cmake -DCMAKE_PREFIX_PATH=$$[QT_INSTALL_LIBS]/cmake -DCMAKE_INSTALL_PREFIX=\$\$(pwd) -DCMAKE_INSTALL_LIBDIR=lib -DQT_QMAKE_EXECUTABLE=\$(QMAKE) $$MBEDTLS_OPTS $$MBEDTLS_SRC
    }
    mbedtls.commands += && make install
    #mbedtls.commands += && make mbedtls
    QMAKE_EXTRA_TARGETS += mbedtls
    
    PRE_TARGETDEPS += $$mbedtls.target
    INCLUDEPATH += $$MBEDTLS_BUILD/include
    LIBS += -L$$MBEDTLS_BUILD/lib -lmbedcrypto -lmbedx509 -lmbedtls
    
    QMAKE_DISTCLEAN += "$$OBJECTS_DIR/mbedtls" -r
    

    I need to be able to compile these in a build directory. Which they do fine. The issue is open62541 is dependent upon mbedtls.pri.

    Edit:
    Ah crap. I think I may have just figured out how to do this! Use the proper sub project crap I used to include these in the main project... Nevermind on this statement. I have no clue what I am doing.



  • My paths were relative to a cd. This messed things up.


Log in to reply