[CMake] CMake with IDL file generation

Petr Kmoch petr.kmoch at gmail.com
Tue Sep 11 03:13:54 EDT 2012


Hi Robert.

What you're after is pretty standard cmake. You'll need

add_custom_command(
  OUTPUT path_to/generated_header.h path_to/generated_source.cpp
  COMMAND midl.exe arguments to midl
  other options of add_custom_command as necessary
)
# as many times as necessary (probably once per IDL source file)

Then, you can use the generated sources in add_library/add_executable
calls as normal, e.g.
add_executable(UsesIDL path_to/some_source.cpp
path_to/generated_header.h path_to/generated_source.cpp)

cmake knows internally when a source file is generated by a custom
command and does not require the file to be present at generation time
in such case.

The above assumes all files generated from IDL are used in subsequent
library/executable targets (or if they are not, they don't need to be
generated). If you need to run MIDL to generate files which are not
used anywhere else in the build, you will need to add_custom_target()
which uses these files as SOURCES.

Hope this helps.

Petr

On Tue, Sep 11, 2012 at 1:38 AM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
> I'm creating a shared library target that needs to compile and include
> source generated by an IDL. I want CMake to create a custom target
> that will invoke MIDL.EXE (comes with Windows SDK) against the IDL
> file to generate the header / source files needed. These header/source
> files will then be built by the shared library target. I saw a similar
> post on this here:
>
> http://www.cmake.org/pipermail/cmake/2011-July/045617.html
>
> This seems complicated and I'm not sure it even works, since from my
> tests, if source files don't exist by the time add_library,
> add_executable, etc is called, generation will fail. I also don't want
> CMake to invoke MIDL for me since that would require us to run CMake
> again every time the IDL file changes (this shouldn't be the case, we
> should just have to rebuild the target again using Visual Studio or
> NMake).
>
> Any ideas on a simple solution to this?
>
> Thanks in advance.
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list