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

Global compile options are missing #21

Open SpriteOvO opened 3 years ago

SpriteOvO commented 3 years ago

Simplified example:

top-level CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(FindWDK_IssueTest)

add_compile_options("/MP")

add_subdirectory(Exe)
add_subdirectory(Sys)

Exe CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(FindWDK_IssueTest_Exe)

add_executable(FindWDK_IssueTest_Exe Main.cpp)

Sys CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

project(FindWDK_IssueTest_Sys)

find_package(WDK REQUIRED)

wdk_add_driver(FindWDK_IssueTest_Sys Main.cpp)

So, I added a compile option /MP to the top-level CMakeLists.txt and want it to work on all subdirectories. But when I open the generated solution, I see that the compile option only applies to the project Exe and not both. image image

Of course, there is a workaround:

top-level CMakeLists.txt:

set(MY_GLOBAL_COMPILE_OPTIONS "/MP")
add_compile_options(${MY_GLOBAL_COMPILE_OPTIONS})

Sys CMakeLists.txt:

wdk_add_driver(FindWDK_IssueTest_Sys Main.cpp)
target_compile_options(FindWDK_IssueTest_Sys PRIVATE ${MY_GLOBAL_COMPILE_OPTIONS})

It works, but obviously not so elegantly.

I personally think this is a bug. So, I was wondering if it is possible for FindWDK to keep global compile options that are safe for driver projects?

Thanks in advance!

SergiusTheBest commented 3 years ago

I agree with you. But the question is which compile options are safe for driver projects? Probably it will be wise to add only popular options.

SpriteOvO commented 3 years ago

Probably it will be wise to add only popular options.

Yes, my words in the OP were a bit inaccurate, that was just the result I wanted to see, not the solution.

It might be good to use the properties of the solution generated by the VS WDK wizard as a reference. That is, just adding the necessary properties and setting default preprocessor definitions for TARGET.

We can also consider adding a default value to some known properties if they would obviously conflict with the WDK project.

I made this attempt a few days ago, but I got stuck at the beginning.

I tried to fix the Configuration Type and Platform Toolset, but after that I had to change the Windows SDK Version to $(LatestTargetPlatformVersion), because I installed Windows SDK 10.0.18362.0 and 10.0.19041.0, but the WDK only has 10.0.18362.0 installed, so the default value of the Windows SDK Version generated by CMake does not compile for me. And I have tried many ways to do this, but at present it seems impossible to do it from CMake.