添加msvc编译脚本

This commit is contained in:
2026-03-27 22:39:33 +08:00
parent 01b7f905e4
commit 4419d606a8
2 changed files with 87 additions and 3 deletions

80
BuildVs.bat Normal file
View File

@@ -0,0 +1,80 @@
@echo off
setlocal enabledelayedexpansion
:: Configuration
set INSTALL_PREFIX=C:/local/cxxLibrary
set BUILD_DEBUG_DIR=debug
set BUILD_RELEASE_DIR=release
set CMAKE_GENERATOR="Ninja"
echo ========================================
echo cxxLibrary Build and Install Script
echo ========================================
echo.
:: Check CMake availability
where cmake >nul 2>nul
if %ERRORLEVEL% neq 0 (
echo [ERROR] CMake not found in PATH!
echo Please ensure CMake is installed and added to system PATH.
pause
exit /b 1
)
:: Check MinGW availability
where mingw32-make >nul 2>nul
if %ERRORLEVEL% neq 0 (
echo [WARNING] mingw32-make not found in PATH!
echo This may cause build failures if using MinGW generator.
echo.
)
:: Build Debug configuration
echo [1/4] Configuring Debug build...
cmake -B%BUILD_DEBUG_DIR% -G %CMAKE_GENERATOR% -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=%INSTALL_PREFIX%
if %ERRORLEVEL% neq 0 (
echo [ERROR] Debug configuration failed!
pause
exit /b 1
)
echo [2/4] Building and installing Debug version...
cmake --build %BUILD_DEBUG_DIR% --target install
if %ERRORLEVEL% neq 0 (
echo [ERROR] Debug build/install failed!
pause
exit /b 1
)
:: Build Release configuration
echo [3/4] Configuring Release build...
cmake -B%BUILD_RELEASE_DIR% -G %CMAKE_GENERATOR% -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%INSTALL_PREFIX%
if %ERRORLEVEL% neq 0 (
echo [ERROR] Release configuration failed!
pause
exit /b 1
)
echo [4/4] Building and installing Release version...
cmake --build %BUILD_RELEASE_DIR% --target install
if %ERRORLEVEL% neq 0 (
echo [ERROR] Release build/install failed!
pause
exit /b 1
)
:: Verification
echo.
echo ========================================
echo Build completed successfully!
echo ========================================
echo Library installed to: %INSTALL_PREFIX%
echo Debug build directory: %BUILD_DEBUG_DIR%
echo Release build directory: %BUILD_RELEASE_DIR%
echo.
echo To use this library in other projects, add to CMake:
echo list(APPEND CMAKE_PREFIX_PATH "%INSTALL_PREFIX%")
echo find_package(cxxLibrary REQUIRED)
echo target_link_libraries(your_target PRIVATE cxxLibrary::cxxLibrary)
echo ========================================
pause

View File

@@ -3,6 +3,10 @@ cmake_minimum_required(VERSION 3.16)
project(cxxLibrary VERSION 1.0.0 LANGUAGES CXX) project(cxxLibrary VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
if (MSVC)
add_compile_definitions(-D_WIN32_WINNT=0x0601)
endif()
set(SOURCES set(SOURCES
src/tinyxml2.cpp src/tinyxml2.cpp
) )