CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp
CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp.
IDL is used for creating COM servers. Unfortunately CMake has a limited support for IDL, so this module comes to rescue. The Type Library Importer (Tlbimp) converts the type definitions found within a COM type library (TLB) into equivalent definitions in a common language runtime assembly. The output of Tlbimp.exe is a binary file (an assembly) that contains runtime metadata for the types defined within the original type library.
Add FindIDL to the module search path and call find_package
:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake")
find_package(IDL REQUIRED)
FindIDL will search for midl.exe and tlbimp.exe
Takes two arguments: the name of the target project and idl file.
add_idl(<name> source)
Where:
<name>
- name of the target projectsource
- full path to idl fileExample:
add_idl(GreeterIDL Greeter.idl)
The function does the same work as MIDL, specifically generates files:
To use the generated files the idl project should be linked as following
target_link_libraries(Main GreeterIDL)
Takes four arguments: the name of the target project, idl file, TLBIMP flag and the name of the tlbimp target.
add_idl(<name> source TLBIMP <tlbimp name>)
Where:
<name>
- name of the target projectsource
- full path to idl fileTLBIMP
- flag to indicate to run tlbimp<tlbimp name>
- name of the tlbimp targetExample:
add_idl(GreeterIDLWithTLBIMP Greeter.idl TLBIMP GreeterInterop)
The function does the same work as MIDL and tlbimp.exe, specifically generates files:
To use the generated files the idl project should be linked as following
target_link_libraries(MainCpp GreeterIDL)
Or if you want to use the file generated by tlbimp:
target_link_libraries(MainCsharp GreeterInterop)
To specify additional command-line options for midl set MIDL_FLAGS
variabe.
set(MIDL_FLAGS /target NT60) # avoid MIDL2455 error
To specify additional command-line options for tlbimp set TLBIMP_FLAGS
variabe.
set(TLBIMP_FLAGS /silence:3002) # importing a type library into a platform agnostic assembly
Take a look at the samples folder to see how to use FindIDL.
Apriorit released FindIDL under the OSI-approved 3-clause BSD license. You can freely use it in your commercial or opensource software.
TLBIMP_FLAGS