fix: define M_PI for MSVC builds#18
Merged
Merged
Conversation
M_PI is not declared by <cmath> on MSVC unless _USE_MATH_DEFINES is set before the header. Define it (plus an #ifndef M_PI fallback) in fft.cpp and mel_gpu.cpp, and add _USE_MATH_DEFINES as a PUBLIC MSVC compile definition on the parakeet target so the test executables that also use M_PI build too. Non-MSVC builds are unaffected. Closes mudler#6 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Thanks @mudler for landing this. M_PI defined for MSVC means Windows builds work out of the box. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On MSVC,
M_PIis not declared by<cmath>unless_USE_MATH_DEFINESis defined before the header is included, so the build fails withidentifier "M_PI" is undefined(#6). The constant is used insrc/fft.cpp,src/mel_gpu.cpp, and the test sources.Fix
src/fft.cppandsrc/mel_gpu.cpp, define_USE_MATH_DEFINESbefore<cmath>and add an#ifndef M_PIfallback, so the library sources compile regardless of toolchain or include ordering.CMakeLists.txt, add_USE_MATH_DEFINESfor MSVC as aPUBLICcompile definition on theparakeettarget.PUBLIC(rather thanPRIVATE) propagates it to consumers that link the library, so the test executables built with-DPARAKEET_BUILD_TESTS=ON(test_fft,test_audio_io,test_mel_gpu, which also useM_PI) get the define as well.Non-MSVC builds are unaffected: the generator expression only emits the define for
CXX_COMPILER_ID:MSVC, and the#ifndefguards are no-ops whereM_PIis already provided.Testing
PUBLICdefinition reaches the test targets throughtarget_link_libraries(<test> PRIVATE parakeet).Closes #6
AI was used for assistance.