kcat / openal-soft

OpenAL Soft is a software implementation of the OpenAL 3D audio API.
Other
2.21k stars 535 forks source link

Error while building with MSVC2022 and CMake PCH: error C1021: #warning preprocessor #629

Closed ghidosoft closed 2 years ago

ghidosoft commented 2 years ago

I'm getting this error when building using MSVC2022 (using openal-soft in a CMake project):

external\openal-soft\core\cpu_caps.cpp(115): fatal error C1021: invalid preprocessor command 'warning'

The strange thing is that it happens only if I enable precompiled headers in cmake and add <AL/al.h> and <AL/alc.h> to the PCH with: target_precompile_headers(myaudiolibrary PRIVATE <various-stl-headers...> <AL/al.h> <AL/alc.h>).

If I simply include those headers in the relevant .cpp files it works (and the OpenAL32.dll library get built regardless of the above problem). Am I missing something obvious?

Thanks.

kcat commented 2 years ago

That is definitely odd. warning is supposed to be a well-supported (if non-standard) directive. I suppose precompiled headers are causing it to fail to recognize the HAVE_CPUID_INTRINSIC macro, or it's computing the different paths the macros can cause it to take and running into the #warning it otherwise wouldn't. I don't see why having al.h and alc.h in the precompiled headers would cause that, though.

ghidosoft commented 2 years ago

I fear that it was a transient problem caused by CMake cache and Visual Studio: after the n-th restart of Visual Studio and CMake cache reconfiguration now it works correctly, without any further changes to CMakeLists.txt.

Looking at the code of cpu_caps.cpp the intellisense reported that no CMake compiler flags were defined, so it was definitely a CMake issue causing the compiler to not recognize that intrin.h and cpuid where available.

I'm sorry for bothering you with a moot issue, thanks nonetheless for the support.