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.
- CMake 3.0 or higher
- MIDL compiler
- Tlbimp.exe (optional)
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 file
Example:
add_idl(GreeterIDL Greeter.idl)
The function does the same work as MIDL, specifically generates files:
- Greeter_i.h
- Greeter_i.c
- Greeter_p.c
- Greeter.tlb
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 target
Example:
add_idl(GreeterIDLWithTLBIMP Greeter.idl TLBIMP GreeterInterop)
The function does the same work as MIDL and tlbimp.exe, specifically generates files:
- Greeter_i.h
- Greeter_i.c
- Greeter_p.c
- Greeter.tlb
- GreeterInterop.dll
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.
- New: Add
TLBIMP_FLAGS
- New: Add tlbimp
- Initial public release