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

qmake: create folder if not exist from inside makefile



  • Hi all

    Using Qt Creator I need to generate a makefile with instruction to create a folder if not exist before start compile. I added this line to the .pro file:

    createdir.commands = $(CHK_DIR_EXISTS) $$shell_path(path/of/dir) & $(MKDIR) $$shell_path(path/of/dir)
    

    My problem is that this line work as expencted if compilation is executed on Windows (cause the label CHK_DIR_EXISTS is replaced by "if not exist") but doesn't work if compiled on Linux (in this case the label is replaced with "test -d"). The test tool return an error about an incorrect params. I tried to remove the CHK_DIR_EXISTS condition and, basically, leave the command to create folder only. This work on Linux but return error on Windows cause the mkdir command return error in case the folder already exist and this error stop the compilation.

    Someone can suggest an "universal" metod to create a folder from inside makefile? Please note I can not use the qmake command exist() cause it is executed only the fist time in the phase of makefile creation and not during each compilation.

    Thank you



  • @Suppaman

    I do not know enough about the linux specialities. However, you could use possibly a work-around

    win32:createdir.commands = $(CHK_DIR_EXISTS) $$shell_path(path/of/dir) & $(MKDIR) $$shell_path(path/of/dir)
    linux:createdir.commands = $$shell_path(path/of/dir) & $(MKDIR) $$shell_path(path/of/dir)
    

    Check it out and I hope it helps



  • Hi

    At first thank you for your reply. Unfortunately qmake tags win32: and linux: are connected to the target platform to compile for not to the OS used to compile. For make an example in case you are compiling under Linux (Qt Creator is installed on Linux) and want to crosscompile a project for Windows platform, in this case the tag win32: make sense and will be taken in consideration.



  • @Suppaman

    You need to check out the different qmake test function then e.g. https://doc.qt.io/qt-5/qmake-test-function-reference.html#mkpath-dirpath



  • This set of function are part of qmake and are invoked only when qmake generate the makefile the first time that is an operation that happen only once during first time project configuration. If, for some reasons, the folder I'm interested in is removed using this way it will not be recreated and compilation return error. On the contrary insert this step in the makefile the folder will be recreated before each compilation start, this is the reason I need this step to be executed by the makefile.



  • If someone is interested found a solution:

    equals(QMAKE_HOST.os, Windows) {
    .....
    } else {
    .....
    }
    

Log in to reply