Compare commits

...

2 Commits

Author SHA1 Message Date
b01ab5a972 增加构建配置 2024-09-27 14:38:53 +08:00
c72ef9cb47 优化构建 2024-09-26 20:06:56 +08:00
8 changed files with 187 additions and 112 deletions

21
CppProperties.json Normal file
View File

@ -0,0 +1,21 @@
{
"configurations": [
{
"inheritEnvironments": [
"msvc_x86"
],
"name": "x86-Debug",
"includePath": [
"${env.INCLUDE}",
"${workspaceRoot}\\**"
],
"defines": [
"WIN32",
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "windows-msvc-x86"
}
]
}

View File

@ -49,42 +49,46 @@ endif()
target_link_libraries(DeviceManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 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_SIZEOF_VOID_P EQUAL 8)
if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(ARCH_DIR "x64")
set(WinDevice_LIB_DIR "../WinDevice/output/debug/")
else() else()
set(WinDevice_LIB_DIR "../WinDevice/output/release/") set(ARCH_DIR "x86")
endif() endif()
# 使 find_library
find_library(WinDevice_LIB set(WinDevice_OUTPUT "../WinDevice/output")
NAMES WinDevice message("WinDevice_OUTPUT: ${WinDevice_OUTPUT}")
HINTS ${WinDevice_LIB_DIR} #
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")
set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/debug/")
else()
set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/release/")
endif()
message("WinDevice_LIB_DIR: ${WinDevice_LIB_DIR}")
message("build WinDecie in: ${CMAKE_BUILD_TYPE} mode")
add_custom_target(BuildWinDevice ALL
COMMAND ${CMAKE_COMMAND} -E echo "Starting to build WinDevice project..."
COMMAND ${CMAKE_COMMAND} -S ../WinDevice -B ../WinDevice/build -G "Visual Studio 17 2022" -A ${ARCH_DIR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
COMMAND ${CMAKE_COMMAND} --build ../WinDevice/build --config ${CMAKE_BUILD_TYPE}
COMMENT "Building WinDevice project in ${CMAKE_BUILD_TYPE} mode"
) )
# # DeviceManager BuildWinDevice
add_dependencies(DeviceManager BuildWinDevice)
#
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})
# Release WinDevice
target_link_libraries(DeviceManager PRIVATE ${WinDevice_LIB}) 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()
set_target_properties(DeviceManager PROPERTIES set_target_properties(DeviceManager PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}

View File

@ -6,11 +6,31 @@
"configurationType": "Debug", "configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}", "buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ]
},
{
"name": "x86-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "", "cmakeCommandArgs": "",
"buildCommandArgs": "", "buildCommandArgs": "",
"ctestCommandArgs": "", "ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ], "inheritEnvironments": [ "msvc_x86" ]
"variables": [] },
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ]
} }
] ]
} }

33
DeviceManager/build.bat Normal file
View 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

View File

@ -15,10 +15,10 @@ set(CMAKE_GENERATOR_TOOLSET "v143")
if (NOT DEFINED CMAKE_GENERATOR_PLATFORM) if (NOT DEFINED CMAKE_GENERATOR_PLATFORM)
if (CMAKE_SIZEOF_VOID_P EQUAL 8) if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_GENERATOR_PLATFORM x64) set(CMAKE_GENERATOR_PLATFORM x64)
else() else ()
set(CMAKE_GENERATOR_PLATFORM x86) set(CMAKE_GENERATOR_PLATFORM x86)
endif() endif ()
endif() endif ()
# C++ # C++
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
@ -37,8 +37,8 @@ if (ENABLE_UTF8_SOURCE)
elseif (CMAKE_COMPILER_IS_GNUCXX) elseif (CMAKE_COMPILER_IS_GNUCXX)
# MinGWUTF-8 # MinGWUTF-8
add_compile_options("-fexec-charset=UTF-8" "-finput-charset=UTF-8") add_compile_options("-fexec-charset=UTF-8" "-finput-charset=UTF-8")
endif() endif ()
endif() endif ()
# DirectX # DirectX
set(Windows_Kits_DIR "C:\\Program Files (x86)\\Windows Kits\\10") set(Windows_Kits_DIR "C:\\Program Files (x86)\\Windows Kits\\10")
@ -46,64 +46,63 @@ set(Windows_Kits_Version "10.0.19041.0")
set(Windows_Kits_UM_DIR "${Windows_Kits_DIR}\\Include\\${Windows_Kits_Version}\\um") set(Windows_Kits_UM_DIR "${Windows_Kits_DIR}\\Include\\${Windows_Kits_Version}\\um")
set(Windows_Kits_SHARED_DIR "${Windows_Kits_DIR}\\Include\\${Windows_Kits_Version}\\shared") set(Windows_Kits_SHARED_DIR "${Windows_Kits_DIR}\\Include\\${Windows_Kits_Version}\\shared")
if(CMAKE_SIZEOF_VOID_P EQUAL 8) if (CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64-bit # 64-bit
set(CMAKE_LIBRARY_ARCHITECTURE x64) set(CMAKE_LIBRARY_ARCHITECTURE x64)
set(DirectX_SDK_LIB_DIR "${Windows_Kits_DIR}\\Lib\\${Windows_Kits_Version}\\um\\x64") set(DirectX_SDK_LIB_DIR "${Windows_Kits_DIR}\\Lib\\${Windows_Kits_Version}\\um\\x64")
else() else ()
# 32-bit # 32-bit
set(CMAKE_LIBRARY_ARCHITECTURE x86) set(CMAKE_LIBRARY_ARCHITECTURE x86)
set(DirectX_SDK_LIB_DIR "${Windows_Kits_DIR}\\Lib\\${Windows_Kits_Version}\\um\\x86") set(DirectX_SDK_LIB_DIR "${Windows_Kits_DIR}\\Lib\\${Windows_Kits_Version}\\um\\x86")
endif() endif ()
# DirectX # DirectX
file(GLOB DirectX_LIBS file(GLOB DirectX_LIBS
"${DirectX_SDK_LIB_DIR}/d3d9.lib" "${DirectX_SDK_LIB_DIR}/d3d9.lib"
"${DirectX_SDK_LIB_DIR}/d3d10.lib" "${DirectX_SDK_LIB_DIR}/d3d10.lib"
"${DirectX_SDK_LIB_DIR}/d3d11.lib" "${DirectX_SDK_LIB_DIR}/d3d11.lib"
"${DirectX_SDK_LIB_DIR}/d3d12.lib" "${DirectX_SDK_LIB_DIR}/d3d12.lib"
"${DirectX_SDK_LIB_DIR}/dxgi.lib" "${DirectX_SDK_LIB_DIR}/dxgi.lib"
"${DirectX_SDK_LIB_DIR}/ddraw.lib" "${DirectX_SDK_LIB_DIR}/ddraw.lib"
) )
# 使 # 使
file(GLOB_RECURSE SOURCE_FILES "./src/*") file(GLOB_RECURSE SOURCE_FILES "./src/*")
set(Third_Include_DIR "include/third_lib/") set(Third_Include_DIR "include/third_lib/")
# #
add_library(WinDevice SHARED add_library(WinDevice SHARED
${SOURCE_FILES} ${SOURCE_FILES}
) )
# WinDevice # WinDevice
target_include_directories(WinDevice target_include_directories(WinDevice
PUBLIC PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src> $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
PRIVATE PRIVATE
${Windows_Kits_UM_DIR} ${Windows_Kits_UM_DIR}
${Windows_Kits_SHARED_DIR} ${Windows_Kits_SHARED_DIR}
${Third_Include_DIR} ${Third_Include_DIR}
) )
# d3d lib # d3d lib
target_link_libraries(WinDevice PRIVATE ${DirectX_LIBS}) target_link_libraries(WinDevice PRIVATE ${DirectX_LIBS})
# output # output
set(OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/output) set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/output)
# #
if(CMAKE_SIZEOF_VOID_P EQUAL 8) if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH_DIR "x64") set(ARCH_DIR "x64")
else() else ()
set(ARCH_DIR "x86") set(ARCH_DIR "x86")
endif() endif ()
# #
file(MAKE_DIRECTORY ${OUTPUT_DIR}/${ARCH_DIR}) file(MAKE_DIRECTORY ${OUTPUT_DIR}/${ARCH_DIR})
set_target_properties(WinDevice PROPERTIES set_target_properties(WinDevice PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug" ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug"
LIBRARY_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" RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug"
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/${ARCH_DIR}/release" ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/${ARCH_DIR}/release"
LIBRARY_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") if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Debug # Debug
@ -111,33 +110,28 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/debug") set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/debug")
# #
add_executable(WinDeviceTest "src/main.cpp" ${SOURCE_FILES}) add_executable(WinDeviceTest "src/main.cpp" ${SOURCE_FILES})
target_include_directories(WinDeviceTest target_include_directories(WinDeviceTest
PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src> PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
PRIVATE ${Third_Include_DIR} ${Windows_Kits_UM_DIR} ${Windows_Kits_SHARED_DIR}) PRIVATE ${Third_Include_DIR} ${Windows_Kits_UM_DIR} ${Windows_Kits_SHARED_DIR})
target_link_libraries(WinDeviceTest PRIVATE ${DirectX_LIBS}) target_link_libraries(WinDeviceTest PRIVATE ${DirectX_LIBS})
set_target_properties(WinDeviceTest PROPERTIES set_target_properties(WinDeviceTest PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/debug" ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/debug" LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/debug" RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug")
else ()
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/release"
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/release"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}/release"
)
else()
# Release # Release
set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/release") set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/release")
endif() endif ()
# include # include
file(GLOB_RECURSE EXPORTED_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h) file(GLOB_RECURSE EXPORTED_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h)
foreach(HEADER ${EXPORTED_HEADERS}) foreach (HEADER ${EXPORTED_HEADERS})
get_filename_component(HEADER_DIR ${HEADER} DIRECTORY) get_filename_component(HEADER_DIR ${HEADER} DIRECTORY)
get_filename_component(HEADER_NAME ${HEADER} NAME) get_filename_component(HEADER_NAME ${HEADER} NAME)
string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" HEADER_RELATIVE_PATH ${HEADER_DIR}) string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" HEADER_RELATIVE_PATH ${HEADER_DIR})
file(COPY ${HEADER} DESTINATION ${OUTPUT_DIR}/include/${HEADER_RELATIVE_PATH}) file(COPY ${HEADER} DESTINATION ${OUTPUT_DIR}/include/${HEADER_RELATIVE_PATH})
endforeach() endforeach ()
# output/third_lib # output/third_lib
set(OUTPUT_THIRD_LIB_DIR ${OUTPUT_DIR}/third_lib) set(OUTPUT_THIRD_LIB_DIR ${OUTPUT_DIR}/third_lib)

33
WinDevice/build.bat Normal file
View 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

View File

@ -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;
}

View File

@ -1,8 +0,0 @@
// WinDeviceDemo.h: 标准系统包含文件的包含文件
// 或项目特定的包含文件。
#pragma once
#include <iostream>
// TODO: 在此处引用程序需要的其他标头。