优化构建
This commit is contained in:
parent
9371d67b00
commit
c72ef9cb47
@ -49,12 +49,20 @@ endif()
|
||||
|
||||
target_link_libraries(DeviceManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
set(WinDevice_INCLUDE_DIR "../WinDevice/output/include/")
|
||||
set(WinDevice_THIRD_INCLUDE_DIR "../WinDevice/output/third_lib/")
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(WinDevice_LIB_DIR "../WinDevice/output/debug/")
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(ARCH_DIR "x64")
|
||||
else()
|
||||
set(WinDevice_LIB_DIR "../WinDevice/output/release/")
|
||||
set(ARCH_DIR "x86")
|
||||
endif()
|
||||
|
||||
set(WinDevice_OUTPUT ${CMAKE_SOURCE_DIR}/../WinDevice/output)
|
||||
# 获取架构信息
|
||||
set(WinDevice_INCLUDE_DIR "${WinDevice_OUTPUT}/include/")
|
||||
set(WinDevice_THIRD_INCLUDE_DIR "${WinDevice_OUTPUT}/third_lib/")
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/debug/")
|
||||
else()
|
||||
set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/release/")
|
||||
endif()
|
||||
# 使用 find_library 查找动态库文件
|
||||
find_library(WinDevice_LIB
|
||||
@ -66,23 +74,24 @@ include_directories(${WinDevice_INCLUDE_DIR} ${WinDevice_THIRD_INCLUDE_DIR})
|
||||
# 将找到的库链接到你的目标
|
||||
target_link_libraries(DeviceManager PRIVATE ${WinDevice_LIB})
|
||||
|
||||
# if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
# # Debug 模式下,添加 WinDevice 项目作为子项目
|
||||
# add_subdirectory(../WinDevice WinDevice)
|
||||
# # 链接WinDevice项目
|
||||
# target_include_directories(DeviceManager PRIVATE
|
||||
# ../WinDevice/src
|
||||
# include/third_lib
|
||||
# )
|
||||
# target_link_libraries(DeviceManager PRIVATE WinDevice)
|
||||
# else()
|
||||
# # Release 模式下,链接 WinDevice 生成的库文件
|
||||
# target_link_libraries(DeviceManager PRIVATE WinDevice)
|
||||
# # 在 Release 模式下,添加 WinDevice 的头文件路径
|
||||
# target_include_directories(DeviceManager PRIVATE
|
||||
# ../WinDevice/lib
|
||||
# )
|
||||
# endif()
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
# Debug 模式下,添加 WinDevice 项目作为子项目
|
||||
add_subdirectory(../WinDevice WinDevice)
|
||||
# 链接WinDevice项目
|
||||
target_include_directories(DeviceManager PRIVATE
|
||||
../WinDevice/src
|
||||
include/third_lib
|
||||
)
|
||||
target_link_libraries(DeviceManager PRIVATE WinDevice)
|
||||
else()
|
||||
# Release 模式下,链接 WinDevice 生成的库文件
|
||||
target_link_libraries(DeviceManager PRIVATE WinDevice)
|
||||
# 在 Release 模式下,添加 WinDevice 的头文件路径
|
||||
target_include_directories(DeviceManager PRIVATE
|
||||
${WinDevice_INCLUDE_DIR}
|
||||
${WinDevice_THIRD_INCLUDE_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
set_target_properties(DeviceManager PROPERTIES
|
||||
|
33
DeviceManager/build.bat
Normal file
33
DeviceManager/build.bat
Normal file
@ -0,0 +1,33 @@
|
||||
@echo on
|
||||
chcp 65001
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set arch=x64
|
||||
set build_type=Debug
|
||||
|
||||
rem 如果参数1不为空,设置架构
|
||||
if not "%~1" == "" (
|
||||
set arch=%~1
|
||||
)
|
||||
|
||||
rem 如果参数2不为空,设置构建类型
|
||||
if not "%~2" == "" (
|
||||
set build_type=%~2
|
||||
)
|
||||
|
||||
rem 删除旧的构建目录
|
||||
if exist "build" (
|
||||
rmdir "build" /s /q
|
||||
)
|
||||
|
||||
rem 创建新的构建目录并进入
|
||||
mkdir "build"
|
||||
cd build
|
||||
|
||||
rem 运行 CMake 配置命令
|
||||
cmake .. -G "Visual Studio 17 2022" -A %arch% -DCMAKE_BUILD_TYPE=%build_type%
|
||||
|
||||
rem 执行构建
|
||||
cmake --build . --config %build_type%
|
||||
|
||||
endlocal
|
@ -85,7 +85,7 @@ target_include_directories(WinDevice
|
||||
target_link_libraries(WinDevice PRIVATE ${DirectX_LIBS})
|
||||
|
||||
# 创建 output 目录
|
||||
set(OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/output)
|
||||
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/output)
|
||||
# 获取架构信息
|
||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(ARCH_DIR "x64")
|
||||
@ -102,8 +102,7 @@ set_target_properties(WinDevice PROPERTIES
|
||||
|
||||
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/${ARCH_DIR}/release"
|
||||
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/${ARCH_DIR}/release"
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/${ARCH_DIR}/release"
|
||||
)
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/${ARCH_DIR}/release")
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
# Debug 模式下的配置
|
||||
@ -116,14 +115,9 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
PRIVATE ${Third_Include_DIR} ${Windows_Kits_UM_DIR} ${Windows_Kits_SHARED_DIR})
|
||||
target_link_libraries(WinDeviceTest PRIVATE ${DirectX_LIBS})
|
||||
set_target_properties(WinDeviceTest PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/debug"
|
||||
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/debug"
|
||||
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/debug"
|
||||
|
||||
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/release"
|
||||
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/release"
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/release"
|
||||
)
|
||||
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug"
|
||||
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug"
|
||||
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug")
|
||||
else ()
|
||||
# Release 模式下的配置
|
||||
set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/release")
|
||||
|
33
WinDevice/build.bat
Normal file
33
WinDevice/build.bat
Normal file
@ -0,0 +1,33 @@
|
||||
@echo on
|
||||
chcp 65001
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set arch=x64
|
||||
set build_type=Debug
|
||||
|
||||
rem 如果参数1不为空,设置架构
|
||||
if not "%~1" == "" (
|
||||
set arch=%~1
|
||||
)
|
||||
|
||||
rem 如果参数2不为空,设置构建类型
|
||||
if not "%~2" == "" (
|
||||
set build_type=%~2
|
||||
)
|
||||
|
||||
rem 删除旧的构建目录
|
||||
if exist "build" (
|
||||
rmdir "build" /s /q
|
||||
)
|
||||
|
||||
rem 创建新的构建目录并进入
|
||||
mkdir "build"
|
||||
cd build
|
||||
|
||||
rem 运行 CMake 配置命令
|
||||
cmake .. -G "Visual Studio 17 2022" -A %arch% -DCMAKE_BUILD_TYPE=%build_type%
|
||||
|
||||
rem 执行构建
|
||||
cmake --build . --config %build_type%
|
||||
|
||||
endlocal
|
@ -1,22 +0,0 @@
|
||||
// WinDeviceDemo.cpp: 定义应用程序的入口点。
|
||||
//
|
||||
|
||||
#include "WinDeviceDemo.h"
|
||||
#include "Video/ScreenManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
hr = CoInitialize(nullptr);
|
||||
if (FAILED(hr)) {
|
||||
return 0;
|
||||
}
|
||||
cout << "Hello CMake." << endl;
|
||||
|
||||
ScreenManager screenManager;
|
||||
screenManager.UpdateDisplayInfo();
|
||||
CoUninitialize();
|
||||
return 0;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
// WinDeviceDemo.h: 标准系统包含文件的包含文件
|
||||
// 或项目特定的包含文件。
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// TODO: 在此处引用程序需要的其他标头。
|
Loading…
Reference in New Issue
Block a user