Skip to content

Commit de2fa78

Browse files
authored
Support UWP build with CMakePresets.json (#116)
* Support UWP and fix compile errors * gh-actions: UWP build uses CMakePresets.json * create cmake-uwp job * link Kernel32 for some functions * cmake: support both x64-uwp, arm64-uwp * cmake: apply PR feedback
1 parent 8ec7bd9 commit de2fa78

File tree

4 files changed

+100
-8
lines changed

4 files changed

+100
-8
lines changed

.github/workflows/build.yml

+25
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,31 @@ jobs:
4343
run: scripts/local-build.sh
4444
shell: bash # Specify bash so we can reuse the build script on Windows (runs on Git bash)
4545
working-directory: ${{ github.workspace }}
46+
cmake-uwp:
47+
runs-on: windows-latest
48+
timeout-minutes: 40
49+
steps:
50+
- uses: actions/checkout@v2
51+
- name: 'x64-uwp(Debug)'
52+
uses: lukka/run-cmake@v10
53+
with:
54+
configurePreset: 'x64-uwp'
55+
buildPreset: 'x64-uwp-dbg'
56+
- name: 'x64-uwp(Release)'
57+
uses: lukka/run-cmake@v10
58+
with:
59+
configurePreset: 'x64-uwp'
60+
buildPreset: 'x64-uwp-rel'
61+
- name: 'arm64-uwp(Debug)'
62+
uses: lukka/run-cmake@v10
63+
with:
64+
configurePreset: 'arm64-uwp'
65+
buildPreset: 'arm64-uwp-dbg'
66+
- name: 'arm64-uwp(Release)'
67+
uses: lukka/run-cmake@v10
68+
with:
69+
configurePreset: 'arm64-uwp'
70+
buildPreset: 'arm64-uwp-rel'
4671
cmake-android:
4772
strategy:
4873
matrix:

CMakeLists.txt

+10-6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ IF(NOT CMAKE_SYSTEM_NAME)
7777
"Target operating system is not specified. "
7878
"cpuinfo will compile, but cpuinfo_initialize() will always fail.")
7979
SET(CPUINFO_SUPPORTED_PLATFORM FALSE)
80-
ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS|Darwin|Linux|Android)$")
80+
ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|WindowsStore|CYGWIN|MSYS|Darwin|Linux|Android)$")
8181
IF(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14" AND NOT CMAKE_SYSTEM_NAME STREQUAL "iOS")
8282
MESSAGE(WARNING
8383
"Target operating system \"${CMAKE_SYSTEM_NAME}\" is not supported in cpuinfo. "
@@ -141,7 +141,7 @@ IF(CPUINFO_SUPPORTED_PLATFORM)
141141
src/x86/linux/cpuinfo.c)
142142
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
143143
LIST(APPEND CPUINFO_SRCS src/x86/mach/init.c)
144-
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS)$")
144+
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "^(Windows|WindowsStore|CYGWIN|MSYS)$")
145145
LIST(APPEND CPUINFO_SRCS src/x86/windows/init.c)
146146
ENDIF()
147147
ELSEIF(CPUINFO_TARGET_PROCESSOR MATCHES "^(armv[5-8].*|aarch64|arm64)$" OR IOS_ARCH MATCHES "^(armv7.*|arm64.*)$")
@@ -171,7 +171,7 @@ IF(CPUINFO_SUPPORTED_PLATFORM)
171171
LIST(APPEND CPUINFO_SRCS
172172
src/arm/android/properties.c)
173173
ENDIF()
174-
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CPUINFO_TARGET_PROCESSOR STREQUAL "ARM64")
174+
ELSEIF((CMAKE_SYSTEM_NAME MATCHES "^Windows") AND CPUINFO_TARGET_PROCESSOR STREQUAL "ARM64")
175175
LIST(APPEND CPUINFO_SRCS src/arm/windows/init-by-logical-sys-info.c)
176176
LIST(APPEND CPUINFO_SRCS src/arm/windows/init.c)
177177
ENDIF()
@@ -211,10 +211,14 @@ ADD_LIBRARY(cpuinfo_internals STATIC ${CPUINFO_SRCS})
211211
CPUINFO_TARGET_ENABLE_C99(cpuinfo)
212212
CPUINFO_TARGET_ENABLE_C99(cpuinfo_internals)
213213
CPUINFO_TARGET_RUNTIME_LIBRARY(cpuinfo)
214-
IF(CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS)$")
214+
IF(CMAKE_SYSTEM_NAME MATCHES "^(Windows|WindowsStore|CYGWIN|MSYS)$")
215215
# Target Windows 7+ API
216-
TARGET_COMPILE_DEFINITIONS(cpuinfo PRIVATE _WIN32_WINNT=0x0601)
217-
TARGET_COMPILE_DEFINITIONS(cpuinfo_internals PRIVATE _WIN32_WINNT=0x0601)
216+
TARGET_COMPILE_DEFINITIONS(cpuinfo PRIVATE _WIN32_WINNT=0x0601 _CRT_SECURE_NO_WARNINGS)
217+
TARGET_COMPILE_DEFINITIONS(cpuinfo_internals PRIVATE _WIN32_WINNT=0x0601 _CRT_SECURE_NO_WARNINGS)
218+
# Explicitly link Kernel32 for UWP build
219+
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
220+
TARGET_LINK_LIBRARIES(cpuinfo PUBLIC Kernel32)
221+
endif()
218222
ENDIF()
219223
SET_TARGET_PROPERTIES(cpuinfo PROPERTIES PUBLIC_HEADER include/cpuinfo.h)
220224
TARGET_INCLUDE_DIRECTORIES(cpuinfo BEFORE PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

CMakePresets.json

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"version": 3,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 21,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "x64-uwp",
11+
"displayName": "x64(uwp)",
12+
"generator": "Visual Studio 17 2022",
13+
"architecture": "x64",
14+
"binaryDir": "${sourceDir}/build/x64-uwp",
15+
"installDir": "${sourceDir}/install",
16+
"cacheVariables": {
17+
"CPUINFO_BUILD_UNIT_TESTS": false,
18+
"CPUINFO_BUILD_MOCK_TESTS": false,
19+
"CPUINFO_BUILD_BENCHMARKS": false,
20+
"CMAKE_SYSTEM_NAME": "WindowsStore",
21+
"CMAKE_SYSTEM_VERSION": "10.0",
22+
"CMAKE_SYSTEM_PROCESSOR": "x86_64"
23+
},
24+
"condition": {
25+
"type": "equals",
26+
"lhs": "${hostSystemName}",
27+
"rhs": "Windows"
28+
}
29+
},
30+
{
31+
"name": "arm64-uwp",
32+
"displayName": "arm64(uwp)",
33+
"inherits": "x64-uwp",
34+
"architecture": "ARM64",
35+
"binaryDir": "${sourceDir}/build/arm64-uwp",
36+
"cacheVariables": {
37+
"CMAKE_SYSTEM_PROCESSOR": "ARM64"
38+
}
39+
}
40+
],
41+
"buildPresets": [
42+
{
43+
"name": "x64-uwp-dbg",
44+
"configurePreset": "x64-uwp",
45+
"configuration": "Debug"
46+
},
47+
{
48+
"name": "x64-uwp-rel",
49+
"configurePreset": "x64-uwp",
50+
"configuration": "Release"
51+
},
52+
{
53+
"name": "arm64-uwp-dbg",
54+
"configurePreset": "arm64-uwp",
55+
"configuration": "Debug"
56+
},
57+
{
58+
"name": "arm64-uwp-rel",
59+
"configurePreset": "arm64-uwp",
60+
"configuration": "Release"
61+
}
62+
]
63+
}

src/x86/name.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ uint32_t cpuinfo_x86_normalize_brand_string(
581581
/* Iterate through all tokens and erase redundant parts */
582582
{
583583
bool is_token = false;
584-
char* token_start;
584+
char* token_start = NULL;
585585
for (char* char_ptr = name; char_ptr != name_end; char_ptr++) {
586586
if (*char_ptr == ' ') {
587587
if (is_token) {
@@ -619,7 +619,7 @@ uint32_t cpuinfo_x86_normalize_brand_string(
619619
/* Compact tokens: collapse multiple spacing into one */
620620
{
621621
char* output_ptr = normalized_name;
622-
char* token_start;
622+
char* token_start = NULL;
623623
bool is_token = false;
624624
bool previous_token_ends_with_dash = true;
625625
bool current_token_starts_with_dash = false;

0 commit comments

Comments
 (0)