Qbs, How can .h.in files be configured on Windows?

171 Views Asked by At

I have a C/C++ project that was written to be configured with CMake. I'm trying to learn Qbs by converting it to use Qbs. It happen there are .h.in files that in CMake are configured using the configure_file() function. For example in CMake a file named bson-version.h.in is converted to bson-version.h using the below code.

configure_file (
   "${SOURCE_DIR}/src/bson/bson-version.h.in"
   "${PROJECT_BINARY_DIR}/src/bson/bson-version.h"
)

How can this be achieved in Qbs? I'm on Windows 10 x64.

1

There are 1 best solutions below

0
On BEST ANSWER

There is no built-in functionality for this. You can easily implement it yourself, though. Here's a sketch (untested):

Product {
    // ...
    Group {
        files: ["src/bson/bson-version.h.in"]
        fileTags: ["header.in"]
    }
    // ...
    cpp.includePaths: [buildDirectory + "/generated_headers"]
    Rule {
        inputs: ["header.in"]
        Artifact {
            filePath: "generated_headers/bson-version.h"
            fileTags: ["hpp"]
        }
        prepare: {
            // Create JavaScriptCommand and do the replacements
            // via qbs.TextFile. 
        }
    }
}

Of course, if the .in file refers to cmake variables, you will have to define equivalent qbs properties in your project and consider them in the rule.