SergiusTheBest / FindWDK

CMake module for building drivers with Windows Development Kit (WDK)
BSD 3-Clause "New" or "Revised" License
251 stars 53 forks source link

CRT is not usable from WDK libraries (only the main driver project #16

Closed TheJCAB closed 4 years ago

TheJCAB commented 4 years ago

The fix from #12 just needs to be also applied to wdk_add_library. Looks like an oversight.

TheJCAB commented 4 years ago

I should be more specific. If you compile a driver, with wdk_add_driver, it'll use ${WDK_VERSION}/km/crt CRT (the intended one). As long as you don't use stuff you shouldn't that's all good.

If you compile a library for inclusion in drivers, with wdk_add_library, it will use the ${WDK_VERSION}/ucrt to find all (well... many - some are under MSVC's directory tree) CRT headers. This... works to some extent. But regardless, it means it'll use different definitions for the library than for the driver itself.

The solution is simple, and I'm preparing a PR for it.

Note, however, that using ${WDK_VERSION}/km/crt as the primary CRT directory means that, if you accidentally (and innocently) mix the wrong thing it, you're in for a world of compilation errors. For instance, this sequence:

include

include

It works fine from a library target, but not for a driver target.

The reason is that the ${WDK_VERSION}/ucrt directory remains in the compiler command-line. is unfortunately missing from the kernel mode CRT, so the ucrt one is used.

I already posed the question in another issue, but... what would it take to remove compilation/linker switches (and defines and include dirs and libs) out of WDK targets? I'm not that good of a CMake guru (yet?), so I'm not sure.

(and thank you, Sergei... this is awesome, regardless)