Commit Graph

54 Commits

Author SHA1 Message Date
Pierluigi Taddei 31be918b0b find_package: Optionally sort globbed directories in a meaningful order
Add `CMAKE_FIND_PACKAGE_SORT_{ORDER,DIRECTION}` variables to specify
sort order and direction.

When multiple package with the same name have been found in the same
location sorting option can be used to force a specific version to be
loaded (e.g. libA_1.12.0 instead of libA_1.1.0).  Currently sorting by
NAME and by NATURAL order have been implemented.

Natural ordering makes use of the `strverscmp(3)` ordering.
2016-09-15 13:35:25 -04:00
Silvio Traversaro 828d6c137d find_package: Extend search path for combined Windows/UNIX convention
Find packages that install their cmake package configuration files in
`lib/cmake/<name>` when they are installed in the default Windows
CMAKE_INSTALL_PREFIX, `C:/Program Files/<name>`.

Closes: #16212
2016-08-24 09:40:25 -04:00
Daniel Pfeifer 7a649111cd Use string(APPEND) in Tests
Automate with:

find Tests -type f -print0 | xargs -0 perl -i -0pe \
's/set\(([a-zA-Z0-9_]+)(\s+)"\$\{\1\}([^"])/string(APPEND \1\2"\3/g'
2016-07-28 00:43:04 +02:00
Kitware Robot d9fd2f5402 Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.
2016-05-16 16:05:19 -04:00
Brad King d430cb7c36 Tests: Fix failures when running under the default install prefix (#15566)
Fix test cases whose behavior differs when their source or build tree is
under CMAKE_INSTALL_PREFIX by setting an install prefix under the build
tree.  Otherwise they may fail when run under the default install prefix
(e.g. /usr/local).
2015-05-14 10:07:37 -04:00
Stephen Kelly d1a6d15bcd FPHSA: Always populate the ExactCase_FOUND variable (#15412).
The UPPERCASE name was inconsistent with config-packages, the
find_dependency macro, and even FPHSA itself, which expects
components to be specified with names matching ExactCase.

The FOUND_VAR was only permitted to have two possible values, and
now both are set for compatibility.  Document it as obsolete, and
adjust the code for the same.  Users of the variable should just
remove it.
2015-04-17 10:46:24 -04:00
Daniele E. Domenichelli e3007c92e0 CMakePackageConfigHelpers: Add unit tests for INSTALL_PREFIX option 2014-08-11 09:38:29 -04:00
Daniele E. Domenichelli be8ae96098 Allow the Package Registry to be disabled (#14849)
When a project is packaged for redistribution the local package
registries should not be updated or consulted.  They are for developers.

Add variables to disable use of package registries globally:

* CMAKE_EXPORT_NO_PACKAGE_REGISTRY that disables the export(PACKAGE)
  command
* CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY that disables the User Package
  Registry in all the find_package calls.
* CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY that disables the
  System Package Registry in all the find_package calls.

Update documentation and unit tests.
2014-05-12 09:50:01 -04:00
Brad King d09fda5d91 Tests: Improve FindPackageTest for in-source builds
Use a different directory name for the Exporter build tree so that it is
out-of-source even when the main test is in-source.
2014-05-12 09:44:32 -04:00
Brad King ac24a1c031 Tests: Improve FindPackageTest exported package version
Add a random version component so that the test is unlikely to conflict
with other tests of the same CMake version on the same machine.
2014-05-12 09:44:28 -04:00
Brad King 7e187eeacd CMP0017: Fix check when including from CMake source tree
When running CMake from the build tree the CMAKE_ROOT is the
entire source tree.  Fix the CMP0017 check to be specific to
the Modules/ directory under CMAKE_ROOT so that Tests/ does
not count.  Fix the FindPackageTest modules to include FPHSA
by full path from CMAKE_ROOT so that they do not include the
local FPHSA which reports an error meant to test that CMP0017
works.
2014-03-04 09:35:00 -05:00
Alex Neundorf 7bb1abe56a FPHSA: Add FOUND_VAR option to specify _FOUND variable name
In the new mode FPHSA now accepts a FOUND_VAR option, which can be set
either to ExactCase_FOUND or UPPERCASE_FOUND, no other values are
accepted.  Also add tests for that, including failure.

Alex
2013-02-22 08:31:00 -05:00
Kitware Robot 9db3116226 Remove CMake-language block-end command arguments
Ancient versions of CMake required else(), endif(), and similar block
termination commands to have arguments matching the command starting the
block.  This is no longer the preferred style.

Run the following shell code:

for c in else endif endforeach endfunction endmacro endwhile; do
    echo 's/\b'"$c"'\(\s*\)(.\+)/'"$c"'\1()/'
done >convert.sed &&
git ls-files -z -- bootstrap '*.cmake' '*.cmake.in' '*CMakeLists.txt' |
egrep -z -v '^(Utilities/cm|Source/kwsys/)' |
egrep -z -v 'Tests/CMakeTests/While-Endwhile-' |
xargs -0 sed -i -f convert.sed &&
rm convert.sed
2012-08-13 14:19:16 -04:00
Kitware Robot 77543bde41 Convert CMake-language commands to lower case
Ancient CMake versions required upper-case commands.  Later command
names became case-insensitive.  Now the preferred style is lower-case.

Run the following shell code:

cmake --help-command-list |
grep -v "cmake version" |
while read c; do
    echo 's/\b'"$(echo $c | tr '[:lower:]' '[:upper:]')"'\(\s*\)(/'"$c"'\1(/g'
done >convert.sed &&
git ls-files -z -- bootstrap '*.cmake' '*.cmake.in' '*CMakeLists.txt' |
egrep -z -v '^(Utilities/cm|Source/kwsys/)' |
xargs -0 sed -i -f convert.sed &&
rm convert.sed
2012-08-13 14:19:16 -04:00
Alex Neundorf 14b213c0ce add test for #13241: empty SIZEOF_VOIDP in write_basic_package_version_file
Alex
2012-05-23 20:48:47 +02:00
Alex Neundorf d81d83c218 add macro check_required_components() to configure_package_config_file()
As discussed on cmake-developers, this patch adds a macro
check_required_components() to the file configured via
configure_package_config_file(), so for proper handling
of components in Config.cmake files users can simply call

check_required_components(PackageName)

and this will do the right thing.

Alex
2012-03-19 10:53:36 -04:00
Alex Neundorf b15c0b418b FPHSA(): add HANDLE_COMPONENTS option
if the HANDLE_COMPONENTS is used, FPHSA() now also checks all required COMPONENTS,
i.e. all elements from <name>_FIND_COMPONENTS for which <name>_FIND_REQUIRED_<comp>
is true, and sets <name>_FOUND only to true if all have been found.
As discussed on cmake-developers.

Alex
2012-03-19 10:53:36 -04:00
Alex Neundorf 56ae3f9412 find_package: add test for setting Foo_FOUND to FALSE in a Config file
Alex
2012-03-13 16:56:52 -04:00
Alex Neundorf e390f87dd1 WriteBasicConfigVersionFile: add test for ExactVersion mode
Alex
2012-03-10 16:19:02 +01:00
Alex Neundorf 6973e2d5a8 wrap write_basic_config_version_file as write_basic_package_version_file()
So the name fits better with configure_package_config_file(), as
discussed on the mailing list. Adapt the documentation accordingly.

Alex
2012-03-07 11:23:18 -05:00
Alex Neundorf 204f5d443c add CMakePackageConfigHelpers: configure_package_config_file()
The function configure_package_config_file() may be used instead of
configure_file() for generating the Config.cmake files for installation,
they help to make those files relocatable.

Alex
2012-03-07 11:23:11 -05:00
Alex Neundorf 208bb9009b Set UNSUITABLE instead of not COMPATIBLE
Alex
2011-08-05 22:42:57 +02:00
Alex Neundorf 4ba09bc6a2 Add some tests for write_basic_config_version_file()
Alex
2011-08-01 23:29:27 +02:00
Alex Neundorf 4a50b5f2aa Add a basic test for CMAKE_DISABLE_FIND_PACKAGE_<package>
Alex
2011-06-23 11:09:54 +02:00
Brad King 52a6ed2aed Test find_package multiarch support (#12037) 2011-06-08 10:28:20 -04:00
Brad King 08b93977cf find_package: Fix system package registry test path conversion
Do not use file(TO_NATIVE_PATH) to compute the value to store in the
registry.  It is meant for constructing values to be put in shells.
Since find_package() can use the value with CMake-normalized slashes do
not bother with any conversion.
2011-04-14 09:35:21 -04:00
Brad King 93021adb73 find_package: Test system package registry when possible
Teach the FindPackagTest to try creating the appropriate HKLM system
package registry value.  If it works then add a test to verify that
find_package() reads it as expected.  Then delete the value to cleanup.
2011-04-13 14:28:00 -04:00
Brad King 9fc7ea4c62 find_package: Forward component list for recursive calls in modules
Some find modules call find_package recursively to locate a package
configuration file for the package instead of searching for individual
pieces.  Commit 79e9b755 (Help recursive find_package calls in modules,
2008-10-03) taught find_package to forward the version number and EXACT
arguments through the recursive call automatically.  Do the same for the
component list.
2011-04-07 15:36:05 -04:00
Alex Neundorf 7db8db5b72 Improve documentation and messages for the new CMP0017
This patch incorporates the comments from Brad:
-some improvements to the documentation of CMP0017
-make the test QUIETLY search for zlib
2011-01-04 08:19:33 -05:00
Alex Neundorf db44848f44 Prefer files from CMAKE_ROOT when including from CMAKE_ROOT
This patch makes include() and find_package() prefer cmake files
located in CMAKE_ROOT over those in CMAKE_MODULE_PATH.
This makes sure that the including file gets that file included
which it expects, i.e. the one from cmake with which it was tested.
It only changes behaviour when such an included file exists both
in CMAKE_MODULE_PATH and in CMAKE_ROOT.
This comes together with a new policy CMP0017, with default
behaviour it behaves as it always did, but warns.
With NEW behaviour it includes the file from CMAKE_ROOT
instead from CMAKE_MODULE_PATH. This fixes (if CMP0017 is set)
building KDE 4.5 with cmake >= 2.8.3.
Also a basic test for this policy in included.
2011-01-04 08:06:20 -05:00
Todd Gamblin 1221581aa8 Teach find_* commands to ignore some paths
Add platform configuration variable CMAKE_SYSTEM_IGNORE_PATH and user
configuration variable CMAKE_IGNORE_PATH.  These specify a set of
directories that will be ignored by all the find commands.  Update
FindPackageTest so that several cases will fail without a functioning
CMAKE_IGNORE_PATH.
2010-08-13 11:53:28 -04:00
Brad King 0328379411 Report commit hash in CMake development versions
For builds from Git repositories, add "-g<commit>" to the end of the
version number.  If the source tree is modified, append "-dirty".
For builds from CVS checkouts, add "-cvs-<branch>".
2010-04-23 10:01:49 -04:00
Brad King 3a790251f4 Document and test find_package <pkg>_DIR env var
The find_package(<pkg>) command checks the <pkg>_DIR environment
variable.  This commit documents and tests the feature.
2009-11-04 13:14:57 -05:00
Brad King 71910b3fd4 Fix find_package() when <pkg>_DIR is wrong
When <pkg>_DIR is set to an incorrect version we search again and store
the result in the variable, even if it is <pkg>_DIR-NOTFOUND.

There was a bug in the case when the new search does not find anything
and the old value came from a cache entry with UNINITALIZED type.  The
command used to try to load a package configuration file from the last
place searched, and would leave the old wrong value in the entry.  This
commit fixes the behavior to avoid trying to load a missing file and to
set the value to <pkg>_DIR-NOTFOUND as expected.
2009-10-07 14:37:30 -04:00
Brad King 07f029d6ef Test the user package registry
We teach the FindPackageTest to build a sample project that stores its
build tree in the user package registry using export(PACKAGE), and then
find it with find_package.
2009-09-01 14:05:42 -04:00
Brad King bb2c08546c ENH: Test find_package re-find feature
Recently we taught find_package to re-find a package if its
<package>_DIR result variable was set to a location not containing the
package (instead of reporting an error as before).  This tests the
feature.
2009-01-14 09:34:42 -05:00
Brad King 3958b3e112 ENH: Teach find_package about more install dirs
We now search in

  <prefix>/<name>*/
  <prefix>/<name>*/(cmake|CMake)

when looking for package configuration files.  This is useful on Windows
since the Program Files folder is in CMAKE_SYSTEM_PREFIX_PATH.  These
paths are the Windows equivalent to the Apple convention application and
framework paths we already search.  See issue #8264.
2008-12-17 09:24:05 -05:00
Brad King 63e186a8e6 ENH: Strengthen FindPackageTest version check
The previous change to test finding in lib/cmake/<name>* weakened the
versioned find tests.  Since the lib/cmake paths are searched before
lib/<name>* paths the previous change skipped requiring the command to
ignore zot-3.0 when finding zot-3.1.  This change restores that and adds
zot-4.0 to test the lib/cmake path.
2008-12-16 09:13:39 -05:00
Brad King e51969ac49 ENH: Add useful search locations to find_package
This teaches find_package to search

  <prefix>/(share|lib)/cmake/<name>*/

for package configuration files.  Packages that do not already have
files in a <prefix>/lib/<name>* directory can use this location to avoid
cluttering the lib directory.
2008-12-09 14:07:19 -05:00
Brad King 25a5c34a62 ENH: Remove implicit NO_MODULE when recursing
Recently we taught find_package that the NO_MODULE option is implied
when it is recursively invoked in a find-module.  This behavior may be
confusing because two identical calls may enter different modes
depending on context.  It also disallows the possibility that one
find-module defers to another find-module by changing CMAKE_MODULE_PATH
and recursively invoking find_package.  This change reverts the feature.
2008-10-08 10:56:23 -04:00
Brad King 0ae545ebad ENH: Add UNSUITABLE result to package version test
Package version test files may now declare that they are unsuitable for
use with the project testing them.  This is important when the version
being tested does not provide a compatible ABI with the project target
environment.
2008-10-03 10:41:15 -04:00
Brad King 79e9b75558 ENH: Help recursive find_package calls in modules
These changes teach find_package to behave nicely when invoked
recursively inside a find-module for the same package.  The module will
never be recursively loaded again.  Version arguments are automatically
forwarded.
2008-10-03 10:40:07 -04:00
Brad King 4fa96dbf95 ENH: Add version comparison to if() command
Provide VERSION_LESS, VERSION_EQUAL, and VERSION_GREATER operators in
the if() command.  This simplifies component-wise comparison of version
numbers in the form "major[.minor[.patch[.tweak]]]".
2008-09-10 11:58:40 -04:00
Brad King 994262e5cc ENH: Improve find_package version numbering
Make the number of version components specified explicitly available.
Set variables for unspecified version components to "0" instead of
leaving them unset.  This simplifies version number handling for find-
and config-modules.  Also support a fourth "tweak" version component
since some packages use them.
2008-09-10 10:11:48 -04:00
Brad King fdb17d604c ENH: Add test for new find_* command HINTS option. 2008-06-09 15:09:14 -04:00
Ken Martin ce8810c4e7 ENH: preclean some warnings 2008-03-25 11:27:18 -04:00
Brad King 41c2895b75 ENH: Added version support to Config mode of find_package command.
- Added EXACT option to request an exact version.
  - Enforce version using check provided by package.
  - Updated FindPackageTest to test versioning in config mode.
2008-01-28 20:38:48 -05:00
Brad King f41b1e8e91 ENH: Implement version support in the find_package command module mode. Version numbers provided to the command are converted to variable settings to tell the FindXXX.cmake module what version is requested. This addresses issue #1645. 2008-01-21 08:48:33 -05:00
Brad King 81af53e3c0 ENH: Updated FindPackageTest to test new find_package command features. 2008-01-17 09:06:36 -05:00
Brad King 07db9b83a7 ENH: Renamed CMAKE_FIND_PREFIX_PATH to CMAKE_PREFIX_PATH for brevity and consistency with other find path variable names. 2007-12-19 11:06:47 -05:00