The great thing about the policies framework is that you can completely ignore it, as long as you have cmake_minimum_required(VERSION 3.3) at the top of your toplevel CMakeLists.txt. To this end they have introduced the rather obtuse policies framework. The CMake developers seem pretty good at backwards compatibility. Of course, is a special character in UNIX shells so must be escaped.ĬMake supports multiple backends, and Ninja is often faster than GNU Make, so give the Ninja backend a try: cmake -G Ninja. DCMAKE_PREFIX_PATH=/opt/path1\ /opt/path2 However, that won’t work (unless you did actually mean that to be one item). DCMAKE_PREFIX_PATH=/opt/path1:/opt/path2 The semi-colon separator can bite you in other ways, for example, when specifying CMAKE_PREFIX_PATH (library and header search path) you might expect this to work: cmake. CMake hasn’t actually solved this but just punted the special character to a less often used one, as far as I can see. Most of us are trained to avoid spaces, partly because we know how broken (all?) most shell-based build systems are in those cases. Semicolons occur less often in file names, I guess. Output: item:ls item:filename item:with item:semicolons On the other hand: cmake_minimum_required(VERSION 3.2) set(path "filename with\ semicolons") set(command ls $) endforeach() Output: item:ls item:filename with spaces I like this more than shell code where I have to quote literally every variable (or else Richard Maw shouts at me).įor example: cmake_minimum_required(VERSION 3.2) Crucially, they seem to be converted before variable expansion is done, which means that filenames with spaces don’t need any special treatment. Spaces are used as an argument separator, but converted to semicolons during argument parsing, I think. Semicolon safety instead of whitespace safetyĬMake has a ‘list’ type which is actually a string with (semicolon) used to delimit entities. Which makes sense! Why say with two commandline arguments what you can say with one?Īt least, this will be fine once CMake’s pkg-config integration returns absolute paths to libraries …ģ. So the recommended way to link to libraries is with the absolute path. There is a global LINK_DIRECTORIES property, confusingly, but it’s specifically marked as “for debugging purposes.” There’s no target property for LINK_DIRECTORIES, though, so outside of the current CMakeLists.txt file they won’t be tracked. Library ‘targets’ in CMake keep track of associated include paths, dependent libraries, compile flags, and even extra source files, using ‘target properties’. pc files I have installed use the -L/path -Lname pattern.ĬMake makes this quite awkward to do, because it makes every effort to forget about the linker paths. I don’t think pkg-config actually enforces this pattern but pretty much all the. Then, if libfoo is in a non-standard location, you pass -L/path/to/foo -lfoo. Traditionally you link to libfoo by passing -lfoo to the linker. Targets have properties, which are useful. You need to use custom targets feature if you want a custom command target to be tied to the default target, which is a little confusing but works OK. You can also create custom targets which run commands if executed. Libraries are targets, programs are targets, subdirectories are targets and custom commands create files which are considered targets. This is a quick list of things I found in CMake that confused me to start with but ultimately I think are good things.ĬMake is pretty similar to normal make in that all the things that you care about are ‘targets’. To keep a project going for 16 years is impressive and it is pretty widely used now. It seems like many of its warts are due to its long history and the need for backwards compatibility, not anything fundamentally broken. In general I think CMake has a sound design and I quite want to like it. Maybe there will be a few blog posts on that subject! This was my first major outing with CMake. I spent the past few weeks converting a bunch of Make and Autotools-based modules to use CMake instead.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |