添加msvc编译脚本
This commit is contained in:
80
BuildVs.bat
Normal file
80
BuildVs.bat
Normal 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
|
||||||
@@ -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
|
||||||
)
|
)
|
||||||
@@ -16,7 +20,7 @@ file(GLOB_RECURSE BOOST_SOURCES
|
|||||||
add_library(cxxLibrary STATIC ${SOURCES} ${BOOST_SOURCES})
|
add_library(cxxLibrary STATIC ${SOURCES} ${BOOST_SOURCES})
|
||||||
|
|
||||||
# 修正1:使用相对路径,避免绝对路径警告
|
# 修正1:使用相对路径,避免绝对路径警告
|
||||||
target_include_directories(cxxLibrary PUBLIC
|
target_include_directories(cxxLibrary PUBLIC
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:include>
|
$<INSTALL_INTERFACE:include>
|
||||||
)
|
)
|
||||||
@@ -31,7 +35,7 @@ target_compile_definitions(cxxLibrary PUBLIC
|
|||||||
BOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF
|
BOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(cxxLibrary PROPERTIES
|
set_target_properties(cxxLibrary PROPERTIES
|
||||||
DEBUG_POSTFIX "d"
|
DEBUG_POSTFIX "d"
|
||||||
# 可选:设置其他配置的后缀
|
# 可选:设置其他配置的后缀
|
||||||
# RELEASE_POSTFIX ""
|
# RELEASE_POSTFIX ""
|
||||||
@@ -84,4 +88,4 @@ install(FILES
|
|||||||
"${CMAKE_CURRENT_BINARY_DIR}/cxxLibraryConfig.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/cxxLibraryConfig.cmake"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/cxxLibraryConfigVersion.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/cxxLibraryConfigVersion.cmake"
|
||||||
DESTINATION lib/cmake/cxxLibrary
|
DESTINATION lib/cmake/cxxLibrary
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user