Neverendingo (Talk | contribs) m (Text replace - "<code cppqt>" to "<syntaxhighlight lang="cpp-qt">") |
Neverendingo (Talk | contribs) m (Text replace - "</code>" to "</syntaxhighlight>") |
||
| Line 61: | Line 61: | ||
Q_OBJECT | Q_OBJECT | ||
}; | }; | ||
| − | </ | + | </syntaxhighlight> |
foo.cpp: | foo.cpp: | ||
<syntaxhighlight lang="cpp-qt"> | <syntaxhighlight lang="cpp-qt"> | ||
| Line 70: | Line 70: | ||
#include "foo.moc" | #include "foo.moc" | ||
#include "moc_foo.cpp" | #include "moc_foo.cpp" | ||
| − | </ | + | </syntaxhighlight> |
In that case two moc files will be created, moc_foo.cpp from foo.h and foo.moc from foo.cpp. | In that case two moc files will be created, moc_foo.cpp from foo.h and foo.moc from foo.cpp. | ||
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.
automoc4 <output file> <current source dir>
<current binary dir> <moc executable>
<cmake executable> [--touch]
The output file tells automoc4 how the source file that contains the #include lines of the moc files that are not included in any other source files of the target is called. It also uses this file name and appends .files to find the other variables set by the cmake macro. (i.e. it reads <current source dir>/<output file>.files and creates <current binary dir>/<output file>)
The moc executable is the full filepath to the executable, so that automoc4 can reuse this information.
The cmake executable is also the full filepath and is used for colored status output.
The --touch switch tells automoc4 to update the timestamp of <current source dir>/<output file>.files after it touched <current binary dir>/<output file>. This ensures that automoc4 always gets called for every target. This switch is not needed if automoc4 is used as an extra target, since in that case it will be called unconditionally already.
automoc4 is passed a list of files to process. For most cases this is a list of only source files (no headers) (i.e. the sources list variable used in the CMakeLists.txt file).
A moc file is created if ...
Invalid language.
You need to specify a language like this: <source lang="html4strict">...</source>
Supported languages for syntax highlighting:
4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic