commit a2eb47cc5495fb29d57a5f0617271f8b1728dde6 Author: wdp <544209413@qq.com> Date: Sun Dec 8 23:44:18 2024 +0800 【初始提交】 diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..a6f33ea --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,47 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "process", + "command": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", + "args": [ + "-File", + "${workspaceFolder}\\build-win-app.ps1", + "-build_type", + "Release", + "-build_and_run", + "false" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "presentation": { + "reveal": "silent" + }, + "problemMatcher": [] + }, + { + "label": "run", + "type": "process", + "command": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", + "args": [ + "-File", + "${workspaceFolder}\\build.ps1", + "-build_type", + "Debug", + "-build_and_run", + "true" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "silent" + }, + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..af7956d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.8) +project(Demo) +set(CMAKE_CXX_STANDARD 11) +if(WIN32) + set(CMAKE_CXX_COMPILER "MSVC") +elseif(UNIX) + set(CMAKE_CXX_COMPILER "g++") +endif() + +# 指定库链接目录 +link_directories(3rd/lib) + +include_directories(3rd/include) +include_directories(src) + +aux_source_directory(./src DIR_SRCS) +aux_source_directory(./app DIR_SRCS) + + +add_executable(Demo ${DIR_SRCS}) + +# if(CMAKE_BUILD_TYPE STREQUAL "Debug") +# target_link_libraries(${PROJECT_NAME} spdlogd-mt-x64.lib) +# else() +# target_link_libraries(${PROJECT_NAME} spdlog-mt-x64) +# endif() diff --git a/app/main.cpp b/app/main.cpp new file mode 100644 index 0000000..dcdca77 --- /dev/null +++ b/app/main.cpp @@ -0,0 +1,6 @@ +#include + +int32_t main(int32_t argc, char** argv) { + std::cout << "Hello, World!" << std::endl; + return 0; +} \ No newline at end of file diff --git a/build-win-app.ps1 b/build-win-app.ps1 new file mode 100644 index 0000000..8cc2683 --- /dev/null +++ b/build-win-app.ps1 @@ -0,0 +1,39 @@ +param( + [Parameter(Mandatory=$true)] + [string]$build_type, + + [Parameter(Mandatory=$true)] + [string]$build_and_run +) + +# 定义项目和构建目录的变量 +$projectDir = "$PSScriptRoot" +echo $projectDir +$buildDir = "$projectDir\build" + +# 创建构建目录 +if (-Not (Test-Path -Path $buildDir)) { + New-Item -ItemType Directory -Path $buildDir +} + +# 进入构建目录 +Set-Location -Path $buildDir + +# 运行CMake生成构建系统 +# 这里假设CMakeLists.txt在项目根目录下 +cmake -G "Visual Studio 17 2022" -T host=x64 -DCMAKE_BUILD_TYPE=$build_type .. +# 编译项目 +cmake --build . --config $build_type + +# 返回项目目录 +Set-Location -Path $projectDir + +# 打印构建完成的消息 +Write-Host "build done." -ForegroundColor Darkgreen + +if($build_and_run -eq "true"){ + Write-Host "################## APP Run ##################" -ForegroundColor Blue + Start-Process -FilePath "build\\${build_type}\\TestCode.exe" + # & "build\\$build_type\\TestCode.exe" + +} diff --git a/src/TimeCount.cpp b/src/TimeCount.cpp new file mode 100644 index 0000000..c557680 --- /dev/null +++ b/src/TimeCount.cpp @@ -0,0 +1,20 @@ +#include "TimeCount.h" +#include + +USE_TIME::USE_TIME(std::string str) : + strTmp(str) +{ + start = std::chrono::system_clock::now(); +} + +USE_TIME::~USE_TIME() +{ + end = std::chrono::system_clock::now(); + + auto duration = std::chrono::duration_cast(end - start); + std::cout << strTmp << "\t" << float(duration.count()*1.0) * std::chrono::milliseconds::period::num << "ms \t\n"; + + //auto duration = std::chrono::duration_cast(end - start); + //std::cout << strTmp << "\t" << float(duration.count()*1.0) * std::chrono::microseconds::period::num << "ms \t\n"; +} + diff --git a/src/TimeCount.h b/src/TimeCount.h new file mode 100644 index 0000000..18babcb --- /dev/null +++ b/src/TimeCount.h @@ -0,0 +1,18 @@ +#ifndef TIME_COUNT_H +#define TIME_COUNT_H + +#include +#include + +class USE_TIME{ +public: + USE_TIME(std::string str = ""); + ~USE_TIME(); + +private: + std::string strTmp; + std::chrono::system_clock::time_point start; + std::chrono::system_clock::time_point end; +}; + +#endif \ No newline at end of file