On 08/09/16 14:34, Christian Kandeler wrote:
On 09/08/2016 02:03 PM, Bo Thorsen wrote:
Ok, go try it. Create a simple python or perl script that reads a file.
The file just has a single number N inside it. And based on N the script
outputs those files:

Here's the CMake version:

    cmake_minimum_required(VERSION 3.5.0)
    project(cmaketest)

    find_package(Qt5Core REQUIRED)

    execute_process(
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/generator.py --list ${CMAKE_CURRENT_BINARY_DIR}/genoutput 5
      OUTPUT_VARIABLE fileList
    )

    string(REPLACE "\n" ";" fileList ${fileList})

    add_custom_command(OUTPUT ${fileList}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generator.py ${CMAKE_CURRENT_BINARY_DIR}/genoutput 5
    )

    qt5_wrap_cpp(moc_files ${fileList})

    add_executable(servertest servertest.cpp ${fileList} ${moc_files})
    target_link_libraries(servertest Qt5::Core)
target_include_directories(servertest PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/genoutput)



However, it is cheating in the same way that the QBS version from Christian is cheating - it assumes '--list' exists:

In qbs:

     outputArtifacts: {
         var p = new Process();
         try {
             p.exec("path_to_script", ["--list", input.filePath]);
             var files = p.readStdout.split("\n");


Christian, can you create a version which does not require --list? As far as I understand, that is the point of the QBS dynamic build graph. I would like to make sure my understanding is correct. I've attached the generator and servertest.cpp if that helps.

Thanks,

--
Ableton AG, Schoenhauser Allee 6-7, 10119 Berlin, Germany
Management Board: Gerhard Behles, Jan Bohl
Chair of the Supervisory Board: Uwe Struck
Registered Office: Berlin, Amtsgericht Berlin-Charlottenburg, HRB 72838

#!/usr/bin/env python

import os, sys

if len(sys.argv) == 4 and sys.argv[1] == "--list":
    outPath = sys.argv[2]
    numFiles = int(sys.argv[3])

    print(os.path.join(outPath, "server.h"))

    for num in range(numFiles):
        print(os.path.join(outPath, "method%s.h" % num))

    sys.exit(0)

if len(sys.argv) == 3:
    outPath = sys.argv[1]
    numFiles = int(sys.argv[2])

    if not os.path.exists(outPath):
        os.makedirs(outPath)
else:
    print("Incorrect args. Use ./generator.py [--list] /path/to/output numFiles")

with open(os.path.join(outPath, "server.h"), "w") as serverFile:

    for num in range(numFiles):
        serverFile.write('#include "method%s.h"\n' % num)

    serverFile.write("""
class Server {
public:
""")

    for num in range(numFiles):
        serverFile.write('    Method%s* call%s() { return new Method%s; }\n' % (num, num, num))

    serverFile.write("""};

""")

for num in range(numFiles):
    with open(os.path.join(outPath, "method%s.h" % num), "w") as methodFile:
        methodFile.write("""
#include <QObject>

class Method%s : public QObject {
  Q_OBJECT
};
""" % num)
#include "server.h"

#include <QObject>
#include <QDebug>

int main(int argc, char** argv)
{
    Server server;
    auto m2 = server.call2();
    if (m2->metaObject()->className() == QStringLiteral("Method2")) {
        qDebug() << "PASS";
        return 0;
    }
    qDebug() << "FAIL";
    return 1;
}
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to