Skip to content

Commit 5a55a06

Browse files
committed
feat: add mingw toolchain and preset
1 parent 19b08f5 commit 5a55a06

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

CMakePresets.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
"value": "x64",
4040
"strategy": "external"
4141
}
42+
},
43+
{
44+
"name": "mingw",
45+
"displayName": "MinGW-w64 (cross)",
46+
"description": "Cross-compile for Windows using MinGW-w64",
47+
"generator": "Ninja",
48+
"binaryDir": "${sourceDir}/build/mingw",
49+
"toolchainFile": "${sourceDir}/cmake/mingw-toolchain.cmake",
50+
"cacheVariables": {
51+
"CMAKE_BUILD_TYPE": "Debug"
52+
}
4253
}
4354
],
4455
"buildPresets": [
@@ -77,6 +88,18 @@
7788
"displayName": "MSVC Release",
7889
"configurePreset": "msvc",
7990
"configuration": "Release"
91+
},
92+
{
93+
"name": "mingw-debug",
94+
"displayName": "MinGW Debug",
95+
"configurePreset": "mingw",
96+
"configuration": "Debug"
97+
},
98+
{
99+
"name": "mingw-release",
100+
"displayName": "MinGW Release",
101+
"configurePreset": "mingw",
102+
"configuration": "Release"
80103
}
81104
]
82105
}

cmake/mingw-toolchain.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# MinGW-w64 Toolchain file for cpp-core
2+
# Usage:
3+
# cmake -B build-win -DCMAKE_TOOLCHAIN_FILE=cmake/mingw64-toolchain.cmake ..
4+
# cmake --build build-win
5+
6+
# Target system
7+
set(CMAKE_SYSTEM_NAME Windows)
8+
set(CMAKE_SYSTEM_PROCESSOR x86_64)
9+
10+
# MinGW-w64 compilers
11+
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
12+
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
13+
14+
# Optional, useful for Windows resources
15+
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
16+
17+
# Search behavior for cross compiling
18+
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
19+
20+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
21+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
22+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
23+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
24+
25+
# Compiler-specific flags
26+
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wpedantic")
27+
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wpedantic")
28+
29+
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -O0")
30+
set(CMAKE_C_FLAGS_DEBUG_INIT "-g -O0")
31+
32+
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
33+
set(CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
34+
35+
# Recommended for Deno-loaded DLLs:
36+
# statically link MinGW runtime parts, but keep Windows system DLLs dynamic.
37+
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++")
38+
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++")

0 commit comments

Comments
 (0)