Skip to content

CMake: fix MSVC static library flags for Windows ARM64#218

Merged
ajelenak merged 1 commit intoHDFGroup:masterfrom
Harishmcw:win_arm64
Feb 3, 2026
Merged

CMake: fix MSVC static library flags for Windows ARM64#218
ajelenak merged 1 commit intoHDFGroup:masterfrom
Harishmcw:win_arm64

Conversation

@Harishmcw
Copy link
Contributor

@Harishmcw Harishmcw commented Jan 28, 2026

This PR fixes MSVC static library build issues on Windows ARM64.

Currently, the build forces /machine:x64, which causes linker failures when compiling HDF5 natively on ARM64.

Changes

Select /machine flag based on target architecture:

  • x64 → /machine:x64
  • ARM64 → /machine:ARM64

Important

Fixes MSVC static library build issue on Windows ARM64 by selecting appropriate /machine flag based on architecture in zlib-CMakeLists.txt and LZF CMakeLists.txt.

  • Behavior:
    • Fixes MSVC static library build issue on Windows ARM64 by selecting /machine flag based on target architecture in zlib-CMakeLists.txt and CMakeLists.txt for LZF.
    • Uses /machine:x64 for x64 and /machine:ARM64 for ARM64.
  • Files:
    • zlib-CMakeLists.txt: Adjusts set_target_properties for zlibstat.
    • CMakeLists.txt for LZF: Adjusts set_target_properties for ${LZF_LIB_TARGET}.

This description was created by Ellipsis for f9ce6b6. You can customize this summary. It will automatically update as commits are pushed.

add_library(zlibstat STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
if (MSVC AND CMAKE_CL_64)
set_target_properties (zlibstat PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
if (MSVC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than just removing the checking of CMAKE_CL_64, it looks like the logic should be checking CMAKE_SIZEOF_VOID_P in this case

if (MSVC AND CMAKE_CL_64)
set_target_properties (zlibstat PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
if (MSVC)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|x86_64)$")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on https://gitlab.kitware.com/cmake/cmake/-/issues/25466 and https://gitlab.kitware.com/cmake/cmake/-/issues/15170, it seems like using CMAKE_SYSTEM_PROCESSOR here may also not give the expected results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. Based on the discussion in CMake Issue #15170, CMAKE_C_COMPILER_ARCHITECTURE_ID is suggested as the reliable alternative for Windows since it's set after the compiler probe.

I have updated the PR to use this variable along with the CMAKE_SIZEOF_VOID_P check. Could you please review the changes.

@ajelenak ajelenak merged commit b9906bf into HDFGroup:master Feb 3, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants