[CMake] FindPackage: Mismatch between documentation and implementation ?

Theodore Papadopoulo Theodore.Papadopoulo at inria.fr
Mon May 5 14:19:24 EDT 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm not quite clear, but here is the problem.
I want to control precisely the place where a subproject XXX is found
(using external_project_add). For this I'm passing the variable
XXX_DIR to the other projects needing XXX.

This variable XXX_DIR is set to the installation directory of XXX,
which contains in the subdirectory share/cmake/XXX the proper config
files. But find_package does not find them, even though the
documentation states that XXX_DIR is used as a prefix and that (for
unix) a set of subdirectories are searched.  [ see the prefix section
and then subsection 2. of prefix generation].

But if I'm using CMAKE_FIND_DEBUG_MODE, I do not see a prefix but
directly a search of the conhig files.

find_package(XXX NO_DEFAULT_PATH QUIET)

Checking file [PATH/XXX/install/XXXConfig.cmake]
Checking file [PATH/XXX/install/XXX-config.cmake]

If I provide the path as a PATH argument to find_package, the proper
behaviour (as per the docunebtation) is achieved.

find_package(XXX PATHS ${XXX_DIR} NO_DEFAULT_PATH QUIET)

Checking file [PATH/XXX/install/XXXConfig.cmake]
Checking file [PATH/XXX/install/XXX-config.cmake]
Checking prefix [PATH/XXX/install/]
Checking file [PATH/XXX/install/XXXConfig.cmake]
Checking file [PATH/XXX/install/XXX-config.cmake]
Checking file [PATH/XXX/install/share/cmake/XXX/XXXConfig.cmake]
Checking file [PATH/XXX/install/share/cmake/XXX/XXX-config.cmake]

which reading the docs I would have expected even in the first case.
All this seems supported by the git code[1] (look at comment line).

I spent a huge amount of time to figure out what was happening. It
would be nice to correct this either in the code or in the documentation.

Should I open a bug report ? In which direction (code or documentation)?

Thank;s for any help.

	Theo.


[1] in cmFindpackageCommand.cxx function(HandlePackageMode):, the code is:

  // Try to load the config file if the directory is known
  bool fileFound = false;
  if (this->UseConfigFiles)
    {
    if(!cmSystemTools::IsOff(def))
      {
      // Get the directory from the variable value.
      std::string dir = def;
      cmSystemTools::ConvertToUnixSlashes(dir);

      // Treat relative paths with respect to the current source dir.
      if(!cmSystemTools::FileIsFullPath(dir.c_str()))
        {
        dir = "/" + dir;
        dir = this->Makefile->GetCurrentDirectory() + dir;
        }
      // The file location was cached.  Look for the correct file.
      std::string file;

       // Comment: this should be FindPrefixedConfig per the docs ??
	
      if (this->FindConfigFile(dir, file))
        {
        this->FileFound = file;
        fileFound = true;
        }
      def = this->Makefile->GetDefinition(this->Variable);
      }

    // Search for the config file if it is not already found.
    if(cmSystemTools::IsOff(def) || !fileFound)
      {
      fileFound = this->FindConfig();
      def = this->Makefile->GetDefinition(this->Variable);
      }

    // Sanity check.
    if(fileFound && this->FileFound.empty())
      {
      this->Makefile->IssueMessage(
        cmake::INTERNAL_ERROR, "fileFound is true but FileFound is
empty!");
      fileFound = false;
      }
    }





-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlNn1iwACgkQEr8WrU8nPV1GkACeIGXEDNiwxO8pnh6ywf96aAy9
k2EAn2uSTTH3nG2ha2WNuWBHseatPMO5
=p/MK
-----END PGP SIGNATURE-----


More information about the CMake mailing list