Skip to content

Commit e30d3e4

Browse files
committed
add basic qt6 project
1 parent 8ea811a commit e30d3e4

File tree

9 files changed

+165
-3
lines changed

9 files changed

+165
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ local.properties
1212
log/
1313
*.spv
1414
.vscode
15-
nickel_engine_project_path.toml
15+
nickel_engine_project_path.toml
16+
CMakeLists.txt.user

ReadMe.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ NickelEngine重写中,老版本备份在[NickelEngine-backup](https://github.c
2121

2222
```bash
2323
cmake --preset=default
24+
```
25+
26+
若需要编译Editor,需要安装Qt6.9,使用Qt Creator打开并构建
27+
28+
如果是纯CMake环境,需要指定Qt的工具链路径:
29+
30+
```bash
31+
cmake -S . -B cmake-build -DNICKEL_BUILD_TOOLS=ON -DQT6_PATH=<your qt path>
32+
```
33+
34+
使用CMake构建:
35+
36+
```bash
2437
cmake --build cmake-build
2538
```
2639

engine/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ project(NickelEngine
66
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
77

88
option(NICKEL_BUILD_TESTS "build tests" OFF)
9-
option(NICKEL_BUILD_TOOLS "build tests" OFF)
9+
option(NICKEL_BUILD_TOOLS "build tools" OFF)
1010

1111
set(CMAKE_VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1212

engine/tools/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
add_subdirectory(vehicle_editor)
1+
add_subdirectory(vehicle_editor)
2+
add_subdirectory(editor)

engine/tools/editor/CMakeLists.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
set(QT6_PATH "" CACHE PATH "qt6 path")
2+
list(APPEND CMAKE_PREFIX_PATH ${QT6_PATH})
3+
4+
set(CMAKE_AUTOUIC ON)
5+
set(CMAKE_AUTOMOC ON)
6+
set(CMAKE_AUTORCC ON)
7+
8+
set(CMAKE_CXX_STANDARD 17)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
11+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
12+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
13+
14+
set(PROJECT_SOURCES
15+
main.cpp
16+
mainwindow.cpp
17+
mainwindow.hpp
18+
mainwindow.ui
19+
)
20+
21+
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
22+
qt_add_executable(editor
23+
MANUAL_FINALIZATION
24+
${PROJECT_SOURCES}
25+
)
26+
# Define target properties for Android with Qt 6 as:
27+
# set_property(TARGET editor APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
28+
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
29+
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
30+
else()
31+
if(ANDROID)
32+
add_library(editor SHARED
33+
${PROJECT_SOURCES}
34+
)
35+
# Define properties for Android with Qt 5 after find_package() calls as:
36+
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
37+
else()
38+
add_executable(editor
39+
${PROJECT_SOURCES}
40+
)
41+
endif()
42+
endif()
43+
44+
target_link_libraries(editor PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${NICKEL_ENGINE_NAME})
45+
46+
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
47+
# If you are developing for iOS or macOS you should consider setting an
48+
# explicit, fixed bundle identifier manually though.
49+
if(${QT_VERSION} VERSION_LESS 6.1.0)
50+
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.editor)
51+
endif()
52+
set_target_properties(editor PROPERTIES
53+
${BUNDLE_ID_OPTION}
54+
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
55+
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
56+
MACOSX_BUNDLE TRUE
57+
WIN32_EXECUTABLE TRUE
58+
)
59+
60+
include(GNUInstallDirs)
61+
install(TARGETS editor
62+
BUNDLE DESTINATION .
63+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
64+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
65+
)
66+
67+
if(QT_VERSION_MAJOR EQUAL 6)
68+
qt_finalize_executable(editor)
69+
endif()

engine/tools/editor/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "mainwindow.hpp"
2+
#include "nickel/nickel.hpp"
3+
4+
#include <QApplication>
5+
6+
int main(int argc, char *argv[])
7+
{
8+
QApplication a(argc, argv);
9+
MainWindow w;
10+
w.show();
11+
return a.exec();
12+
}

engine/tools/editor/mainwindow.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "mainwindow.hpp"
2+
#include "./ui_mainwindow.h"
3+
4+
MainWindow::MainWindow(QWidget *parent)
5+
: QMainWindow(parent)
6+
, ui(new Ui::MainWindow)
7+
{
8+
ui->setupUi(this);
9+
}
10+
11+
MainWindow::~MainWindow()
12+
{
13+
delete ui;
14+
}

engine/tools/editor/mainwindow.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include <QMainWindow>
4+
5+
QT_BEGIN_NAMESPACE
6+
namespace Ui {
7+
class MainWindow;
8+
}
9+
QT_END_NAMESPACE
10+
11+
class MainWindow : public QMainWindow
12+
{
13+
Q_OBJECT
14+
15+
public:
16+
MainWindow(QWidget *parent = nullptr);
17+
~MainWindow();
18+
19+
private:
20+
Ui::MainWindow *ui;
21+
};

engine/tools/editor/mainwindow.ui

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainWindow</class>
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>800</width>
10+
<height>600</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>MainWindow</string>
15+
</property>
16+
<widget class="QWidget" name="centralwidget"/>
17+
<widget class="QMenuBar" name="menubar">
18+
<property name="geometry">
19+
<rect>
20+
<x>0</x>
21+
<y>0</y>
22+
<width>800</width>
23+
<height>17</height>
24+
</rect>
25+
</property>
26+
</widget>
27+
<widget class="QStatusBar" name="statusbar"/>
28+
</widget>
29+
<resources/>
30+
<connections/>
31+
</ui>

0 commit comments

Comments
 (0)