build: back to cmake.

This commit is contained in:
2025-07-06 23:51:45 +08:00
parent 13be630726
commit a04202c00e
33 changed files with 436 additions and 5247 deletions

41
.vscode/settings.json vendored
View File

@@ -3,14 +3,41 @@
"editor.fontSize": 14,
// "editor.fontFamily": "'Source Code Pro', 'Source Code Pro', 'Source Code Pro'",
"terminal.integrated.fontFamily": "Source Code Pro",
"cmake.configureOnOpen": false,
"C_Cpp.default.compileCommands": "${workspaceRoot}/.vscode/compile_commands.json",
"C_Cpp.default.cppStandard": "c++11",
"editor.inlayHints.enabled": "off",
"xmake.additionalConfigArguments": [
"--qt=C:/Qt/6.8.3",
"--gui=y"
"cmake.configureOnOpen": true,
"cmake.debugConfig": {
"console": "integratedTerminal",
"setupCommands": [
{
"description": "-gdb-set charset utf-8",
"text": "-gdb-set charset UTF-8"
},
{
"description": "Enable gdb pretty-printing",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"visualizerFile": "${workspaceRoot}/.vscode/qt5.natvis",
"args": ["127.0.0.1", "9009"]
},
"cmake.configureArgs": [
"-Wno-dev"
],
"cmake.environment": {
"QT_LIB_ROOT": "C:/Qt/6.8.3",
"PATH": "${env:PATH};C:/Qt/6.8.3/bin"
},
"cmake.configureSettings": {
"CMAKE_PREFIX_PATH": "${env:QT_LIB_ROOT}",
"QT_DEFAULT_MAJOR_VERSION": "6",
"COMPILE_GUI": "ON"
},
"cmake.options.statusBarVisibility": "visible",
"cmake.generator": "Ninja",
"C_Cpp.default.compileCommands": "${workspaceRoot}/build/compile_commands.json",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"editor.inlayHints.enabled": "off",
"editor.unicodeHighlight.allowedLocales": {
"ja": true,
"zh-hant": true,

View File

@@ -1,26 +0,0 @@
add_rules("mode.debug", "mode.release")
target("SingleApplication")
add_rules("qt.static")
if has_config("qt5") then
add_defines("QT_DEFAULT_MAJOR_VERSION=5")
else
add_defines("QT_DEFAULT_MAJOR_VERSION=6")
end
-- QApplication/QGuiApplication/QCoreApplication
add_defines("QAPPLICATION_CLASS=QApplication")
add_defines("QT_NO_CAST_TO_ASCII")
add_defines("QT_NO_CAST_FROM_ASCII")
add_defines("QT_NO_URL_CAST_FROM_STRING")
add_defines("QT_NO_CAST_FROM_BYTEARRAY")
add_defines("QT_USE_QSTRINGBUILDER")
add_defines("QT_NO_NARROWING_CONVERSIONS_IN_CONNECT")
add_defines("QT_NO_KEYWORDS")
add_defines("QT_NO_FOREACH")
add_includedirs(".", {public = true})
add_files("*.h")
add_files("*.cpp")
add_frameworks("QtCore")
add_frameworks("QtGui")
add_frameworks("QtWidgets")
add_frameworks("QtNetwork")

127
CMakeLists.txt Normal file
View File

@@ -0,0 +1,127 @@
cmake_minimum_required(VERSION 3.16)
project(frelay VERSION 0.2.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(PROJECT_URL "https://github.com/taynpg/frelay")
if(NOT DEFINED QT_DEFAULT_MAJOR_VERSION)
set(QT_DEFAULT_MAJOR_VERSION 6)
endif()
set(QAPPLICATION_CLASS QApplication)
if (MSVC)
add_compile_options(/utf-8)
endif()
if(DEFINED CMAKE_PREFIX_PATH)
message(STATUS "CMAKE_PREFIX_PATH => ${CMAKE_PREFIX_PATH}.")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
message(STATUS "frelay use MINGW compiler.")
set(COMPILER_USE_MINGW ON)
add_definitions(-DCOMPILER_USE_MINGW)
get_filename_component(CXX_COMPILER_PATH ${CMAKE_CXX_COMPILER} DIRECTORY)
set(MINGW_DLLS
"${CXX_COMPILER_PATH}/libgcc_s_dw2-1.dll"
"${CXX_COMPILER_PATH}/libstdc++-6.dll"
"${CXX_COMPILER_PATH}/libwinpthread-1.dll"
)
endif()
if(WIN32)
if(DEFINED XP_PLATFORM_SUPPORT)
message(STATUS "Support Windows XP platform => ${XP_PLATFORM_SUPPORT}.")
add_definitions(-D_WIN32_WINNT=0x0501)
else()
add_definitions(-D_WIN32_WINNT=0x0601)
endif()
set(QT_DEP_FILES
"${CMAKE_PREFIX_PATH}/bin/Qt${QT_DEFAULT_MAJOR_VERSION}Core.dll"
"${CMAKE_PREFIX_PATH}/bin/Qt${QT_DEFAULT_MAJOR_VERSION}Gui.dll"
"${CMAKE_PREFIX_PATH}/bin/Qt${QT_DEFAULT_MAJOR_VERSION}Widgets.dll"
"${CMAKE_PREFIX_PATH}/bin/Qt${QT_DEFAULT_MAJOR_VERSION}Network.dll"
)
set(QT_DEP_DIRS
"${CMAKE_PREFIX_PATH}/plugins/platforms/qwindows.dll"
)
endif()
set(CMAKE_DEBUG_POSTFIX "d")
include_directories(${CMAKE_SOURCE_DIR}/Gui/Control)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/)
include_directories(${PROJECT_BINARY_DIR})
add_definitions(-DFMT_HEADER_ONLY)
include_directories(3rd)
add_subdirectory(Protocol)
add_subdirectory(Server)
add_subdirectory(ClientCore)
add_subdirectory(Util)
if(DEFINED COMPILE_GUI)
message(STATUS "Support Gui Part => ${COMPILE_GUI}.")
add_subdirectory(3rd/SingleApplication-3.5.2)
add_subdirectory(Gui)
install(TARGETS frelayGUI DESTINATION bin)
endif()
add_subdirectory(Console)
add_subdirectory(Struct)
add_subdirectory(Test)
install(TARGETS frelayConsole DESTINATION bin)
install(TARGETS frelayServer DESTINATION bin)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
install(FILES ${MINGW_DLLS} DESTINATION bin)
endif()
if (WIN32)
install(FILES ${QT_DEP_FILES} DESTINATION bin)
install(FILES ${QT_DEP_DIRS} DESTINATION bin/platforms)
endif()
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(version.h.in fversion.h)
message(STATUS "${CMAKE_SYSTEM_NAME} build dir:${PROJECT_BINARY_DIR}")
message(STATUS "VERSION_GIT_BRANCH: ${VERSION_GIT_BRANCH}")
message(STATUS "VERSION_GIT_HASH: ${VERSION_GIT_HASH}")
set(CPACK_PACKAGE_NAME "frelay")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_CONTACT "taynpg <taynpg@163.com>")
set(CPACK_PACKAGE_DESCRIPTION "A simple tool that uses a server as a relay center to indirectly transfer files between multiple clients.")
set(CPACK_PACKAGE_VENDOR "taynpg")
if(WIN32)
set(CPACK_GENERATOR "NSIS;ZIP")
set(CPACK_NSIS_DISPLAY_NAME "frelay")
set(CPACK_NSIS_INSTALL_ROOT "$PROFILE")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "frelay")
set(CPACK_NSIS_CREATE_ICONS_EXTRA "
CreateShortCut '$DESKTOP\\\\frelayGUI.lnk' '$INSTDIR\\\\bin\\\\frelayGUI.exe'
CreateShortCut '$DESKTOP\\\\frelayServer.lnk' '$INSTDIR\\\\bin\\\\frelayServer.exe'
")
set(CPACK_NSIS_DELETE_ICONS_EXTRA "
Delete '$DESKTOP\\\\frelayGUI.lnk'
Delete '$DESKTOP\\\\frelayServer.lnk'
")
else()
set(CPACK_GENERATOR "TGZ")
endif()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-v${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}")
include(CPack)

31
ClientCore/CMakeLists.txt Normal file
View File

@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.16)
project(ClientCore LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)
set(SOURCES
ClientCore.cpp
ClientCore.h
RemoteFile.h
RemoteFile.cpp
FileTrans.h
FileTrans.cpp
)
add_library(ClientCore STATIC ${SOURCES})
target_link_libraries(ClientCore PRIVATE Protocol
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Struct
Util
)
target_include_directories(ClientCore PUBLIC ${CMAKE_CURRENT_LIST_DIR})

View File

@@ -1,12 +0,0 @@
add_rules("mode.debug", "mode.release")
target("ClientCore")
add_rules("qt.static")
add_includedirs(".", {public = true})
add_files("*.h")
add_files("*.cpp")
add_frameworks("QtCore")
add_frameworks("QtNetwork")
add_deps("Struct")
add_deps("Util")
add_deps("Protocol")

17
Console/CMakeLists.txt Normal file
View File

@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.16)
project(frelayConsole LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)
add_executable(frelayConsole Console.h Console.cpp main.cpp ../Res/ico.rc)
target_link_libraries(frelayConsole PRIVATE Protocol Util ClientCore)
target_link_libraries(frelayConsole PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network)

View File

@@ -4,10 +4,6 @@
#include "Console.h"
#ifndef NO_CRASHELPER
#include <crashelper.h>
#endif
int main(int argc, char* argv[])
{
if (argc < 3) {
@@ -15,16 +11,6 @@ int main(int argc, char* argv[])
return 0;
}
#ifndef NO_CRASHELPER
auto configDir = Util::GetCurConfigPath("frelay");
#ifdef _WIN32
backward::SetDumpFileSavePath(configDir + "/dumpfile");
backward::SetDumpLogSavePath(configDir + "/dumplog");
#else
backward::SetDumpLogSavePath(configDir + "/dumplog");
#endif
#endif
qRegisterMetaType<QSharedPointer<FrameBuffer>>("QSharedPointer<FrameBuffer>");
qRegisterMetaType<InfoClientVec>("InfoClientVec");
qRegisterMetaType<DirFileInfoVec>("DirFileInfoVec");

View File

@@ -1,23 +0,0 @@
add_rules("mode.debug", "mode.release")
target("frelayConsole")
set_rules("qt.console")
add_files("Console.cpp", "Console.h", "main.cpp")
add_deps("ClientCore")
add_deps("Protocol")
add_deps("Util")
add_frameworks("QtNetwork")
if is_plat("windows") then
add_files("../Res/ico.rc")
end
if is_plat("mingw") then
add_files("../Res/ico.rc")
else
add_deps("crashelper")
end
if is_plat("linux") then
add_links("dl")
end

89
Gui/CMakeLists.txt Normal file
View File

@@ -0,0 +1,89 @@
cmake_minimum_required(VERSION 3.16)
project(frelayGUI VERSION ${PROJECT_VERSION} LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-DUSE_QT_GUI)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(PROJECT_SOURCES main.cpp
frelayGUI.cpp frelayGUI.h frelayGUI.ui
Control/LogControl.h Control/LogControl.cpp Control/LogControl.ui
Control/FileControl.h Control/FileControl.cpp Control/FileControl.ui
Control/ConnectControl.h Control/ConnectControl.cpp Control/ConnectControl.ui
Control/CompareControl.h Control/CompareControl.cpp Control/CompareControl.ui
GuiUtil/Public.h GuiUtil/Public.cpp
Form/Transform.h Form/Transform.cpp Form/Transform.ui
../Res/frelay.qrc ../Res/ico.rc
Control/cusTableWidget.cpp Control/cusTableWidget.h
Control/cpTableWidget.h Control/cpTableWidget.cpp
GuiUtil/Config.h GuiUtil/Config.cpp
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(frelayGUI
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET frelayGUI APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(frelayGUI SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(frelayGUI
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(frelayGUI PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Network
ClientCore Protocol
Util
Struct SingleApplication::SingleApplication
)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
target_link_libraries(frelayGUI PRIVATE ws2_32 wsock32)
endif()
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.frelayGUI)
endif()
set_target_properties(frelayGUI PROPERTIES
${BUNDLE_ID_OPTION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
include(GNUInstallDirs)
install(TARGETS frelayGUI
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(frelayGUI)
endif()

View File

@@ -28,7 +28,7 @@ frelayGUI::frelayGUI(QWidget* parent) : QMainWindow(parent), ui(new Ui::frelayGU
int height = static_cast<int>(availableGeometry.height() * 0.6);
resize(width, height);
setWindowTitle(QString(tr("frelay %1.%2.%3")).arg(VERSION_MAJOR).arg(VERSION_MINOR).arg(VERSION_ALTER));
setWindowTitle(QString(tr("frelay %1")).arg(VERSION_NUM));
QLabel* permanent = new QLabel(this);
permanent->setFrameStyle(QFrame::Box | QFrame::Sunken);

View File

@@ -5,24 +5,9 @@
#include "frelayGUI.h"
#ifndef NO_CRASHELPER
#include <crashelper.h>
#endif
int main(int argc, char* argv[])
{
#ifndef NO_CRASHELPER
auto configDir = Util::GetCurConfigPath("frelay");
#ifdef _WIN32
backward::SetDumpFileSavePath(configDir + "/dumpfile");
backward::SetDumpLogSavePath(configDir + "/dumplog");
#else
backward::SetDumpLogSavePath(configDir + QDir::separator() + "dumplog");
#endif
CRASHELPER_MARK_ENTRY();
#endif
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
@@ -32,7 +17,7 @@ int main(int argc, char* argv[])
#ifdef _WIN32
QFont font("Microsoft YaHei", 9);
a.setFont(font);
//a.setStyle("fusion");
// a.setStyle("fusion");
a.setStyle("windows");
#endif

View File

@@ -1,40 +0,0 @@
add_rules("mode.debug", "mode.release")
target("frelayGUI")
add_rules("qt.widgetapp")
add_defines("QAPPLICATION_CLASS=QApplication")
add_includedirs(".", {public = true})
add_files("Control/*.h")
add_files("Form/*.h")
add_files("GuiUtil/*.h")
add_files("Control/*.cpp")
add_files("Control/*.ui")
add_files("Form/*.cpp")
add_files("Form/*.ui")
add_files("GuiUtil/*.cpp")
add_files("*.cpp")
add_files("*.ui")
add_files("*.h")
add_files("../Res/frelay.qrc")
if is_plat("windows") then
add_files("../Res/ico.rc")
add_ldflags("-subsystem:windows")
end
add_frameworks("QtCore")
add_frameworks("QtGui")
add_frameworks("QtNetwork")
add_deps("Struct")
add_deps("Protocol")
add_deps("Util")
add_deps("ClientCore")
add_deps("SingleApplication")
if is_plat("mingw") then
add_files("../Res/ico.rc")
add_ldflags("-mwindows")
else
add_deps("crashelper")
end
if is_plat("linux") then
add_links("dl")
end

22
Protocol/CMakeLists.txt Normal file
View File

@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.16)
project(Protocol LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
set(SOURCES
Protocol.cxx
Protocol.h
)
add_library(Protocol STATIC ${SOURCES})
target_link_libraries(Protocol Qt${QT_VERSION_MAJOR}::Core Struct)
target_include_directories(Protocol PUBLIC ${CMAKE_CURRENT_LIST_DIR})

View File

@@ -1,9 +0,0 @@
add_rules("mode.debug", "mode.release")
target("Protocol")
add_rules("qt.static")
add_includedirs(".", {public = true})
add_files("*.cxx")
add_files("*.h")
add_deps("Struct")
add_frameworks("QtCore")

View File

@@ -1,22 +1,17 @@
#!/bin/bash
current_user=$(whoami)
qt_path="/home/${current_user}/Qt5.14.2/5.14.2/gcc_64"
build_dir="build-linux/linux/x64/release"
if [ -d "$qt_path" ]; then
echo "Found Qt directory: $qt_path"
cd ..
xmake f -a x64 -m release --qt="$qt_path" --gui=y --qt5=y -o build-linux -v
xmake
cmake -B../build -S../ -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$qt_path" -DQT_DEFAULT_MAJOR_VERSION=5 -DCOMPILE_GUI=ON
cmake --build ../build --config Release
if [ $? -eq 0 ]; then
find "$build_dir" -name "*.a" -delete 2>/dev/null
find "$build_dir" -name "*Test*" -type f -delete 2>/dev/null
echo "xmake command executed successfully"
echo "cmake command executed successfully"
else
echo "xmake command failed"
echo "cmake command failed"
exit 1
fi
else

View File

@@ -1,13 +1,9 @@
@echo off
@echo on
set QT_DIR=C:/Qt/6.8.3
cd ..
xmake f -p windows -a x64 -m release --qt=C:\Qt\6.8.3 --gui=y -o build-qt6 -v
xmake -r
set outDir=%~dp0..\build-qt6\windows\x64\release\
if %errorlevel% equ 0 (
del /q "%outDir%\*.lib" 2>nul
for /f "delims=" %%f in ('dir /b /a-d "%outDir%\*Test*" 2^>nul') do (
del /q "%outDir%\%%f"
)
C:\Qt\6.8.3\bin\windeployqt.exe %outDir%frelayGUI.exe
)
cmake -Bbuild-qt6 -S. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%QT_DIR% -DQT_DEFAULT_MAJOR_VERSION=6 -DCOMPILE_GUI=ON
cmake --build build-qt6 --config Release
cd build-qt6
cpack
pause

View File

@@ -1,11 +1,2 @@
#!/bin/bash
cd ..
xmake f -a x64 -m release --qt="/data/data/com.termux/files/usr/lib" --qt5=y -o build-linux -v
xmake
if [ $? -eq 0 ]; then
echo "xmake command executed successfully"
else
echo "xmake command failed"
exit 1
fi
cmake -B../build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/data/data/com.termux/files/usr/lib -S../
cmake --build ../build --config Release

View File

@@ -1,17 +1,12 @@
@echo on
set QT_DIR=C:\Qt\Qt5.7.1\5.7\mingw53_32
set COMPILE_DIR=C:\Qt\Qt5.7.1\Tools\mingw530_32
set QT_DIR=C:/Qt/Qt5.7.1/5.7/mingw53_32
set COMPILE_DIR=C:/Qt/Qt5.7.1/Tools/mingw530_32
set PATH=%PATH%;%COMPILE_DIR%/bin
set PATH=%PATH%;%COMPILE_DIR\bin%
xmake f -p mingw --sdk=C:\Qt\Qt5.7.1\Tools\mingw530_32 -a i386 -m release --qt=%QT_DIR% --gui=y --qt5=y --xp=y -o build-xp -v
xmake
set outDir=%~dp0..\build-xp\mingw\i386\release\
if %errorlevel% equ 0 (
del /q "%outDir%\*.a" 2>nul
for /f "delims=" %%f in ('dir /b /a-d "%outDir%\*Test*" 2^>nul') do (
del /q "%outDir%\%%f"
)
%QT_DIR%\bin\windeployqt.exe %outDir%frelayGUI.exe
)
cd ..
cmake -Bbuild-xp -S. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%QT_DIR% -DQT_DEFAULT_MAJOR_VERSION=5 -DXP_PLATFORM_SUPPORT=ON -DCOMPILE_GUI=ON
cmake --build build-xp --config Release
cd build-xp
cpack
pause

17
Server/CMakeLists.txt Normal file
View File

@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.16)
project(frelayServer LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)
add_executable(frelayServer Server.h Server.cpp main.cpp ../Res/server.rc)
target_link_libraries(frelayServer PRIVATE Protocol Util)
target_link_libraries(frelayServer PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network)

View File

@@ -4,10 +4,6 @@
#include "Server.h"
#ifndef NO_CRASHELPER
#include <crashelper.h>
#endif
int main(int argc, char* argv[])
{
int port = 9009;
@@ -17,16 +13,6 @@ int main(int argc, char* argv[])
port = atoi(argv[1]);
}
#ifndef NO_CRASHELPER
auto configDir = Util::GetCurConfigPath("frelay");
#ifdef _WIN32
backward::SetDumpFileSavePath(configDir + "/dumpfile");
backward::SetDumpLogSavePath(configDir + "/dumplog");
#else
backward::SetDumpLogSavePath(configDir + QDir::separator() + "dumplog");
#endif
#endif
QCoreApplication app(argc, argv);
Util::InitLogger("frelayServer.log", "frelayServer");

View File

@@ -1,23 +0,0 @@
add_rules("mode.debug", "mode.release")
target("frelayServer")
set_rules("qt.console")
add_files("Server.cpp", "Server.h", "main.cpp")
add_deps("ClientCore")
add_deps("Protocol")
add_deps("Util")
add_frameworks("QtNetwork")
if is_plat("windows") then
add_files("../Res/server.rc")
end
if is_plat("mingw") then
add_files("../Res/server.rc")
else
add_deps("crashelper")
end
if is_plat("linux") then
add_links("dl")
end

27
Struct/CMakeLists.txt Normal file
View File

@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.16)
project(Struct LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
set(SOURCES
InfoClient.h
InfoClient.cpp
InfoPack.hpp
InfoDirFile.h
InfoDirFile.cpp
InfoMsg.h
InfoMsg.cpp
)
add_library(Struct STATIC ${SOURCES})
target_link_libraries(Struct Qt${QT_VERSION_MAJOR}::Core)
target_include_directories(Struct PUBLIC ${CMAKE_CURRENT_LIST_DIR})

View File

@@ -1,8 +0,0 @@
add_rules("mode.debug", "mode.release")
target("Struct")
add_rules("qt.static")
add_includedirs(".", {public = true})
add_files("*.h")
add_files("*.cpp")
add_frameworks("QtCore")

24
Test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.16)
project(frelayTest LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
set(MSOURCES
msgTest.h msgTest.cpp
protocolTest.cpp infoTest.h infoTest.cpp
)
add_executable(frelayTest ${MSOURCES})
target_link_libraries(frelayTest PRIVATE Protocol Util)
add_executable(frelayBaseTest BaseTest.cpp)
target_link_libraries(frelayBaseTest Qt${QT_VERSION_MAJOR}::Core)

View File

@@ -1,18 +0,0 @@
add_rules("mode.debug", "mode.release")
target("frelayTest")
set_rules("qt.console")
add_files("msgTest.cpp", "msgTest.h", "protocolTest.cpp")
add_files("infoTest.cpp", "infoTest.h")
add_deps("ClientCore")
add_deps("Protocol")
add_deps("Util")
add_frameworks("QtNetwork")
target("frelayBaseTest")
set_rules("qt.console")
add_files("BaseTest.cpp")
add_deps("ClientCore")
add_deps("Protocol")
add_deps("Util")
add_frameworks("QtNetwork")

17
Util/CMakeLists.txt Normal file
View File

@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.16)
project(Util LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
add_library(Util STATIC Util.h Util.cpp LocalFile.h LocalFile.cpp)
target_link_libraries(Util PRIVATE Qt${QT_VERSION_MAJOR}::Core Struct)
target_include_directories(Util PUBLIC ${CMAKE_CURRENT_LIST_DIR})

View File

@@ -1,9 +0,0 @@
add_rules("mode.debug", "mode.release")
target("Util")
add_rules("qt.static")
add_includedirs(".", {public = true})
add_files("*.cpp")
add_files("*.h")
add_deps("Protocol")
add_frameworks("QtCore")

File diff suppressed because it is too large Load Diff

View File

@@ -1,54 +0,0 @@
#ifndef CRASHELPER_H
#define CRASHELPER_H
#if defined(_WIN32) || defined(_WIN64)
#define WIN_OS
#include <windows.h>
#if defined(min)
#undef min
#endif
#elif defined(__APPLE__) && defined(__MACH__)
#define MAC_OS
#elif defined(__linux__) || defined(__TERMUX__) || defined(TERMUX) || defined(__ANDROID__)
#define LINUX_OS
#define BACKWARD_HAS_BFD 1
#else
#error "Unsupported OS"
#endif
#include "backward.hpp"
#include <QString>
namespace backward {
///
/// @brief 设置dump文件的保存目录,不设置默认当前目录。
/// @param path 若不存在则创建,创建失败返回false
///
bool SetDumpFileSavePath(const QString& path);
///
/// @brief 设置dump日志文件的保存目录,不设置默认当前目录。
/// @param path 若不存在则创建,创建失败返回false
///
bool SetDumpLogSavePath(const QString& path);
std::string GetCurFullLogPath();
#if defined(WIN_OS)
void UseExceptionHandler(EXCEPTION_POINTERS* exception);
#endif
} // namespace backward
#ifdef WIN_OS
#define CRASHELPER_MARK_ENTRY() \
backward::SignalHandling sh; \
sh.register_crash_use_handler([](EXCEPTION_POINTERS* exception) { backward::UseExceptionHandler(exception); }); \
sh.register_crash_path([]() -> std::string { return backward::GetCurFullLogPath(); })
#elif defined(MAC_OS)
#elif defined(LINUX_OS)
#define CRASHELPER_MARK_ENTRY() \
backward::SignalHandling sh; \
sh.register_crash_path([]() -> std::string { return backward::GetCurFullLogPath(); })
#endif
#endif // CRASHELPER_H

View File

@@ -1,161 +0,0 @@
#include "crashelper.h"
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QStandardPaths>
#include "backward.hpp"
#ifdef _WIN32
std::function<std::string()> backward::SignalHandling::crash_path_getter_ = nullptr;
std::function<void(EXCEPTION_POINTERS* info)> backward::SignalHandling::crash_use_handler_ = nullptr;
std::function<void(int sig)> backward::SignalHandling::user_sig_handler_ = nullptr;
#else
std::function<std::string()> backward::SignalHandling::crash_path_getter_ = nullptr;
std::function<void(int sig)> backward::SignalHandling::user_sig_handler_ = nullptr;
#endif
namespace backward {
class crashHelper
{
public:
static crashHelper& getInstance()
{
static crashHelper instance;
return instance;
}
public:
static bool createDir(const QString& path);
static QString getCurrentTime();
static QString getBinName();
static QString toFull(const QString& path);
public:
QString dumpSavePath_;
QString dumpLogSavePath_;
private:
crashHelper() = default;
~crashHelper() = default;
};
bool crashHelper::createDir(const QString& path)
{
QDir dir(path);
if (dir.exists()) {
if (!dir.isReadable()) {
return false;
}
return true;
}
if (!dir.mkpath(".")) {
return false;
}
return true;
}
QString crashHelper::getCurrentTime()
{
QDateTime now = QDateTime::currentDateTime();
return now.toString("yyyyMMdd-HHmmss-zzz");
}
QString crashHelper::getBinName()
{
QString exePath = QCoreApplication::applicationFilePath();
if (!exePath.isEmpty()) {
QFileInfo fi(exePath);
return fi.completeBaseName(); // Returns the name without extension
}
return "";
}
QString crashHelper::toFull(const QString& path)
{
QFileInfo fi(path);
if (fi.isRelative()) {
return QDir::current().absoluteFilePath(path);
}
return fi.absoluteFilePath();
}
bool SetDumpFileSavePath(const QString& path)
{
auto& h = crashHelper::getInstance();
if (!h.createDir(path)) {
return false;
}
h.dumpSavePath_ = path;
return true;
}
bool SetDumpLogSavePath(const QString& path)
{
auto& h = crashHelper::getInstance();
if (!h.createDir(path)) {
return false;
}
h.dumpLogSavePath_ = path;
return true;
}
std::string GetCurFullLogPath()
{
auto gf = []() {
auto& h = crashHelper::getInstance();
QString dumpName = h.getCurrentTime() + "-" + h.getBinName() + ".log";
QString fullPath = QDir(h.dumpLogSavePath_).absoluteFilePath(dumpName);
return fullPath.toStdString();
};
#if defined(WIN_OS)
#if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG)
return gf();
#else
return "";
#endif
#else
return gf();
#endif
}
#if defined(WIN_OS)
void UseExceptionHandler(EXCEPTION_POINTERS* exception)
{
auto& h = crashHelper::getInstance();
// Release mode, output dump result to file
QString dumpBase = h.getCurrentTime() + "-" + h.getBinName();
QString dumpName = h.getCurrentTime() + "-" + h.getBinName() + ".windump";
QString dumpFailedLog = h.getCurrentTime() + "-" + h.getBinName() + ".dumpfailed.log";
QString fullPath = QDir(h.dumpSavePath_).absoluteFilePath(dumpName);
QString fullFailedPath = QDir(h.dumpSavePath_).absoluteFilePath(dumpFailedLog);
HANDLE hFile =
CreateFileA(fullPath.toStdString().c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
QFile file(fullFailedPath);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out << "Create dump file failed.\n";
out << "File: " << fullPath << "\n";
out << "Error code: " << GetLastError() << "\n";
}
return;
};
MINIDUMP_EXCEPTION_INFORMATION info;
info.ThreadId = GetCurrentThreadId();
info.ExceptionPointers = exception;
info.ClientPointers = TRUE;
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &info, NULL, NULL);
CloseHandle(hFile);
}
#endif
} // namespace backward

View File

@@ -1,11 +0,0 @@
add_rules("mode.debug", "mode.release")
target("crashelper")
add_rules("qt.static")
add_includedirs("include", {public = true})
add_files("src/*.cxx")
add_frameworks("QtCore")
if is_plat("linux") then
add_links("bfd", "dl")
end

View File

@@ -1,12 +1,9 @@
#ifndef VERSION
#define VERSION
#ifndef VERSION_H
#define VERSION_H
#define VERSION_MAJOR ${VERSION_MAJOR}
#define VERSION_MINOR ${VERSION_MINOR}
#define VERSION_ALTER ${VERSION_ALTER}
#define VERSION_BUILD ${VERSION_BUILD}
#define VERSION_GIT_COMMIT "${GIT_COMMIT}"
#define VERSION_GIT_BRANCH "${GIT_BRANCH}"
#define VERSION_GIT_COMMIT "@VERSION_GIT_HASH@"
#define VERSION_GIT_BRANCH "@VERSION_GIT_BRANCH@"
#define VERSION_NUM "@PROJECT_VERSION@"
#define VERSION_URL "@PROJECT_URL@"
#endif

View File

@@ -1,49 +0,0 @@
add_rules("mode.debug", "mode.release")
set_version("0.2.1", {build = "1"})
if is_plat("windows") then
add_cxflags("/utf-8")
end
if is_plat("mingw") then
add_defines("NO_CRASHELPER=ON")
end
if has_config("xp") then
add_defines("_WIN32_WINNT=0x0501")
else
add_defines("_WIN32_WINNT=0x0601")
end
add_defines("FMT_HEADER_ONLY")
add_includedirs("3rd")
if has_config("gui") then
add_includedirs("Gui/Control")
includes("Gui", "3rd/SingleApplication-3.5.2")
end
add_includedirs("$(builddir)")
add_configfiles("version.h.in", {filename = "fversion.h", outputdir = "$(builddir)"})
includes("Struct", "Protocol", "Util", "ClientCore", "Console", "Server", "Test")
if is_plat("mingw") then
else
includes("crashelper")
end
option("xp")
set_default(false)
set_showmenu(true)
set_description("Enable Windows XP support")
option("gui")
set_default(false)
set_showmenu(true)
set_description("Enable GUI support")
option("qt5")
set_default(false)
set_showmenu(true)
set_description("Use Qt5 instead of Qt6.")