I wrote a C++ code generator program for code that provides access to Sql tables in QT. The generator takes a simple text file and produces a class header file (.h) and the class definition file (.cpp) pair. All the files are known to QT Creator in my project (and are under version control).
I want to have my code generator run when I change the input text file. I would then re-generate the .h and .cpp files corresponding to it. The build will then automatically compile the .cpp file when I build.
I don't know how to get my code generator into the QT Creator (cmake) build process. Can anyone help me?
I can run the process manually by selection each input text file and dropping it on the program. The is the capability to add a build step in QT Creator. I added my program as a "Custom Process Step", but it doesn't select each input text file, and use dependencies to decide to run or not.
A typical input text file look like this:
tablename=filepathtable,FP,dbt_filepath
filepath_id INTEGER PRIMARY KEY
drive_letter TEXT
file_path TEXT
full_path TEXT
The code generator creates a header file like this:
#ifndef DBT_FILEPATH_H
#define DBT_FILEPATH_H
// DO NOT EDIT THIS FILE! File was generated by dbtable_qt.ahk
#include "dbmanager.h"
#include <QString>
#include <QSqlQuery>
#include <QSqlError>
class Dbt_Filepath
{
public:
Dbt_Filepath(QSqlDatabase* p_db);
bool createFPTable();
bool insertFPTable();
bool queryFPTablePrimaryKey(int p_filepath_id);
void debugShowSqlQueryError(const QLatin1String& funcname,
QSqlQuery& query);
const QString getTableName();
// database table fields
int filepath_id;
QString drive_letter;
QString file_path;
QString full_path;
enum eFP_dbcol{
field_filepath_id=0,
field_drive_letter,
field_file_path,
field_full_path };
// private data and functions
private:
QSqlDatabase* m_db; // database
void fillFieldsFromQuery(QSqlQuery& query);
};
#endif // DBT_FILEPATH_H
and a .cpp file like this (partial shown):
// DO NOT EDIT THIS FILE! File was generated by dbtable_qt.ahk
#include <QDebug>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include "dbt_filepath.h"
Dbt_Filepath::Dbt_Filepath(QSqlDatabase* p_db)
: m_db(p_db)
{
}
const QString Dbt_Filepath::getTableName()
{
const QString tblnm = QLatin1String("filepathtable");
return tblnm;
}
bool Dbt_Filepath::createFPTable()
{
bool success = false;
const QLatin1String fname("DFP::createFPTable()");
qDebug() << fname;
QSqlQuery querycreate(*m_db);
QString sqlcreate = QLatin1String(
"CREATE TABLE filepathtable ("
"filepath_id INTEGER PRIMARY KEY,"
"drive_letter TEXT,"
"file_path TEXT,"
"full_path TEXT"
");" );
querycreate.prepare(sqlcreate);
if (querycreate.exec())
success = true;
else
debugShowSqlQueryError(fname, querycreate);
return success;
}
bool Dbt_Filepath::insertFPTable()
{
bool success = false;
const QLatin1String fname("DFP::insertFPTable()");
qDebug() << fname;
QSqlQuery queryinsert(*m_db);
QString sqlinsert = QLatin1String(
"INSERT INTO filepathtable ("
"drive_letter,"
"file_path,"
"full_path"
") VALUES(?,?,?);");
queryinsert.prepare(sqlinsert);
queryinsert.addBindValue(drive_letter.toUtf8());
...
What I want is for the build process to use the input text files as sources - prior to compiling anything - to re-generate the c++ files, if required. Then I want to normal build process to proceed to compile and link my code.