MarkSchofield / WindowsToolchain

A repository containing a CMake toolchain for using MSVC
MIT License
106 stars 19 forks source link

Add an example that builds .asm files #118

Closed MarkSchofield closed 3 weeks ago

MarkSchofield commented 3 weeks ago

117 fixed a bug in ASM_MASM usage - the Windows SDK's include paths should be added for the ASM_MASM language, so that .asm files can correctly find MASM .inc files that are shipped in the Windows SDK. This PR adds an 'example', so that it shows that things work, and makes sure that there's no regressions.

This change adds an 'example/CommandLineAsm' folder, with a simple example. A single function - CallAsmCode - is implemented in assembly. It takes no parameters, and returns the value 42. And there's a 'main' that calls the function and prints out the value. I've added implementations for ASM_MASM (on X86 and AMD64), and I've added an example for ASM_MARMASM, which is used on ARM64. But the ARM64 example is a little broken. The ARM64 include files (for example kxarm64.h) contain C-pre-processor directives that the ASM_MARMASM assembly doesn't support, because the headers expect the assembly files to have been pre-processed by a C preprocessor first. Looking at the Visual Studio support for MARMASM (in, say, MSBuild\Microsoft\VC\v170\BuildCustomizations\marmasm.props and MSBuild\Microsoft\VC\v170\BuildCustomizations\marmasm.targets) shows the invocation of the Cl pre-processor first. But with a non-Visual Studio generator, the CMake logic just runs the ARM assembler, without running, say, $(CMAKE_C_COMPILER). I don't know of a way to 'fix' this from a WindowsToolchain level - it seems to be a gap in the CMake support for ASM_MARMASM. With all that being said, I could be missing something. Does anyone have any insights that could shed some light here?

Tagging @waldnercharles (who filed #115) and @paulfd (who fixed #115 with #117), in case they have any ideas.

paulfd commented 3 weeks ago

Sorry I don't have much experience in windows ASM at all... Seems like it could be a cmake thing to fix though. I know gcc runs preprocessor on .S files automatically.