From 84867cc4747ac2b7b9b84884995e4bfbdf42a271 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Tue, 21 May 2024 16:46:53 +0400 Subject: [PATCH] Create and use cmake toolchains for msys2. --- .github/workflows/cmake-tier1.yml | 15 +++++------- packaging/cpack_options.cmake | 21 +++++++++-------- toolchains/win32-mingw-msys2.cmake | 37 ++++++++++++++++++++++++++++++ toolchains/win64-mingw-msys2.cmake | 37 ++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 toolchains/win32-mingw-msys2.cmake create mode 100644 toolchains/win64-mingw-msys2.cmake diff --git a/.github/workflows/cmake-tier1.yml b/.github/workflows/cmake-tier1.yml index 46b2ada..4309a26 100644 --- a/.github/workflows/cmake-tier1.yml +++ b/.github/workflows/cmake-tier1.yml @@ -43,9 +43,7 @@ jobs: run: > cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE - -DAPP_BUILD_EXAMPLES=ON - -DAPP_BUILD_TESTS=ON - -DAPP_COMPILER_ENABLE_WARNINGS=ON + -DCMAKE_TOOLCHAIN_FILE="$GITHUB_WORKSPACE/toolchains/linux-dev.cmake" - name: Build shell: bash @@ -74,8 +72,8 @@ jobs: strategy: matrix: include: [ - { msystem: MINGW64, arch: x86_64 }, - { msystem: MINGW32, arch: i686 } + { msystem: MINGW64, arch: x86_64, platform: win64 }, + { msystem: MINGW32, arch: i686, platform: win32 } ] steps: @@ -105,11 +103,10 @@ jobs: - name: Configure CMake shell: msys2 {0} run: > - cmake -B build -S "$GITHUB_WORKSPACE" -G "MSYS Makefiles" + cmake -B build -S "$GITHUB_WORKSPACE" + -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=$BUILD_TYPE - -DAPP_BUILD_EXAMPLES=ON - -DAPP_BUILD_TESTS=ON - -DAPP_COMPILER_ENABLE_WARNINGS=ON + -DCMAKE_TOOLCHAIN_FILE="$GITHUB_WORKSPACE/toolchains/${{ matrix.platform }}-mingw-msys2.cmake" - name: Build shell: msys2 {0} diff --git a/packaging/cpack_options.cmake b/packaging/cpack_options.cmake index 6163f82..8d0a1fc 100644 --- a/packaging/cpack_options.cmake +++ b/packaging/cpack_options.cmake @@ -128,16 +128,19 @@ if (WIN32) option(APP_WINDOWS_SYSROOT "Location of system root for Windows binaries, for packing" "") if (NOT APP_WINDOWS_SYSROOT) - if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") - if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set(APP_WINDOWS_SYSROOT "c:\\msys64\\mingw64") - else() - set(APP_WINDOWS_SYSROOT "c:\\msys64\\mingw32") - endif() - file(TO_CMAKE_PATH "${APP_WINDOWS_SYSROOT}" APP_WINDOWS_SYSROOT) - else() # Cross-compiling +# if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") +# if (CMAKE_SIZEOF_VOID_P EQUAL 8) +# set(APP_WINDOWS_SYSROOT "/mingw64") +# else() +# set(APP_WINDOWS_SYSROOT "/mingw32") +# endif() +# file(TO_CMAKE_PATH "${APP_WINDOWS_SYSROOT}" APP_WINDOWS_SYSROOT) +# else() # Cross-compiling set(APP_WINDOWS_SYSROOT "${CMAKE_FIND_ROOT_PATH}") - endif() +# endif() + endif() + if (NOT APP_WINDOWS_SYSROOT) + message(FATAL_ERROR "APP_WINDOWS_SYSROOT or CMAKE_FIND_ROOT_PATH must be set to environment root directory when compiling for Windows.") endif() message(STATUS "APP_WINDOWS_SYSROOT: ${APP_WINDOWS_SYSROOT}") diff --git a/toolchains/win32-mingw-msys2.cmake b/toolchains/win32-mingw-msys2.cmake new file mode 100644 index 0000000..7bdd247 --- /dev/null +++ b/toolchains/win32-mingw-msys2.cmake @@ -0,0 +1,37 @@ +############################################################################### +# License: BSD Zero Clause License file +# Copyright: +# (C) 2024 Alexander Shaduri +############################################################################### + +# Windows 32-bit production version with mingw/msys2. +# Use with: +# cmake -DCMAKE_TOOLCHAIN_FILE=... + +# Target OS +set(CMAKE_SYSTEM_NAME Windows) + +# Specify the compiler +set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) +#set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) + +# The target environment. This is a path which is valid for msys2. +set(CMAKE_FIND_ROOT_PATH /mingw32) + +# Enable LTO for Release build +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) + +# Increase optimizations of Release builds +add_compile_options("$<$:-g0 -O3 -s>") + +# Enable common CPU optimizations +add_compile_options(-march=i686 -mtune=generic) + + +# Developer options +set(APP_COMPILER_ENABLE_WARNINGS ON) +set(APP_BUILD_EXAMPLES ON) +set(APP_BUILD_TESTS ON) + + diff --git a/toolchains/win64-mingw-msys2.cmake b/toolchains/win64-mingw-msys2.cmake new file mode 100644 index 0000000..adb0eef --- /dev/null +++ b/toolchains/win64-mingw-msys2.cmake @@ -0,0 +1,37 @@ +############################################################################### +# License: BSD Zero Clause License file +# Copyright: +# (C) 2024 Alexander Shaduri +############################################################################### + +# Windows 64-bit production version with mingw/msys2. +# Use with: +# cmake -DCMAKE_TOOLCHAIN_FILE=... + +# Target OS +set(CMAKE_SYSTEM_NAME Windows) + +# Specify the compiler +set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) +#set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) + +# The target environment. This is a path which is valid for msys2. +set(CMAKE_FIND_ROOT_PATH /mingw64) + +# Enable LTO for Release build +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) + +# Increase optimizations of Release builds +add_compile_options("$<$:-g0 -O3 -s>") + +# Enable common CPU optimizations +add_compile_options(-mtune=generic) + + +# Developer options +set(APP_COMPILER_ENABLE_WARNINGS ON) +set(APP_BUILD_EXAMPLES ON) +set(APP_BUILD_TESTS ON) + +