修复构建 改为源码依赖
This commit is contained in:
parent
fde177894a
commit
ccf642ef92
@ -19,6 +19,14 @@ else()
|
||||
set(ARCH_DIR "x86")
|
||||
endif()
|
||||
|
||||
option(IS_DEBUG "Enable debug mode" OFF)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(IS_DEBUG ON)
|
||||
else()
|
||||
set(IS_DEBUG OFF)
|
||||
endif()
|
||||
|
||||
|
||||
set(WinDevice_OUTPUT "../WinDevice/output")
|
||||
message("WinDevice_OUTPUT: ${WinDevice_OUTPUT}")
|
||||
# 获取架构信息
|
||||
@ -27,7 +35,7 @@ set(WinDevice_INCLUDE_DIR "${WinDevice_OUTPUT}/include/")
|
||||
message("WinDevice_INCLUDE_DIR: ${WinDevice_INCLUDE_DIR}")
|
||||
set(WinDevice_THIRD_INCLUDE_DIR "${WinDevice_OUTPUT}/third_lib/")
|
||||
message("WinDevice_THIRD_INCLUDE_DIR: ${WinDevice_THIRD_INCLUDE_DIR}")
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
if (IS_DEBUG)
|
||||
set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/debug/")
|
||||
else()
|
||||
set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/release/")
|
||||
@ -79,22 +87,11 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# 将 DeviceManager 目标的构建依赖于 BuildWinDevice 自定义目标
|
||||
# add_dependencies(DeviceManager BuildWinDevice)
|
||||
|
||||
message("include_directories ${WinDevice_INCLUDE_DIR} ${WinDevice_THIRD_INCLUDE_DIR}")
|
||||
|
||||
# 添加头文件目录
|
||||
include_directories(${WinDevice_INCLUDE_DIR} ${WinDevice_THIRD_INCLUDE_DIR})
|
||||
# 使用 find_library 查找动态库文件
|
||||
find_library(WinDevice_LIB NAMES WinDevice HINTS ${WinDevice_LIB_DIR})
|
||||
# 如果找到 WinDevice 库,才链接到 DeviceManager
|
||||
if(WinDevice_LIB)
|
||||
message(STATUS "Found WinDevice library: ${WinDevice_LIB}")
|
||||
target_link_libraries(DeviceManager PRIVATE ${WinDevice_LIB})
|
||||
else()
|
||||
message(WARNING "WinDevice library not found in ${WinDevice_LIB_DIR}")
|
||||
endif()
|
||||
# 添加 WinDevice 子目录
|
||||
add_subdirectory(../WinDevice ${CMAKE_BINARY_DIR}/WinDevice)
|
||||
# 链接 WinDevice 库
|
||||
target_link_libraries(DeviceManager PRIVATE WinDevice) # 假设 WinDevice 是在 WinDevice CMakeLists.txt 中创建的目标
|
||||
|
||||
target_link_libraries(DeviceManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
|
@ -1,12 +1,38 @@
|
||||
//
|
||||
// Created by zyz on 2023/10/17.
|
||||
//
|
||||
#ifdef WIN32
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
#include "LogManager.h"
|
||||
|
||||
void LogManager::CustomMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
QByteArray localMsg = msg.toUtf8();
|
||||
#ifdef WIN32
|
||||
|
||||
QString outputMsg;
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
outputMsg = QString("Debug: %1 (%2:%3, %4)").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
outputMsg = QString("Info: %1 (%2:%3, %4)").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
outputMsg = QString("Warning: %1 (%2:%3, %4)").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
outputMsg = QString("Critical: %1 (%2:%3, %4)").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
outputMsg = QString("Fatal: %1 (%2:%3, %4)").arg(localMsg.constData()).arg(context.file).arg(context.line).arg(context.function);
|
||||
abort();
|
||||
}
|
||||
// 使用 OutputDebugStringA 输出消息
|
||||
::OutputDebugStringA(qUtf8Printable(outputMsg + "\n"));
|
||||
#else
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||
@ -24,4 +50,5 @@ void LogManager::CustomMessageHandler(QtMsgType type, const QMessageLogContext &
|
||||
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -2,26 +2,27 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include "Utils/LogManager.h"
|
||||
#include "Video/ScreenManager.h"
|
||||
#include "../WinDevice/src/Video/ScreenManager.h"
|
||||
#include "../WinDevice/src/WinDeviceManager.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
qInstallMessageHandler(LogManager::CustomMessageHandler);
|
||||
WinDevice::WinDeviceManager::Init();
|
||||
|
||||
ScreenManager screenManager;
|
||||
screenManager.UpdateDisplayInfo();
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
for (size_t i = 0; i < screenManager._displayAdapterList.size(); i++) {
|
||||
DXGI_ADAPTER_DESC adapterDesc;
|
||||
hr = screenManager._displayAdapterList[i]->GetDesc(&adapterDesc);
|
||||
if (SUCCEEDED(hr)) {
|
||||
qDebug("Adapter: %s", adapterDesc.Description);
|
||||
}
|
||||
qDebug("Adapter Count: %d", screenManager._displayDeviceList.size());
|
||||
for (size_t i = 0; i < screenManager._displayDeviceList.size(); i++) {
|
||||
qDebug("Adapter: %s", screenManager._displayDeviceList[i].DeviceName);
|
||||
}
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
|
||||
|
@ -129,7 +129,14 @@ file(GLOB_RECURSE EXPORTED_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h)
|
||||
foreach (HEADER ${EXPORTED_HEADERS})
|
||||
get_filename_component(HEADER_DIR ${HEADER} DIRECTORY)
|
||||
get_filename_component(HEADER_NAME ${HEADER} NAME)
|
||||
string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" HEADER_RELATIVE_PATH ${HEADER_DIR})
|
||||
# 检查 HEADER_DIR 是否包含 "/src/"
|
||||
string(FIND ${HEADER_DIR} "/src/" SRC_DIR_INDEX)
|
||||
# 判断是否找到
|
||||
if (SRC_DIR_INDEX GREATER -1)
|
||||
string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" HEADER_RELATIVE_PATH ${HEADER_DIR})
|
||||
else()
|
||||
string(REPLACE "${CMAKE_SOURCE_DIR}/src" "" HEADER_RELATIVE_PATH ${HEADER_DIR})
|
||||
endif()
|
||||
file(COPY ${HEADER} DESTINATION ${OUTPUT_DIR}/include/${HEADER_RELATIVE_PATH})
|
||||
endforeach ()
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include "Log.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/sinks/stdout_sinks.h"
|
||||
|
||||
|
||||
void Log::Init(LogLevel level, std::string fileName)
|
||||
{
|
||||
spdlog::stdout_logger_mt("console");
|
||||
spdlog::set_level(static_cast<spdlog::level::level_enum>(level)); // 设置日志级别为 debug
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
|
||||
}
|
||||
|
||||
|
@ -2,17 +2,24 @@
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
|
||||
template<typename To, typename From>
|
||||
To Convert(const From& input) {
|
||||
std::wstring_convert<std::codecvt_utf8<typename From::value_type>, typename From::value_type> converter;
|
||||
return converter.to_bytes(input);
|
||||
}
|
||||
namespace WinDevcie {
|
||||
|
||||
std::string Wstring2String(const std::wstring& input) {
|
||||
return Convert<std::string>(input);
|
||||
}
|
||||
namespace Utils {
|
||||
|
||||
template<typename To, typename From>
|
||||
To Convert(const From& input) {
|
||||
std::wstring_convert<std::codecvt_utf8<typename From::value_type>, typename From::value_type> converter;
|
||||
return converter.to_bytes(input);
|
||||
}
|
||||
|
||||
std::string Wstring2String(const std::wstring& input) {
|
||||
return Convert<std::string>(input);
|
||||
}
|
||||
|
||||
std::string Wchar2String(const WCHAR* input) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.to_bytes(input);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Wchar2String(const WCHAR* input) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.to_bytes(input);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#include "ScreenManager.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "Utils/StringUtil.h"
|
||||
#include "Utils/Log.h"
|
||||
#include "../Utils/StringUtil.h"
|
||||
#include "../Utils/Log.h"
|
||||
#include <dxgi.h>
|
||||
|
||||
ScreenManager::ScreenManager()
|
||||
@ -56,7 +56,7 @@ void ScreenManager::_UpdateDisplayAdapterList()
|
||||
DXGI_ADAPTER_DESC adapterDesc;
|
||||
pAdapter->GetDesc(&adapterDesc);
|
||||
spdlog::info("Adapter Index:{0}, Description:{1}, DeviceId:{2}, VendorId:{3}, SubSysId:{4}, Revision:{5}, AdapterLuid(H-L):{6}-{7} ",
|
||||
adapterIndex, Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
|
||||
adapterIndex, WinDevcie::Utils::Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
|
||||
adapterDesc.Revision, adapterDesc.AdapterLuid.HighPart, adapterDesc.AdapterLuid.LowPart);
|
||||
|
||||
// print adapter output info
|
||||
@ -72,7 +72,7 @@ void ScreenManager::_UpdateDisplayAdapterList()
|
||||
{
|
||||
// 输出友好名称
|
||||
spdlog::info("Adapter Output Index:{0}, DeviceName:{1}, szDevice:{2}, right:{3}, bottom:{4}",
|
||||
j, Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
|
||||
j, WinDevcie::Utils::Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,7 +110,7 @@ BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
|
||||
if (DisplayConfigGetDeviceInfo(&targetDeviceName.header) == ERROR_SUCCESS)
|
||||
{
|
||||
spdlog::info("_UpdateMonitorInfoMap, monitorDevicePath:{0}, monitorFriendlyDeviceName:{1}",
|
||||
Wchar2String(targetDeviceName.monitorDevicePath), Wchar2String(targetDeviceName.monitorFriendlyDeviceName));
|
||||
WinDevcie::Utils::Wchar2String(targetDeviceName.monitorDevicePath), WinDevcie::Utils::Wchar2String(targetDeviceName.monitorFriendlyDeviceName));
|
||||
|
||||
// 获取指定 HMONITOR 的分辨率信息
|
||||
DEVMODE dm;
|
||||
|
15
WinDevice/src/WinDeviceManager.cpp
Normal file
15
WinDevice/src/WinDeviceManager.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
#include "WinDeviceManager.h"
|
||||
#include "Utils/Log.h"
|
||||
|
||||
WinDevice::WinDeviceManager::WinDeviceManager() {
|
||||
|
||||
}
|
||||
|
||||
WinDevice::WinDeviceManager::~WinDeviceManager() {
|
||||
|
||||
}
|
||||
|
||||
void WinDevice::WinDeviceManager::Init() {
|
||||
Log::Init(LogLevel::Debug, "WinDevice.log");
|
||||
}
|
16
WinDevice/src/WinDeviceManager.h
Normal file
16
WinDevice/src/WinDeviceManager.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef WINDEVICEMANAGER_H
|
||||
#define WINDEVICEMANAGER_H
|
||||
|
||||
#endif // WINDEVICEMANAGER_H
|
||||
|
||||
namespace WinDevice {
|
||||
|
||||
class WinDeviceManager
|
||||
{
|
||||
public:
|
||||
WinDeviceManager();
|
||||
~WinDeviceManager();
|
||||
|
||||
static void Init();
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user