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

the plain signature for target_link_libraries has already been used with X #29

Open snweiss opened 10 months ago

snweiss commented 10 months ago

A "the plain signature for target_link_libraries has already been used with ..." error is generated when trying to add private link dependencies after a target was generated with wdk_add_driver :

wdk_add_driver(driver WINVER 0x0A00)
target_link_libraries(driver PRIVATE WDK::WDMSEC)

This can be workaround by just removing the "PRIVATE" option but our use-case is slightly more complex since the link dependencies are set by down-stream cmake infrastructure files that are shared among different projects.

This is the patch that we're currently using to mitigate the issue

diff --git a/FindWdk.cmake b/FindWdk.cmake
index 6987305..c5ba280 100644
--- a/FindWdk.cmake
+++ b/FindWdk.cmake
@@ -155,15 +155,15 @@ function(wdk_add_driver _target)
         "${WDK_ROOT}/Include/${WDK_INC_VERSION}/km/crt"
         )

-    target_link_libraries(${_target} WDK::NTOSKRNL WDK::HAL WDK::BUFFEROVERFLOWK WDK::WMILIB)
+    target_link_libraries(${_target} PRIVATE WDK::NTOSKRNL WDK::HAL WDK::BUFFEROVERFLOWK WDK::WMILIB)

     if(CMAKE_SIZEOF_VOID_P EQUAL 4)
-        target_link_libraries(${_target} WDK::MEMCMP)
+        target_link_libraries(${_target} PRIVATE WDK::MEMCMP)
     endif()

     if(DEFINED WDK_KMDF)
         target_include_directories(${_target} SYSTEM PRIVATE "${WDK_ROOT}/Include/wdf/kmdf/${WDK_KMDF}")
-        target_link_libraries(${_target}
+        target_link_libraries(${_target} PRIVATE
             "${WDK_ROOT}/Lib/wdf/kmdf/${WDK_PLATFORM}/${WDK_KMDF}/WdfDriverEntry.lib"
             "${WDK_ROOT}/Lib/wdf/kmdf/${WDK_PLATFORM}/${WDK_KMDF}/WdfLdr.lib"
             )
SergiusTheBest commented 10 months ago

Yes, target_link_libraries should be modernized to specify visibility (private, public, interface). Thanks for reporting!