For this to work, the LibFindMacros. After that the actual detection takes place. The library names do not contain the lib prefix used on UNIX system, nor any file extension or compiler specifications, as CMake will platform-independently detect them. The library version number is still needed, if present in the body part of the library file name. The module LibFindMacros. It contains various libfind macros taking care of the boring parts that are always the same for every library.
With it, a scripts look like this:. You don't need to test for CMake version, load the appropriate module, check if it loaded, etc.
For this to work, the first parameter supplied is the name of the current package. Have one of these lines for every library that your library depends on, and be sure to supply find modules for them as well. Three items done, four to go. The CMake variable system is far more complex than it may seem first. Some variables are cached and some are not. The cached variables may be cached as internal not possible to edit with ccmake or as external have a type and a documentation string and can be modified in ccmake.
Further, the external variables may be set advanced, so that they'll only be seen in the advanced mode of ccmake. In order to avoid doing all the library detection again on every run, and more importantly to allow the user to set include dirs and libraries in ccmake, these will have to be cached.
If the variable is already set to a valid value e. This page was initially populated by conversion from its original location in another wiki. The package root variables are maintained as a stack so if called from within a find module, root paths from the parent's find module will also be searched after paths for the current package.
See policy CMP Search paths specified in cmake-specific cache variables. The values are interpreted as semicolon-separated lists. Search paths specified in cmake-specific environment variables. These are intended to be set in the user's shell configuration, and therefore use the host's native path separator ; on Windows and : on UNIX. These should be paths computed by system introspection, such as a hint provided by the location of another item already found.
Search the standard system environment variables. See the cmake-packages 7 manual for details on the user package registry. Search cmake variables defined in the Platform files for the current system. The platform paths that these variables contain are locations that typically include installed software.
See the cmake-packages 7 manual for details on the system package registry. These are typically hard-coded guesses. This effectively "re-roots" the entire search under given locations. See the documentation for that variable for more.
These variables are especially useful when cross-compiling to point to the root directory of the target environment and CMake will search there too. This behavior can be manually overridden on a per-call basis using options:. The default search order is designed to be most-specific to least-specific for common use cases. Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again.
By default the value stored in the result variable will be the path at which the file is found. Setting both variables to TRUE simultaneously is an error. When Config mode is used, this version selection process is applied regardless of whether the full or basic signature was given. When the [version] argument is given, Config mode will only find a version of the package that claims compatibility with the requested version see format specification.
If the EXACT option is given, only a version of the package claiming an exact match of the requested version may be found. CMake does not establish any convention for the meaning of version numbers. You must add the search path that contains them to the compile command. This article discusses how to use an external library in a CMake project, and how to write one for a library that does not have a search module.
A version number is required, which is the version number that the package you are looking for should be compatible format is major [. EXACT options. The version number must match exactly. If the [version] parameter is not given for the recursive call to this command within the find-module, then the [version] and EXACT options will automatically be invoked from the outside forward inheritance. Support for versions currently only exists between packages and packages see below for details.
QUIET parameters:. The warning message when the package is not found will be suppressed. The meaning refers to whether it is necessary for the project, indicating that if the report is not found, the cmake process will be terminated and a warning message will be output. Without checking, the fixed value of the installed library is directly included. The former is called the module mode, and the latter is called the configuration mode.
See the documentation here for the configuration file. This document may also be used for importing and exporting targets.
The module system seems to have no documentation, so this article mainly discusses this aspect. No matter which mode is used, as long as the package is found, the following variables will be defined:.
Now, in the CMakeLists. The documentation of these conventions is in the readme. User code should generally use the simple call format described above to query the required packages. Expect to find and provide package maintenance personnel through this command, and we encourage you to continue reading. This command has two modes when searching for packages: "Module" mode and "Configuration" mode. When the command is invoked through the above reduced format, the module mode is used. If the file is found, it will be read and processed by CMake.
This mode is responsible for finding packages, checking versions, and generating any other necessary information. Many find-modules provide only limited, or even no support for versioning; check the documentation of the module for specific information. If no module is found, the command will enter configuration mode to continue execution. The command format in the complete configuration mode is:.
It also implicitly specifies that the options used in the reduced format are not used. The configuration mode attempts to find the location of a configuration file provided by the package to be found. The search process is described below. If a configuration file is found, it will be read and processed by CMake. Since the file is provided by the package itself, it already knows the location of the content in the package. If no package configuration file is found, CMake will generate an error description file to describe the problem-unless the QUIET option is specified.
However, the example at github is more complex that it can be IMO. As a result the configuration can be cut down significantly. I think I'll make a similar example myself. Dimitris Yes, it can be simplified a little bit. By the way if you have any other suggestions you can send me pull request.
It supports monolithic build all modules from the root folder or autonomous builds each module separately, requires install. Dimitris Okay, now I see. I think it's a good template to start so I will keep it even it's not used in fact.
And namespaces look very pretty, so I will keep them too : Also I've added monolithic build. Each of your examples were very helpful to me.
Thank you both! Show 3 more comments. Brief how-to Associate the targets of SomeLib that you need outside of that external project by adding them to an export set in the CMakeLists. When it might be the right approach This approach is probably best suited for situations where you'll never use your software downstream of the build directory e.
Ryan Feeley Ryan Feeley 5 5 silver badges 11 11 bronze badges. Can confirm user's comment in It is a project specific variable, for modules shipping with your project. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.
0コメント