Skip to content

Commit f299039

Browse files
committed
compiles ok with QMetaObject installation
1 parent 7f7e0ca commit f299039

33 files changed

+8957
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

CMakeLists.txt

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cmake_minimum_required(VERSION 3.0.0)
2+
project(mcc VERSION 0.1.0 LANGUAGES C CXX)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
6+
7+
add_executable(mcc main.cpp
8+
collectjson.cpp
9+
generator.cpp
10+
moc.cpp
11+
parser.cpp
12+
preprocessor.cpp)
13+
14+
target_compile_definitions(${PROJECT_NAME} PUBLIC
15+
QT_USE_QSTRINGBUILDER #for QStringBuilder operator%
16+
UNICODE
17+
)
18+
19+
find_package(QMetaClass REQUIRED)
20+
target_link_libraries(${PROJECT_NAME} QMetaClass::QMetaClass)
21+
get_target_property(QMetaClass_LIBRARY_DLL QMetaClass::QMetaClass LOCATION)
22+
message(STATUS "Path to the library's DLL file: ${QMetaClass_LIBRARY_DLL}")
23+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
24+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
25+
${QMetaClass_LIBRARY_DLL}
26+
$<TARGET_FILE_DIR:mcc>
27+
)
28+
29+
target_include_directories(${PROJECT_NAME} #private header files
30+
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>"
31+
)
32+
33+
include(CTest)
34+
enable_testing()
35+
36+
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
37+
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
38+
include(CPack)

CTestTestfile.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# CMake generated Testfile for
2+
# Source directory: D:/github/qtbase-everywhere-src-6.5.1/src/tools/moc
3+
# Build directory: D:/github/qtbase-everywhere-src-6.5.1/src/tools/moc
4+
#
5+
# This file includes the relevant testing commands required for
6+
# testing this directory and lists subdirectories to be tested as well.

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# mcc
22
Meta Class Compiler, a modified version of Qt's Meta-Object Compiler (moc)
3+
4+
5+
6+
cmake .. -DCMAKE_PREFIX_PATH=D:\testcode\installtest
7+
8+
cmake --build .

cbordevice.h

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (C) 2018 Intel Corporation.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3+
4+
#ifndef CBORDEVICE_H
5+
#define CBORDEVICE_H
6+
7+
#include <memory>
8+
#include <stdio.h>
9+
10+
#define CBOR_API inline
11+
#define CBOR_PRIVATE_API inline
12+
#define CBOR_NO_PARSER_API 1
13+
#include <3rdparty/tinycbor/src/cbor.h>
14+
15+
16+
class CborDevice
17+
{
18+
public:
19+
CborDevice(FILE *out) : out(out) {}
20+
21+
void nextItem(const char *comment = nullptr)
22+
{
23+
i = 0;
24+
if (comment)
25+
fprintf(out, "\n // %s", comment);
26+
}
27+
28+
static CborError callback(void *self, const void *ptr, size_t len, CborEncoderAppendType t)
29+
{
30+
auto that = static_cast<CborDevice *>(self);
31+
auto data = static_cast<const char *>(ptr);
32+
if (t == CborEncoderAppendCborData) {
33+
while (len--)
34+
that->putByte(*data++);
35+
} else {
36+
while (len--)
37+
that->putChar(*data++);
38+
}
39+
return CborNoError;
40+
}
41+
42+
private:
43+
FILE *out;
44+
int i = 0;
45+
46+
void putNewline()
47+
{
48+
if ((i++ % 8) == 0)
49+
fputs("\n ", out);
50+
}
51+
52+
void putByte(uint8_t c)
53+
{
54+
putNewline();
55+
fprintf(out, " 0x%02x, ", c);
56+
}
57+
58+
void putChar(char c)
59+
{
60+
putNewline();
61+
if (uchar(c) < 0x20)
62+
fprintf(out, " '\\x%x',", uint8_t(c));
63+
else if (uchar(c) >= 0x7f)
64+
fprintf(out, " uchar('\\x%x'),", uint8_t(c));
65+
else if (c == '\'' || c == '\\')
66+
fprintf(out, " '\\%c',", c);
67+
else
68+
fprintf(out, " '%c', ", c);
69+
}
70+
};
71+
72+
#endif // CBORDEVICE_H

cmake_install.cmake

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Install script for directory: D:/github/qtbase-everywhere-src-6.5.1/src/tools/moc
2+
3+
# Set the install prefix
4+
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
5+
set(CMAKE_INSTALL_PREFIX "D:/qtbuild")
6+
endif()
7+
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
8+
9+
# Set the install configuration name.
10+
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
11+
if(BUILD_TYPE)
12+
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
13+
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
14+
else()
15+
set(CMAKE_INSTALL_CONFIG_NAME "Debug")
16+
endif()
17+
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
18+
endif()
19+
20+
# Set the component getting installed.
21+
if(NOT CMAKE_INSTALL_COMPONENT)
22+
if(COMPONENT)
23+
message(STATUS "Install component: \"${COMPONENT}\"")
24+
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
25+
else()
26+
set(CMAKE_INSTALL_COMPONENT)
27+
endif()
28+
endif()
29+
30+
# Is this installation the result of a crosscompile?
31+
if(NOT DEFINED CMAKE_CROSSCOMPILING)
32+
set(CMAKE_CROSSCOMPILING "FALSE")
33+
endif()
34+
35+
# Set default install directory permissions.
36+
if(NOT DEFINED CMAKE_OBJDUMP)
37+
set(CMAKE_OBJDUMP "CMAKE_OBJDUMP-NOTFOUND")
38+
endif()
39+
40+
if(CMAKE_INSTALL_COMPONENT STREQUAL "Unspecified" OR NOT CMAKE_INSTALL_COMPONENT)
41+
if(CMAKE_INSTALL_CONFIG_NAME MATCHES "^([Dd][Ee][Bb][Uu][Gg])$")
42+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" TYPE EXECUTABLE FILES "D:/github/qtbase-everywhere-src-6.5.1/bin/moc.exe")
43+
endif(CMAKE_INSTALL_CONFIG_NAME MATCHES "^([Dd][Ee][Bb][Uu][Gg])$")
44+
endif()
45+
46+
if(CMAKE_INSTALL_COMPONENT STREQUAL "Unspecified" OR NOT CMAKE_INSTALL_COMPONENT)
47+
if(CMAKE_INSTALL_CONFIG_NAME MATCHES "^([Dd][Ee][Bb][Uu][Gg])$")
48+
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" TYPE FILE OPTIONAL FILES "D:/github/qtbase-everywhere-src-6.5.1/bin/moc.pdb")
49+
endif(CMAKE_INSTALL_CONFIG_NAME MATCHES "^([Dd][Ee][Bb][Uu][Gg])$")
50+
endif()
51+

collectjson.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (C) 2018 The Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3+
4+
#include <io/qfile.h>
5+
#include <serialization/qjsonarray.h>
6+
#include <serialization/qjsondocument.h>
7+
#include <serialization/qjsonobject.h>
8+
#include <tools/qhashfunctions.h>
9+
#include <text/qstringlist.h>
10+
#include <cstdlib>
11+
12+
static bool readFromDevice(QIODevice *device, QJsonArray *allMetaObjects)
13+
{
14+
const QByteArray contents = device->readAll();
15+
if (contents.isEmpty())
16+
return true;
17+
18+
QJsonParseError error {};
19+
QJsonDocument metaObjects = QJsonDocument::fromJson(contents, &error);
20+
if (error.error != QJsonParseError::NoError) {
21+
fprintf(stderr, "%s at %d\n", error.errorString().toUtf8().constData(), error.offset);
22+
return false;
23+
}
24+
25+
allMetaObjects->append(metaObjects.object());
26+
return true;
27+
}
28+
29+
int collectJson(const QStringList &jsonFiles, const QString &outputFile, bool skipStdIn)
30+
{
31+
QHashSeed::setDeterministicGlobalSeed();
32+
33+
QFile output;
34+
if (outputFile.isEmpty()) {
35+
if (!output.open(stdout, QIODevice::WriteOnly)) {
36+
fprintf(stderr, "Error opening stdout for writing\n");
37+
return EXIT_FAILURE;
38+
}
39+
} else {
40+
output.setFileName(outputFile);
41+
if (!output.open(QIODevice::WriteOnly)) {
42+
fprintf(stderr, "Error opening %s for writing\n", qPrintable(outputFile));
43+
return EXIT_FAILURE;
44+
}
45+
}
46+
47+
QJsonArray allMetaObjects;
48+
if (jsonFiles.isEmpty() && !skipStdIn) {
49+
QFile f;
50+
if (!f.open(stdin, QIODevice::ReadOnly)) {
51+
fprintf(stderr, "Error opening stdin for reading\n");
52+
return EXIT_FAILURE;
53+
}
54+
55+
if (!readFromDevice(&f, &allMetaObjects)) {
56+
fprintf(stderr, "Error parsing data from stdin\n");
57+
return EXIT_FAILURE;
58+
}
59+
}
60+
61+
QStringList jsonFilesSorted = jsonFiles;
62+
jsonFilesSorted.sort();
63+
for (const QString &jsonFile : std::as_const(jsonFilesSorted)) {
64+
QFile f(jsonFile);
65+
if (!f.open(QIODevice::ReadOnly)) {
66+
fprintf(stderr, "Error opening %s for reading\n", qPrintable(jsonFile));
67+
return EXIT_FAILURE;
68+
}
69+
70+
if (!readFromDevice(&f, &allMetaObjects)) {
71+
fprintf(stderr, "Error parsing %s\n", qPrintable(jsonFile));
72+
return EXIT_FAILURE;
73+
}
74+
}
75+
76+
QJsonDocument doc(allMetaObjects);
77+
output.write(doc.toJson());
78+
79+
return EXIT_SUCCESS;
80+
}

collectjson.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (C) 2019 The Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3+
4+
#ifndef COLLECTJSON_H
5+
#define COLLECTJSON_H
6+
7+
#include <global/qglobal.h>
8+
#include <text/qstring.h>
9+
#include <text/qstringlist.h>
10+
11+
QT_BEGIN_NAMESPACE
12+
13+
int collectJson(const QStringList &jsonFiles, const QString &outputFile, bool skipStdIn);
14+
15+
QT_END_NAMESPACE
16+
17+
#endif // COLLECTOJSON_H

depfile_shared.h

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) 2021 The Qt Company Ltd.
2+
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3+
4+
#ifndef QTBASE_DEPFILE_SHARED_H
5+
#define QTBASE_DEPFILE_SHARED_H
6+
7+
#include <qobject.hpp> //from QMetaClass
8+
#include <io/qfile.h>
9+
10+
// Escape characters in given path. Dependency paths are Make-style, not NMake/Jom style.
11+
// The paths can also be consumed by Ninja.
12+
// "$" replaced by "$$"
13+
// "#" replaced by "\#"
14+
// " " replaced by "\ "
15+
// "\#" replaced by "\\#"
16+
// "\ " replaced by "\\\ "
17+
//
18+
// The escape rules are according to what clang / llvm escapes when generating a Make-style
19+
// dependency file.
20+
// Is a template function, because input param can be either a QString or a QByteArray.
21+
template <typename T> struct CharType;
22+
template <> struct CharType<QString> { using type = QLatin1Char; };
23+
template <> struct CharType<QByteArray> { using type = char; };
24+
template <typename StringType>
25+
StringType escapeDependencyPath(const StringType &path)
26+
{
27+
using CT = typename CharType<StringType>::type;
28+
StringType escapedPath;
29+
int size = path.size();
30+
escapedPath.reserve(size);
31+
for (int i = 0; i < size; ++i) {
32+
if (path[i] == CT('$')) {
33+
escapedPath.append(CT('$'));
34+
} else if (path[i] == CT('#')) {
35+
escapedPath.append(CT('\\'));
36+
} else if (path[i] == CT(' ')) {
37+
escapedPath.append(CT('\\'));
38+
int backwards_it = i - 1;
39+
while (backwards_it > 0 && path[backwards_it] == CT('\\')) {
40+
escapedPath.append(CT('\\'));
41+
--backwards_it;
42+
}
43+
}
44+
escapedPath.append(path[i]);
45+
}
46+
return escapedPath;
47+
}
48+
49+
static inline QByteArray escapeAndEncodeDependencyPath(const QString &path)
50+
{
51+
return QFile::encodeName(escapeDependencyPath(path));
52+
}
53+
54+
#endif // QTBASE_DEPFILE_SHARED_H

0 commit comments

Comments
 (0)