chore: update build system

- use configuration-arch-based path in MSVC to make sure generated package can be used by native MSVC project.
- add github action and corresponding build script. but not tested.
- fix some testbench code.
This commit is contained in:
yyc12345 2024-06-20 15:47:15 +08:00
parent 3fa05b43d9
commit bb17bb6a1f
7 changed files with 93 additions and 12 deletions

1
.gitattributes vendored
View File

@ -1 +1,2 @@
Doxyfile.in eol=lf
*.bat eol=crlf

35
.github/workflows/nightly.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: YYCC Nightly Build
on:
workflow_dispatch:
push:
branches:
- master
jobs:
msvc-build:
strategy:
matrix:
vs: ['2019']
msvc_arch: ['x86']
runs-on: windows-2019
steps:
- name: Fetching Repository
uses: actions/checkout@v3
- name: Building YYCC
shell: cmd
run: |
set VS=${{ matrix.vs }}
set VCVARS="C:\Program Files (x86)\Microsoft Visual Studio\%VS%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat"
if not exist %VCVARS% set VCVARS="C:\Program Files\Microsoft Visual Studio\%VS%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat"
call %VCVARS% ${{ matrix.msvc_arch }}
.\script\build.bat
- name: Uploading Nightly Build
uses: actions/upload-artifact@v3
with:
name: YYCC-windows-nightly
path: bin/install/*
retention-days: 30

View File

@ -8,6 +8,18 @@ project(YYCC
option(YYCC_BUILD_TESTBENCH "Build testbench of YYCCommonplace." OFF)
option(YYCC_BUILD_DOC "Build document of YYCCommonplace." OFF)
# Detect MSVC IDE environment.
# If we in it, we should add configuration and build type in install path.
if (CMAKE_GENERATOR MATCHES "Visual Studio")
# Do Visual Studio specific
set(YYCC_INSTALL_PATH_LIB lib/${CMAKE_VS_PLATFORM_NAME}/$<CONFIG>)
set(YYCC_INSTALL_PATH_BIN bin/${CMAKE_VS_PLATFORM_NAME})
else()
# Other stuff
set(YYCC_INSTALL_PATH_LIB lib)
set(YYCC_INSTALL_PATH_BIN bin)
endif()
# Import 2 build targets
add_subdirectory(src)
if (YYCC_BUILD_TESTBENCH)

35
script/build.bat Normal file
View File

@ -0,0 +1,35 @@
@ECHO OFF
SET README_PATH=%CD%\README.md
IF EXIST %README_PATH% (
REM DO NOTHING
) ELSE (
ECHO Error: You must run this script at the root folder of this project!
EXIT /b
)
:: Create essential folder
MKDIR bin
CD bin
MKDIR Win32
MKDIR x64
MKDIR install
:: Build for Win32
CD Win32
cmake -G "Visual Studio 16 2019" -A Win32 -DYYCC_BUILD_TESTBENCH=ON ../..
cmake --build . --config Debug
cmake --install . --prefix=../install --config Debug
cmake --build . --config Release
cmake --install . --prefix=../install --config Release
CD ..
:: Build for x64
CD x64
cmake -G "Visual Studio 16 2019" -A x64 -DYYCC_BUILD_TESTBENCH=ON ../..
cmake --build . --config Debug
cmake --install . --prefix=../install --config Debug
cmake --build . --config Release
cmake --install . --prefix=../install --config Release
CD ..
ECHO DONE

View File

@ -67,13 +67,11 @@ PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/utf-8>
)
# Install project
# Install binary
# Install binary and headers
install(TARGETS YYCCommonplace
EXPORT YYCCommonplaceTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${YYCC_INSTALL_PATH_LIB}
ARCHIVE DESTINATION ${YYCC_INSTALL_PATH_LIB}
INCLUDES DESTINATION include
FILE_SET HEADERS DESTINATION include
)

View File

@ -33,11 +33,9 @@ PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/utf-8>
)
# Install binary
# Install testbench only on Release mode
install(TARGETS YYCCTestbench
EXPORT YYCCTestbenchTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
CONFIGURATIONS Release
RUNTIME DESTINATION ${YYCC_INSTALL_PATH_BIN}
)

View File

@ -352,7 +352,9 @@ namespace YYCCTestbench {
static void WinFctTestbench() {
#if YYCC_OS == YYCC_OS_WINDOWS
Console::FormatLine("Current Module HANDLE: 0x%" PRI_XPTR_LEFT_PADDING PRIXPTR, YYCC::WinFctHelper::GetCurrentModule());
HMODULE test_current_module;
Assert((test_current_module = YYCC::WinFctHelper::GetCurrentModule()) != nullptr, "YYCC::WinFctHelper::GetCurrentModule");
Console::FormatLine("Current Module HANDLE: 0x%" PRI_XPTR_LEFT_PADDING PRIXPTR, test_current_module);
std::string test_temp;
Assert(YYCC::WinFctHelper::GetTempDirectory(test_temp), "YYCC::WinFctHelper::GetTempDirectory");