2

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

Amani
  • 16,245
  • 29
  • 103
  • 153

2 Answers2

5

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.

Stefano
  • 3,981
  • 8
  • 36
  • 66
  • 1
    This is the correct way, if you follow the nomenclature that comes with it. If you don't for some reason, you may still resort to manual `qt4_wrap_cpp` or `qt5_wrap_cpp`. – spectras Sep 01 '17 at 07:36
  • yes... I will add your comment to my answer then... thanks! – Stefano Sep 01 '17 at 07:46
1

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

Paltoquet
  • 1,184
  • 1
  • 10
  • 18