From 9b9cb9e86c3fe14f3d23b1d018c822290de15784 Mon Sep 17 00:00:00 2001 From: flykhan Date: Sun, 3 May 2026 10:58:06 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=B0=86=E9=A1=B9=E7=9B=AE=E4=BB=8E?= =?UTF-8?q?=20.sln/.vcxproj=20=E8=BD=AC=E6=8D=A2=E4=B8=BA=20CMake=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 11 ++++++++ CMakeLists.txt | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index cbef543..42f2da8 100644 --- a/.gitignore +++ b/.gitignore @@ -432,3 +432,14 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +# ---> CMake +build/ +cmake-build-*/ +CMakeCache.txt +CMakeFiles/ +CMakeScripts/ +*.cmake +!CMakeLists.txt +Makefile +*.make + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6c1470a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required(VERSION 3.10) +project(tank_battles_on_the_scrap_paper + VERSION 1.0 + LANGUAGES CXX +) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# ── 源文件 ── +set(SOURCES + tank_battles_on_the_scrap_paper/main.cpp + tank_battles_on_the_scrap_paper/map.cpp +) + +set(HEADERS + tank_battles_on_the_scrap_paper/bullet.h + tank_battles_on_the_scrap_paper/tank.h + tank_battles_on_the_scrap_paper/map.h + tank_battles_on_the_scrap_paper/data_config.h + tank_battles_on_the_scrap_paper/resource.h +) + +# ── 可执行文件 ── +add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} + tank_battles_on_the_scrap_paper/resource.rc +) + +# ── Windows 特定配置 ── +if(WIN32) + # EasyX 图形库 + target_include_directories(${PROJECT_NAME} PRIVATE + ${EASYX_INCLUDE_DIR} + ) + + # Windows 多媒体库 + target_link_libraries(${PROJECT_NAME} PRIVATE + winmm.lib + gdi32.lib + ) + + # 控制台子系统 + set_target_properties(${PROJECT_NAME} PROPERTIES + WIN32_EXECUTABLE FALSE + ) + + target_compile_definitions(${PROJECT_NAME} PRIVATE + _CONSOLE + _UNICODE + UNICODE + ) +else() + # 非 Windows 平台给出提示 + message(WARNING + "${PROJECT_NAME} 依赖 EasyX (Windows-only 图形库)," + "当前平台不支持编译。仅生成项目结构参考。" + ) +endif() + +# ── 复制资源文件到构建目录 ── +file(COPY + tank_battles_on_the_scrap_paper/images/ + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/images/ +) + +file(COPY + tank_battles_on_the_scrap_paper/music/ + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/music/ +)