How to process .mc files in CMakeLists.txt

I am currently converting some legacy build system based on Perl scripts and qmake files to CMake, and came across the following issue:

In our C++ code, we include a file FooBar.h, but there is only a FooBar.mc file in the sources. When looking at the Perl scripts, the FooBar.mc file is processed as follows:

mc FooBar.mc
rc -r -fo FooBar.res FooBar.rc
link -nologo -dll -noentry /MACHINE:X86 -out:FooBar.dll FooBar.res

If I’m correct, the header file is a by-product of the first step (using the Message Compiler mc).

Now my question is how I do all this in my CMakeLists.txt file. I tried simply adding the FooBar.mc file to my list of sources in my add_library command as follows:

add_library(SomeLib SHARED
    ....
    FooBar.mc
    ....
)

but that didn’t work.

Any hints to point me in the right direction are highly appreciated!

Message compiler is not supported natively by CMake.
You have to rely on add_custom_command() and add_custom_target() commands to implement the compilation of mc file into rc file.
And you can add the rc file to the sources of the library because CMake is able to handle resource files.