From 62efdd312cf44748c5ec7ca6012a12b8b0ff6333 Mon Sep 17 00:00:00 2001 From: Kirill Gavrilov Date: Sun, 22 Sep 2024 20:13:08 +0300 Subject: [PATCH] Add CI/CD building script using MinGW64 --- .github/workflows/build_wglinfo_mingw.yml | 46 +++++++++++++++++++++++ .github/workflows/build_wglinfo_msvc.yml | 4 +- CMakeLists.txt | 25 +++++++++++- README.md | 1 + wglinfo.cpp | 12 ++++-- 5 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build_wglinfo_mingw.yml diff --git a/.github/workflows/build_wglinfo_mingw.yml b/.github/workflows/build_wglinfo_mingw.yml new file mode 100644 index 0000000..95c3ce9 --- /dev/null +++ b/.github/workflows/build_wglinfo_mingw.yml @@ -0,0 +1,46 @@ +# This workflow will build wglinfo on Windows +name: Build (MinGW64) + +on: [push] + +jobs: + build-windows-mingw: + name: Build on Windows with GCC + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + + steps: + - name: Checkout repository + uses: actions/checkout@v4.1.7 + with: + fetch-depth: 0 + + - name: Setup MSYS2 + uses: msys2/setup-msys2@v2 + with: + msystem: ucrt64 + update: true + install: >- + git + make + pacboy: >- + toolchain:p + cmake:p + ninja:p + + - name: Configure wglinfo + run: | + mkdir "build" + cmake -G Ninja -D BUILD_TREAT_WARNINGS_AS_ERRORS=ON -S . -B "./build" + + - name: Build wglinfo + run: | + cmake --build "./build" --config Release + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: wglinfo-mingw + path: build/wglinfo.exe diff --git a/.github/workflows/build_wglinfo_msvc.yml b/.github/workflows/build_wglinfo_msvc.yml index 6461017..01ad2d7 100644 --- a/.github/workflows/build_wglinfo_msvc.yml +++ b/.github/workflows/build_wglinfo_msvc.yml @@ -11,8 +11,10 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4.1.7 + with: + fetch-depth: 0 - - name: Set up MSVC + - name: Setup MSVC uses: ilammy/msvc-dev-cmd@v1.13.0 with: arch: x64 diff --git a/CMakeLists.txt b/CMakeLists.txt index 23547fb..cdaa4a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,19 @@ set (CMAKE_CXX_STANDARD 11) if (MSVC) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:precise /EHa /MP") string (REGEX REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -DUNICODE) + add_definitions (-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE) + # static linking with CRT + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + #set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") else() set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -fPIC") + if (WIN32) + # force static linking to gcc C++ runtime libraries + set (CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ ${CMAKE_EXE_LINKER_FLAGS}") + endif() +endif() +if (WIN32) + add_definitions(-DUNICODE) endif() set (BUILD_TREAT_WARNINGS_AS_ERRORS OFF CACHE BOOL "Treat compilation warnings as errors") @@ -37,8 +47,19 @@ endif() # Find OpenGL find_package (OpenGL REQUIRED) +set (USED_SRCFILES "wglinfo.cpp") +set (USED_RCFILE "") +if (WIN32) + set (USED_RCFILE "wglinfo.rc") +endif() + # main project target add_executable (${PROJECT_NAME} - wglinfo.cpp + ${USED_SRCFILES} ${RESOURCE_FILES} ) target_link_libraries (${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARIES}) + +# force static linking to winpthreads +if (WIN32 AND CMAKE_COMPILER_IS_GNUCXX) + target_link_libraries (${PROJECT_NAME} PRIVATE -static gcc stdc++ winpthread -dynamic) +endif() diff --git a/README.md b/README.md index 10c3474..2653962 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ wglinfo - command line tool for printing OpenGL information on Windows platform [![Downloads](https://img.shields.io/github/downloads/gkv311/wglinfo/total.svg)](https://github.com/gkv311/wglinfo/releases) [![License: GPL v3](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/gkv311/wglinfo/blob/master/LICENSE.txt) [![Status](https://github.com/gkv311/wglinfo/actions/workflows/build_wglinfo_msvc.yml/badge.svg?branch=master)](https://github.com/gkv311/wglinfo/actions?query=branch%3Amaster) +[![Status](https://github.com/gkv311/wglinfo/actions/workflows/build_wglinfo_mingw.yml/badge.svg?branch=master)](https://github.com/gkv311/wglinfo/actions?query=branch%3Amaster) wglinfo is a small utility printing information about OpenGL library available in Windows system in similar way as glxinfo does on Linux. In case, if libEGL.dll (e.g. Angle or another implementation) is in PATH, it also prints information about EGL/GLES. diff --git a/wglinfo.cpp b/wglinfo.cpp index f75a448..491b12e 100644 --- a/wglinfo.cpp +++ b/wglinfo.cpp @@ -15,6 +15,12 @@ #include +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__) + #if (__GNUC__ > 8) || ((__GNUC__ == 8) && (__GNUC_MINOR__ >= 1)) + #pragma GCC diagnostic ignored "-Wcast-function-type" + #endif +#endif + //! Window creation tool. struct GlWindow { @@ -1184,7 +1190,7 @@ class EglInfoWindow }; -int actual_main (int theNbArgs, char** theArgVec) +static int actual_main (int theNbArgs, const char** theArgVec) { bool isVerbose = false, toPrintVisuals = true, toShowEgl = true; for (int anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) @@ -1211,7 +1217,7 @@ int actual_main (int theNbArgs, char** theArgVec) else { std::cerr << "Syntax error! Unknown argument '" << theArgVec[anArgIter] << "'\n\n"; - char* anArgs[2] = { theArgVec[0], "-h" }; + const char* anArgs[2] = { theArgVec[0], "-h" }; actual_main (2, anArgs); return 1; } @@ -1252,7 +1258,7 @@ int actual_main (int theNbArgs, char** theArgVec) return 0; } -int main(int argc, char** argv) +int main(int argc, const char** argv) { return actual_main(argc, argv); }