Important: Please read the Qt Code of Conduct -

Multiple conditionals in QMake pro file

  • I have this code that copies additional folders from my build directory to the output:

        copydata.commands += mkdir -p $$OUT_PWD/dir1 ;
        copydata.commands += mkdir -p $$OUT_PWD/dir2 ;
        copydata.commands += echo "Copying additional files..." ;
        copydata.commands += $(COPY_DIR) $$PWD/dir1/* $$OUT_PWD/dir2/ ;
        copydata.commands += $(COPY_DIR) $$PWD/dir1/* $$OUT_PWD/dir2/ ;
        first.depends = $(first) copydata
        QMAKE_EXTRA_TARGETS += first copydata

    I only want this to run if dir1 OR dir2 don't exist OR are empty as they take time to copy on every compile. I've tried every combination of this condition (along with isEmpty) to no avail:

    !exists( $$OUT_PWD/dir1 ) || !exists( $$OUT_PWD/dir2 ){

    What's the proper syntax to combine conditions or is that not allowed? Just wondering what the best way to do this is ... I know I can always hack it to work by nesting these conditions or using an extra variable but it should work just with the built in isEmpty() and exists() functions. Thanks.

  • Qt Champions 2017

  • @kshegunov

    I've tried every variation of the conditionals with the pipe operator as well.

    !exists( $$OUT_PWD/dir1 ) | !exists( $$OUT_PWD/dir2 )
    !exists(( $$OUT_PWD/dir1 ) | !exists( $$OUT_PWD/dir2 ))
    !exists(( $$OUT_PWD/dir1 ) | ( $$OUT_PWD/dir2 ))

    None of these work the way it's supposed to. It will ALWAYS copy the files over. Any suggestions?

  • Qt Champions 2017

    if(!exists( $$OUT_PWD/dir1 )|!exists( $$OUT_PWD/dir2 )) {
        // ...

    I got this directly from the qmake manual, by the way.

  • @kshegunov

    I've tried that too ... but I see what I'm doing wrong. I guess you have to manually run qmake every time you delete the folder to test it or else it won't update the condition. I just kept rebuilding it, which didn't work. Thanks. Guess one of my previous conditions would have worked for this as well.

Log in to reply