Development/Tools/Automoc4: Difference between revisions

From KDE TechBase
No edit summary
Line 11: Line 11:


  set(foobar_srcs main.cpp foobar.cpp)
  set(foobar_srcs main.cpp foobar.cpp)
automoc4_add_executable(foobar ${foobar_srcs})
The last line expands to
automoc4(foobar foobar_srcs)
add_executable(foobar ${foobar_srcs})
on all platform, except when using MSVC, then it'll expand to
  add_automoc4_target(foobar_automoc foobar_srcs)
  add_automoc4_target(foobar_automoc foobar_srcs)
  add_executable(foobar ${foobar_srcs})
  add_executable(foobar ${foobar_srcs})
  add_dependencies(foobar foobar_automoc)
  add_dependencies(foobar foobar_automoc)
The automoc4 macro adds a custom command that outputs a source file that is then added to the sources for the target. (This breaks with nmake as that gets the timestamp of the output file wrong and then recompiles and relinks every time.)


The add_automoc4_target macro adds a new target, which, when called, generates all moc files and a source file to include those when needed and adds the name of that source file to foobar_srcs.
The add_automoc4_target macro adds a new target, which, when called, generates all moc files and a source file to include those when needed and adds the name of that source file to foobar_srcs.
Line 19: Line 30:
The add_dependencies macro tells cmake to add a dependency such that foobar only gets called after foobar_automoc is done.
The add_dependencies macro tells cmake to add a dependency such that foobar only gets called after foobar_automoc is done.


When using KDE4 cmake macros then don't worry about all this. Instead just use the kde4_add_executable macro.
'''When using the KDE4 cmake macros then don't worry about all this. Instead just use the kde4_add_{executable,library,plugin} macros.'''


==Command Line Usage==
==Command Line Usage==

Revision as of 22:52, 16 August 2008

Usage in CMakeLists.txt

You should not use the automoc4 executable directly. Instead use the FIND_PACKAGE() command to use Automoc4 in your CMakeLists.txt (best use FindAutomoc4.cmake). Then you can add two lines per target to your CMakeLists.txt and you never need to worry about moc files anymore:

set(foobar_srcs main.cpp foobar.cpp)
add_executable(foobar ${foobar_srcs})

then becomes

find_package(Automoc4 REQUIRED)
set(foobar_srcs main.cpp foobar.cpp)
automoc4_add_executable(foobar ${foobar_srcs})

The last line expands to

automoc4(foobar foobar_srcs)
add_executable(foobar ${foobar_srcs})

on all platform, except when using MSVC, then it'll expand to

add_automoc4_target(foobar_automoc foobar_srcs)
add_executable(foobar ${foobar_srcs})
add_dependencies(foobar foobar_automoc)

The automoc4 macro adds a custom command that outputs a source file that is then added to the sources for the target. (This breaks with nmake as that gets the timestamp of the output file wrong and then recompiles and relinks every time.)

The add_automoc4_target macro adds a new target, which, when called, generates all moc files and a source file to include those when needed and adds the name of that source file to foobar_srcs.

The add_dependencies macro tells cmake to add a dependency such that foobar only gets called after foobar_automoc is done.

When using the KDE4 cmake macros then don't worry about all this. Instead just use the kde4_add_{executable,library,plugin} macros.

Command Line Usage

Features

When are which files generated

Limitations