"Link" to user32.dll in cmake when compile under Linux (cross)
<p>I'm using mingw under Linux and I'm trying to compile for Windows. I'm using CMake and the ouptut should be an .exe file.
In my program I'm using a WinAPI call (RegisterPowerSettingNotification) which is found in user32.dll/user32.lib. I want to have my .exe independent of the user32.dll version (my .exe should run on Windows8/8.1/10).</p>

<p>My CmakeLists.txt:</p>

<pre><code>include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${USBHID_HEADER}
    )
#USER32 // Will find the user32.lib
find_library(USER32 user32)
list(APPEND USBHID_LIB_DEPS ${USER32})
find_path(USBHID_HEADER winuser.h)
list(APPEND INCLUDES ${USBHID_HEADER})

# add the executable
add_executable( myexe win_service.c resource.rc )
target_link_libraries( myexe LINK_PUBLIC ${USBHID_LIB_DEPS} )
set_target_properties( myexe PROPERTIES OUTPUT_NAME "MyExeService" )
install( TARGETS myexe DESTINATION bin)
</code></pre>

<p>When I'm compiling, I'm receiving a warning:</p>

<pre><code>/.../win_service.c:182:27: warning: assignment makes pointer from integer without a cast [enabled by default]
lidcloseRegHandle = RegisterPowerSettingNotification(serviceStatusHandle, &amp;GUID_LIDCLOSE_ACTION,...
</code></pre>

<p>and at linking time:</p>

<pre><code>Linking C executable myexeservice.exe
CMakeFiles/myexeservice.dir/objects.a(win_service.c.obj):win_service.c:(.text+0x393): undefined reference to `RegisterPowerSettingNotification'
collect2: error: ld returned 1 exit status
</code></pre>

<p>I know that linking against a DLL makes no sense, but how can I fool the CMake to not look after RegisterPowerSettingNotification?</p>