# How to process .mc files in CMakeLists.txt

**URL:** <https://discourse.cmake.org/t/how-to-process-mc-files-in-cmakelists-txt/3102>\
**Category:** Code\
**Created:** [April 8, 2021, 8:59am UTC](https://discourse.cmake.org/t/how-to-process-mc-files-in-cmakelists-txt/3102 "2021-04-08T08:59:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bart\_Vandewoestyne](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bart_vandewoestyne/32/1351_2.png) [@Bart\_Vandewoestyne](https://discourse.cmake.org/u/Bart_Vandewoestyne)\
**Post date:** [April 8, 2021, 8:59am UTC](https://discourse.cmake.org/t/how-to-process-mc-files-in-cmakelists-txt/3102/1 "2021-04-08T08:59:28Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [April 8, 2021, 9:56am UTC](https://discourse.cmake.org/t/how-to-process-mc-files-in-cmakelists-txt/3102/2 "2021-04-08T09:56:59Z")

</div>

Message compiler is not supported natively by `CMake`.  
You have to rely on [add\_custom\_command()](https://cmake.org/cmake/help/latest/command/add_custom_command.html) and [add\_custom\_target()](https://cmake.org/cmake/help/latest/command/add_custom_target.html) 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.
