How to generate moc_*.cpp files using CMake

4.2k views Asked by At

Suppose I have a C++ file named animals.cpp. How can I generate a moc file (moc_animals.cpp) using CMake?

2

There are 2 answers

2
Stefano On BEST ANSWER

There are multiple ways. if you are using CMAKE version grater than 2.8.6 then you can use AUTOMOC which should do everything automatically for you.

Here there is a nice tutorial.

As pointed out by @spectras this assumes respecting their naming convention. If you want to use your specific naming you can of course use the manual mechanism by simple calling qt4_wrap_cpp or qt5_wrap_cpp. This is also what you should do in case you are bound to older CMAKE versions.

0
Paltoquet On

In the bin directory of your Qt installation there is the moc command.

/Users/name/Qt 5.7/...../bin

If you add it with execute_process() or add_custom_command() you should be able to do what you intend to do. You can use AUTOMOC too