Skip to content

Fix SHMath CMake build on non-Windows platforms - #348

Open
Joel Kiptoo (Kiptoo-Deus) wants to merge 1 commit into
microsoft:mainfrom
Kiptoo-Deus:fix-shmath-nonwindows-build
Open

Joel Kiptoo (Kiptoo-Deus) wants to merge 1 commit into
microsoft:mainfrom
Kiptoo-Deus:fix-shmath-nonwindows-build

Conversation

@Kiptoo-Deus

Copy link
Copy Markdown

Fixes #346.

Two problems stop SHMath from building on non-Windows platforms.

sal.h include directory lost on reconfigure. target_include_directories(... sal) was inside if((NOT WIN32) AND (NOT EXISTS ".../sal/sal.h")), so it was only added in the configure run that downloaded the file. Running CMake again on the same build directory skipped the block, the -I.../SHMath/sal flag disappeared from the build, and DirectXSH.cpp failed to compile. The include directory is now added whenever the build is not on Windows, and only the download is guarded by NOT EXISTS.

On the first point in the issue: I left the download in the build directory, since that keeps generated files out of the source tree.

/ZH:SHA_256 passed to non-MSVC Clang. The Clang|IntelLLVM branch added /ZH:SHA_256 for Clang 16 and later, which is only valid for clang-cl. Apple Clang (and Clang on Linux) treat it as a file name, so the first build already failed with:

clang++: error: no such file or directory: '/ZH:SHA_256'

It is now only added when CMAKE_CXX_COMPILER_FRONTEND_VARIANT is MSVC. -Wno-unsafe-buffer-usage is still added for all Clang 16+.

Testing

On macOS (arm64) with Apple Clang 21 and GCC 15.1, -DBUILD_SHMATH=ON:

configure + build configure again + rebuild sal include after reconfigure sal.h downloaded again
before (Apple Clang) build fails (/ZH:SHA_256) build fails missing no
after (Apple Clang) OK OK present no
after (GCC 15) OK OK present no

A small program linked against the built library gets the expected values from XMSHEvalDirection for +Z (Y00 = 0.282095, Y10 = 0.488603).

I couldn't test clang-cl or MSVC here; the change keeps /ZH:SHA_256 for clang-cl and doesn't touch the MSVC branch. SHMath is currently only built by the Windows workflows, which is probably why this wasn't caught.

The sal.h include directory was only added in the configure run that
downloaded sal.h. Reconfiguring an existing build directory skipped the
whole block, so the include path was lost and DirectXSH.cpp no longer
compiled. Add the include directory whenever the build is not on
Windows, and only guard the download itself.

/ZH:SHA_256 was added for all Clang compilers version 16 and later, but
it is only valid for clang-cl. Apple Clang and Clang on Linux fail with
"no such file or directory: '/ZH:SHA_256'". Only add it when Clang uses
the MSVC command-line frontend.

Fixes microsoft#346
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

Issues with including "sal.h"

1 participant