Difference between revisions of "Development/CMake/FAQs"

Jump to: navigation, search
(Created page with "==Can I safely change the cmake_minimum_required version?== Maybe. Your two main considerations, of course, are that if you set it to a too-recent version, your users will n...")
 
(Replaced content with link to Community WIki.)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Can I safely change the cmake_minimum_required version?==
+
Moved to the [https://community.kde.org/Guidelines_and_HOWTOs/CMake/FAQs Community wiki].
 
 
Maybe.
 
 
 
Your two main considerations, of course, are that if you set it to a too-recent version, your users will not have a recent enough CMake (especially if they are using the one provided by their Linux distribution), and that if you set it to a too-old version, you won't be able to use new features.
 
 
 
Bear in mind that you may be able to optionally use new features by doing something like
 
 
 
{{Input|1=<syntaxhighlight lang="cmake">
 
if (NOT CMAKE_VERSION VERSION_LESS 3.0)
 
  # do stuff that requires CMake 3.0 or later
 
endif()
 
</syntaxhighlight>}}
 
 
 
However, [http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:cmake_minimum_required cmake_minimum_required] also sets some [http://www.cmake.org/cmake/help/v2.8.12/cmake.html#section_Policies CMake Policies] to NEW, changing CMake's behaviour in some corner cases. Normally, CMake should have been warning you about these Policies if you have done something that would be affected by them, so you if don't get any warnings when you build with CMake version X or later, you should be safe to set the minimum required version to X.
 
 
 
==Why isn't find_package working?==
 
 
 
If a find_package call isn't finding something you think it should, there are a few things to check. First, the obvious things:
 
 
 
* Was the package name spelled correctly? Case is important!
 
* Do you have the right version installed?
 
 
 
Of course, it may not be obvious what the "correct" spelling of the package name is, especially when it comes to upper- or lower-case letters.
 
 
 
At this point, it is useful to know what a [http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:find_package find_package] call actually does. The CMake documentation contains [http://www.cmake.org/cmake/help/v3.3/command/find_package.html a complete description], but it is long and rather daunting. So here is a simplified description.
 
 
 
find_package has two ways of finding the information it needs. The first method is called the ''module'' search. If you do <code>find_package(Foo)</code>, it progresses like this:
 
 
 
* CMakel searches for a file called <tt>FindFoo.cmake</tt> in the same places it looks for files when you use the [http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:include include] command (the entries in [http://www.cmake.org/cmake/help/v2.8.12/cmake.html#variable:CMAKE_MODULE_PATH CMAKE_MODULE_PATH] followed by the CMake installation).
 
* It sets some variables describing what you are looking for (such as what version you want).
 
* CMake effectively includes the <tt>FindFoo.cmake</tt> file, as though you had copied the text in place of the find_package call.
 
* After this, it unsets the variables it set at the start, but any variables set by the <tt>FindFoo.cmake</tt> file remain (which is how the results of the search are communicated back to your <tt>CMakeLists.txt</tt>.
 
 
 
The second search method is called the ''config'' search.
 
 
 
TODO: describe config search.
 

Latest revision as of 10:27, 28 April 2019

Moved to the Community wiki.


This page was last edited on 28 April 2019, at 10:27. Content is available under Creative Commons License SA 4.0 unless otherwise noted.