From bb17bb6a1f22ee5f77c57bbcf3190f99d57b0243 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 20 Jun 2024 15:47:15 +0800 Subject: [PATCH] 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. --- .gitattributes | 3 ++- .github/workflows/nightly.yml | 35 +++++++++++++++++++++++++++++++++++ CMakeLists.txt | 12 ++++++++++++ script/build.bat | 35 +++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 8 +++----- testbench/CMakeLists.txt | 8 +++----- testbench/main.cpp | 4 +++- 7 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/nightly.yml create mode 100644 script/build.bat diff --git a/.gitattributes b/.gitattributes index 228a0eb..bed93cf 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -Doxyfile.in eol=lf \ No newline at end of file +Doxyfile.in eol=lf +*.bat eol=crlf \ No newline at end of file diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..113ba8b --- /dev/null +++ b/.github/workflows/nightly.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index f06cf86..f894155 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}/$) + 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) diff --git a/script/build.bat b/script/build.bat new file mode 100644 index 0000000..ef249a4 --- /dev/null +++ b/script/build.bat @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fd1774c..d47e380 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,13 +67,11 @@ PRIVATE $<$:/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 ) diff --git a/testbench/CMakeLists.txt b/testbench/CMakeLists.txt index 045f2dd..e496f87 100644 --- a/testbench/CMakeLists.txt +++ b/testbench/CMakeLists.txt @@ -33,11 +33,9 @@ PRIVATE $<$:/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} ) diff --git a/testbench/main.cpp b/testbench/main.cpp index 9c15b13..82dd606 100644 --- a/testbench/main.cpp +++ b/testbench/main.cpp @@ -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");