Professional Documents
Culture Documents
http://leechcraft.org/development-cmake-cheatsheet
Search
About LeechCraft
News
Download
Plugins
Screenshots
Development
FAQ
Home Development Writing plugins About LeechCraft News Download Plugins Screenshots Development General Writing plugins Getting started Code style Architecture CMake cheatsheet Writing a simple plugin Having tabs Plugins for plugins Text completion Using notifications API docs Advanced Notifications Plugin-specific FAQ This cheatsheet contains solutions for typical tasks that a LeechCraft developer may face. We will mostly use code snippets from the CMakeLists.txt of the Auscrie plugin, which is listed fully at the end of the page.
CMake cheatsheet
Submitted by 0xd34df00d on Fri, 04/01/2011 - 01:40 Posted in development
Table of contents [hide] 1. Adding new source files 2. Handling .ui files 3. Adding resources 4. Adding translations 5. Installing arbitrary files 6. Adding Qt modules besides Core and GUI 7. CMakeLists.txt from the Auscrie plugin
Contact us Our team Issue tracker Friends and you've written a class, say, RequestBuilder with requestbuilder.h and requestbuilder.cpp header/implementation files, you should have: SET (SRCS auscrie.cpp shooterdialog.cpp poster.cpp requestbuilder.cpp ) SET (HEADERS auscrie.h shooterdialog.h poster.h requestbuilder.h )
User login
Username: *
Password: *
Log in
Log in using OpenID Create new account Request new password
Please note that you should pass the headers to the QT4_WRAP_CPP CMake macro for the moc'ed files to be generated, which is absolutely necessary for QObjects to work. For example, with the following command:
Languages English
the MOC_SRCS variable would contain the list of sources generated by the moc. It should be
1 of 4
8/22/2011 5:11 PM
http://leechcraft.org/development-cmake-cheatsheet
added as the dependency to your library, for example: ADD_LIBRARY (leechcraft_auscrie SHARED ... ${MOC_SRCS} ... )
Syndicate
Adding resources
To add the resources file, say, anheroresources.qrc, add the following to the CMakeLists.txt, before the ADD_LIBRARY call: SET (RESOURCES auscrieresources.qrc) QT4_ADD_RESOURCES (RCCS ${RESOURCES})
Don't forget to add the ${RCCS} to the list of dependencies for your library. For the above example with AnHero: ADD_LIBRARY (leechcraft_auscrie SHARED ... ${RCCS} ... )
Adding translations
Use the CreateTrVars macro defined in LeechCraft cmake files, like: CreateTrVars ("auscrie" "de;en;es;fr;it;oc;ru_RU;uk_UA" TRANSLATIONS CO
Here you pass the name of your plugin as the first parameter, the ;-separated list of translations languages as the second one and the variable names for the list of files with translations (*.ts) and compiled translations (*.qm) as third and forth ones respectively. Then, you should add a custom command for actually running the lrelease tool: ADD_CUSTOM_COMMAND (OUTPUT ${COMPILED_TRANSLATIONS} COMMAND "${QT_LRELEASE_EXECUTABLE}" ${TRANSLATIONS} DEPENDS ${TRANSLATIONS} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) Don't forget to add the compiled translations as the dependency of your plugin: ADD_LIBRARY (leechcraft_auscrie SHARED ... ${COMPILED_TRANSLATIONS} ...
2 of 4
8/22/2011 5:11 PM
http://leechcraft.org/development-cmake-cheatsheet
) Don't also forget to install the resulting files if you don't embed them into resources (and this is the recommended scheme). See the next section regarding installing.
3 of 4
8/22/2011 5:11 PM
http://leechcraft.org/development-cmake-cheatsheet
${COMPILED_TRANSLATIONS} COMMAND "${QT_LRELEASE_EXECUTABLE}" ${TRANSLATIONS} DEPENDS ${TRANSLATIONS} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) ADD_LIBRARY (leechcraft_auscrie SHARED ${COMPILED_TRANSLATIONS} ${SRCS} ${MOC_SRCS} ${UIS_H} ${RCCS} ) TARGET_LINK_LIBRARIES (leechcraft_auscrie ${QT_LIBRARIES} ${LEECHCRAFT_LIBRARIES} ) INSTALL (TARGETS leechcraft_auscrie DESTINATION ${LC_PLUGINS_DEST}) INSTALL (FILES ${COMPILED_TRANSLATIONS} DESTINATION ${LC_TRANSLATIONS_D LeechCraft architecture up Writing a simple plugin in 20 minutes Login or register to post comments
Hosted by 0xd34df00d.me.
4 of 4
8/22/2011 5:11 PM