Hi all,

I figured I would dig up this question as I found a decent solution to this
issue.

After having a look at how Microsoft Visual Studio is doing to include
references to external libraries, I came to realise that it is using a tool
called TlbImp, which is short for Type Library Importer.

The solution is pretty simple from there: use TlbImp to generate a library
that CSharp will be able to import and add it via CMake to the project. My
code for Windows Media Player boils down to this:

set(_outLib ${CMAKE_CURRENT_BINARY_DIR}/generated/Interop.WMPLib.dll)
execute_process(COMMAND ${TLBIMP_EXECUTABLE} ${WMP_LIBRARY}
/namespace:WMPLib /out:${_outLib}
RESULT_VARIABLE tlbimp_result
ERROR_FILE ${CMAKE_CURRENT_BINARY_DIR}/tlbimp_log.txt
)

set_target_properties(myproject
VS_DOTNET_REFERENCES "WMPLib"
VS_DOTNET_REFERENCEPROP_WMPLib_TAG_HintPath "${_outLib}"
)

And there you have it!

If you would like to see it used in a project, I have just uploaded a small
project to my github that uses just that: https://github.com/
cyrilBoucher/space-invaders

Hope this helps!
Cyril Boucher

2018-02-01 21:57 GMT+01:00 Cyril Boucher <[email protected]>:

> Hi all,
>
> I am trying to use CMake and the CSharp support for a small project of
> mine but I cannot seem to find a way to add a reference to the Windows
> Media Player library. One of the reason for that is that I need to link my
> project to wmp.dll which then needs to generate Interop.WMPLib.dll and a
> reference needs to be added with its path pointing to the latter library.
>
> Adding wmp.dll to my project is as simple as a target_link_libraries call
> but this does not seem to trigger the whole generation and add reference
> sort of process.
>
> Has anyone ever had an experience with adding such libraries? Is there
> support for these scenarios?
>
> Thanks!
> Cyril Boucher
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to