Skip to content

Commit bb3da1f

Browse files
committed
build(cmake): avoid hardcoded paths, add x86
Signed-off-by: Ahmed Samy <asamy@protonmail.com>
1 parent 214a61b commit bb3da1f

8 files changed

Lines changed: 52 additions & 11 deletions

File tree

.github/workflows/windows-cmake.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ permissions:
2020

2121
jobs:
2222
build:
23-
name: ${{ matrix.config }} (${{ matrix.link }})
23+
name: ${{ matrix.arch }} ${{ matrix.config }} (${{ matrix.link }})
2424
runs-on: windows-latest
2525

2626
strategy:
2727
fail-fast: false
2828
matrix:
2929
config: [Debug, Release]
3030
link: [static, shared]
31+
arch: [x64, x86]
3132

3233
env:
33-
VCPKG_DEFAULT_TRIPLET: ${{ matrix.link == 'static' && 'x64-windows-static' || 'x64-windows' }}
34+
VCPKG_DEFAULT_TRIPLET: ${{ matrix.arch }}-windows${{ matrix.link == 'static' && '-static' || '' }}
35+
VCPKG_DEFAULT_HOST_TRIPLET: ${{ matrix.arch }}-windows${{ matrix.link == 'static' && '-static' || '' }}
3436
VCPKG_BUILD_TYPE: ${{ matrix.config == 'Debug' && 'debug' || 'release' }}
37+
VCPKG_OVERLAY_TRIPLETS: ${{ github.workspace }}/cmake/triplets
3538

3639
steps:
3740
- name: Check out repository
@@ -42,12 +45,12 @@ jobs:
4245
- name: Setup MSBuild
4346
uses: microsoft/setup-msbuild@v3
4447
with:
45-
msbuild-architecture: x64
48+
msbuild-architecture: ${{ matrix.arch }}
4649

4750
- name: Setup MSVC dev environment
4851
uses: ilammy/msvc-dev-cmd@v1
4952
with:
50-
arch: x64
53+
arch: ${{ matrix.arch }}
5154

5255
- name: Export GitHub Actions cache environment variables
5356
uses: actions/github-script@v9

CMakePresets.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@
2424
"base"
2525
],
2626
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
27+
"environment": {
28+
"VCPKG_DEFAULT_TRIPLET": "x64-windows-static",
29+
"VCPKG_DEFAULT_HOST_TRIPLET": "x64-windows-static"
30+
},
2731
"cacheVariables": {
32+
"VCPKG_TARGET_TRIPLET": "$env{VCPKG_DEFAULT_TRIPLET}",
33+
"VCPKG_HOST_TRIPLET": "$env{VCPKG_DEFAULT_HOST_TRIPLET}",
34+
"VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/triplets",
2835
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/clang.cmake"
2936
}
3037
}

REUSE.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ SPDX-FileCopyrightText = "2024 Jürgen Repp"
128128
SPDX-License-Identifier = "BSD-2-Clause"
129129

130130
[[annotations]]
131-
path = ["CMakePresets.json", "vcpkg.json", "vcpkg-configuration.json"]
131+
path = ["CMakePresets.json", "vcpkg.json", "vcpkg-configuration.json", "cmake/triplets/*.cmake", "cmake/toolchains/*.cmake"]
132132
precedence = "aggregate"
133133
SPDX-FileCopyrightText = "2026 Ahmed Samy"
134134
SPDX-License-Identifier = "BSD-2-Clause"

cmake/toolchains/clang.cmake

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
# Clang/LLVM toolchain for Windows
55
# Usage: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/clang.cmake
66

7-
# Locate ml64.exe (MASM assembler) from MSVC installation
7+
# Use vswhere to find the VS installation path without hardcoding version/edition
8+
find_program(_VSWHERE vswhere
9+
PATHS "C:/Program Files (x86)/Microsoft Visual Studio/Installer"
10+
NO_DEFAULT_PATH
11+
)
12+
if(_VSWHERE)
13+
execute_process(
14+
COMMAND "${_VSWHERE}" -latest -property installationPath
15+
OUTPUT_VARIABLE _VS_INSTALL_PATH
16+
OUTPUT_STRIP_TRAILING_WHITESPACE
17+
)
18+
file(GLOB _MSVC_TOOL_DIRS "${_VS_INSTALL_PATH}/VC/Tools/MSVC/*/bin/Hostx64/x64")
19+
endif()
20+
21+
# Locate ml64.exe (MASM assembler)
822
find_program(_ML64_PATH ml64
9-
PATHS
23+
HINTS
1024
"$ENV{VCToolsInstallDir}/bin/Hostx64/x64"
11-
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/*/bin/Hostx64/x64"
12-
"C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/*/bin/Hostx64/x64"
13-
"C:/Program Files/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/*/bin/Hostx64/x64"
25+
${_MSVC_TOOL_DIRS}
1426
)
1527
if(_ML64_PATH)
1628
set(CMAKE_ASM_MASM_COMPILER "${_ML64_PATH}")
@@ -20,8 +32,11 @@ endif()
2032

2133
set(CMAKE_SYSTEM_NAME Windows)
2234

23-
# Find Clang from default LLVM install locations
35+
# Find Clang - bundled with VS (preferred) or standalone LLVM install
2436
find_program(CLANG_CL_PATH clang-cl
37+
HINTS
38+
"${_VS_INSTALL_PATH}/VC/Tools/Llvm/x64/bin"
39+
"$ENV{VCToolsInstallDir}/../../Llvm/x64/bin"
2540
PATHS
2641
"C:/Program Files/LLVM/bin"
2742
"C:/Program Files (x86)/LLVM/bin"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(VCPKG_TARGET_ARCHITECTURE x64)
2+
set(VCPKG_CRT_LINKAGE static)
3+
set(VCPKG_LIBRARY_LINKAGE static)
4+
set(VCPKG_BUILD_TYPE $ENV{VCPKG_BUILD_TYPE})

cmake/triplets/x64-windows.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(VCPKG_TARGET_ARCHITECTURE x64)
2+
set(VCPKG_CRT_LINKAGE dynamic)
3+
set(VCPKG_LIBRARY_LINKAGE dynamic)
4+
set(VCPKG_BUILD_TYPE $ENV{VCPKG_BUILD_TYPE})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(VCPKG_TARGET_ARCHITECTURE x86)
2+
set(VCPKG_CRT_LINKAGE static)
3+
set(VCPKG_LIBRARY_LINKAGE static)
4+
set(VCPKG_BUILD_TYPE $ENV{VCPKG_BUILD_TYPE})

cmake/triplets/x86-windows.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(VCPKG_TARGET_ARCHITECTURE x86)
2+
set(VCPKG_CRT_LINKAGE dynamic)
3+
set(VCPKG_LIBRARY_LINKAGE dynamic)
4+
set(VCPKG_BUILD_TYPE $ENV{VCPKG_BUILD_TYPE})

0 commit comments

Comments
 (0)