Development/CMake FAQ

Jump to: navigation, search


Frequently Asked Questions

These are KDE's FAQ for CMake, there is also a CMake FAQ in the main CMake wiki.

How can I teach my favorite editor about CMake syntax and indentation ?

Read the CMake Wiki section CMake Editors Support. It describes how to setup Emacs (XEmacs works too), VIM, Kate, KWrite, and KDevelop.

I need to generate some files during the build. How do I do this ?

Use ADD_CUSTOM_COMMAND(). It's explained here in the CMake wiki: How can I generate a source file during the build

I need to build an executable which is used later on during the build to generate files. How do I do this ?

Let's say the executable is called genembed. Then use KDE4_ADD_EXECUTABLE(foo RUN_UNINSTALLED ${fooSources})to create the executable. The RUN_UNINSTALLED option is important, because the executable has to run from the build dir and has to link to the libraries in the builddir. To achieve this, the executable is compiled with RPATH set accordingly and a wrapper shell script, named just like the executable but with the suffix ".sh" is created. This shell scripts sets up LD_LIBRARY_PATH and the calls the actual executable. Use this wrapper shell script in the ADD_CUSTOM_COMMAND() as described above. You can find out the name and exact location by querying the property WRAPPER_SCRIPT. Here's a full example taken from kdelibs/kstyles/keramik/ :

# build the executable
kde4_add_executable(genembed RUN_UNINSTALLED ${genembed_SRCS})
# get the name of the generated wrapper script (which sets up LD_LIBRARY_PATH)
get_target_property(GENEMBED_EXECUTABLE genembed WRAPPER_SCRIPT)
# and the custom command
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/keramikrc.h
  DEPENDS genembed ${keramikPics}

As you can see genembed is also listed as a dependency, this means cmake knows that it has to build the executable genembed before executing this rule.

I don't want to set the -DCMAKE_INSTALL_PREFIX command line option. Does cmake support the KDEDIR environment variable?

No. $KDEDIR is deprecated in KDE 4.

Why do I get compile errors like /usr/lib/qt4/include/QtCore/qstring.h:536: undefined reference to `QString::fromLatin1_helper(char const*, int)'?

A: If you have an old Qt4 version in your qt/lib directory you must delete the old (4.0.1) files.

How do I tell cmake to create noisy makefiles? I want to see the exact commands that are run during the make process.

Pass the VERBOSE variable to make, i.e.

% make VERBOSE=1


% VERBOSE=1 make

For more details see the CMake wiki: Is there an option to produce more 'verbose' compiling?

There is no 'make distclean' target in the generated Makefiles. How do I clean up everything, including the cache files?

Simply remove the build directory, or just the contents of the build directory.

I've got fatal error LNK1104: cannot open file 'optimized.lib' under Windows/msvc (release with debug info build)

This is a problem with KDE's CMakeLists.txt and CMake 2.6.0 and 2.6.1, it will be fixed soon.

QT_*_LIBRARIES must not be used in your target_link_libraries() line of CMakeLists.txt. Use QT_*_LIBRARY instead. Otherwise the variable will look like this (example for QT_QTNETWORK_LIBRARY):


The first optimized part is translated by cmake to optimized.lib so we have got the cannot open file 'optimized.lib' error.

This page was last modified on 15 July 2012, at 16:56. This page has been accessed 7,826 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal