MantisBT - CMake
View Issue Details
0012475CMakeCMakepublic2011-09-23 08:112016-06-10 14:31
Mourad 
Bill Hoffman 
normalminoralways
closedmoved 
Windows
CMake 2.8.5 
 
0012475: find_package produces path without drive letter if package is in c:/<package> directory
I am trying to use the Registry to find my own package using cmake as stated here : http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:find_package [^]

I am using CPack+NSIS with a custom Nsis.template.in to add an entry to the Registry.

CMake is able to find my package, but shows a wrong PACKAGE_DIR in the GUI.

Say, my FooConfig.cmake is in c:/Foo/cmake. Cmake GUI shows FOO_DIR : /Foo/cmake

But, the configuration and generation of the project files are OK. My generated project builds fine too.

A side note: I noticed that if the installation folder name doesn't begin with the package name, CMake is unable to find it.

Example: if my package Foo is installed into :

- C:/Foo 1.2 --> works
- C:/myFoo --> doesn't work
- C:/Bar --> doesn't work
No tags attached.
Issue History
2011-09-23 08:11MouradNew Issue
2011-09-23 08:38Brad KingNote Added: 0027481
2011-09-23 08:38Brad KingAssigned To => Brad King
2011-09-23 08:38Brad KingStatusnew => assigned
2011-09-23 08:39Brad KingNote Added: 0027482
2011-09-23 09:06MouradNote Added: 0027483
2011-09-23 09:21Brad KingNote Added: 0027484
2011-09-23 09:56MouradNote Added: 0027485
2011-09-23 09:59MouradNote Added: 0027486
2011-09-23 11:43Brad KingNote Added: 0027487
2011-09-23 11:44Brad KingSummaryPACKAGE_DIR entry is wrong when the Registry is used to find a package => find_package produces path without drive letter if package is in c:/<package> directory
2011-09-26 11:29Brad KingNote Added: 0027489
2011-09-26 11:29Brad KingStatusassigned => resolved
2011-09-26 11:29Brad KingResolutionopen => fixed
2011-09-28 15:33Brad KingAssigned ToBrad King => Bill Hoffman
2011-09-28 15:33Brad KingNote Added: 0027490
2011-09-28 15:33Brad KingStatusresolved => feedback
2011-09-28 15:33Brad KingResolutionfixed => reopened
2016-06-10 14:28Kitware RobotNote Added: 0041907
2016-06-10 14:28Kitware RobotStatusfeedback => resolved
2016-06-10 14:28Kitware RobotResolutionreopened => moved
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0027481)
Brad King   
2011-09-23 08:38   
I cannot reproduce this. I created a "c:/Bar/FooConfig.cmake". Under key

  HKEY_LOCAL_MACHINE\SOFTWARE\Kitware\CMake\Packages\Foo

I created value "blah" with data "c:/Bar". Then I ran CMake on the code

  find_package(Foo)

and I got Foo_DIR=c:/Bar in the cmake-gui interface. Then i ran CMake on the code

  find_package(FOO)

and I got FOO_DIR=c:/Bar in the cmake-gui interface.
(0027482)
Brad King   
2011-09-23 08:39   
What registry value is your installer creating?
(0027483)
Mourad   
2011-09-23 09:06   
My package name is "Foo 1.0 win64"
It get installed to : C:/Foo-1.0
The FooConfig.cmake is put into a subfolder "cmake" : C:/Foo-1.0/cmake/FooConfig.cmake


The Registry value get created into :
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Software\Kitware\CMake\Packages\Foo 1.2 win64

Its value is C:/Foo-1.0/cmake (without FooConfig.cmake)
(0027484)
Brad King   
2011-09-23 09:21   
Your registry value is incorrect and not actually being used. That's why the directory name appears to matter.

Your package *name* is just "Foo". The *version* is "1.2 win64".

The documentation makes precise use of the term "registry key" v. "value":
 On Windows a <package> may appear under registry key

   HKEY_LOCAL_MACHINE\Software\Kitware\CMake\Packages\<package>

 as a REG_SZ value, with arbitrary name, that specifies the directory


The *key* name should be

   HKEY_LOCAL_MACHINE\Software\Kitware\CMake\Packages\Foo

and there should be a *value* in it called "1.2 win64" (or anything you want). The "value" should be of type REG_SZ and the data stored in it should be

  C:/Foo-1.0/cmake
(0027485)
Mourad   
2011-09-23 09:56   
Thank you Brad, it is working now with the registry.

I figured out that cmake was finding my Foo package because it is installed in :

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

And it seems, that the problem is here and not with the registry.

To sum up, if I have a valid registry key, FOO_DIR is correct. But if I remove the key, cmake still finds my Foo installation (C:/Foo-1.0/cmake), but then FOO_DIR is wrong ("C:" dissappears)
(0027486)
Mourad   
2011-09-23 09:59   
It looks like <prefix> is not added to FOO_DIR.
(0027487)
Brad King   
2011-09-23 11:43   
Okay, the remaining problem then is only the missing "C:". I tracked that down. It will happen only when there is a directory with the package name at the top of the current working drive when CMake runs. The path /Foo/cmake is actually a valid path on windows, but it is treated relative to the current working drive automatically. Most of the time this is "C:" so it appears to work.

The problem is that CMAKE_SYSTEM_PREFIX_PATH contains just plan "/" even on Windows. One can see the problem like this:

 #list(REMOVE_ITEM CMAKE_SYSTEM_PREFIX_PATH /) # uncomment to fix
 foreach(prefix ${CMAKE_SYSTEM_PREFIX_PATH})
   message("prefix [${prefix}]")
 endforeach()
 unset(Foo_DIR CACHE)
 find_package(Foo)


If one uncomments the list(REMOVE_ITEM) command the problem goes away.

It looks like the "/" prefix was added by:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2a782880#patch3 [^]

in order to preserve the CMAKE_FIND_ROOT_PATH behavior on MinGW added by:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=dac78148 [^]

The "/" is useful as a prefix on Windows only when appended to a value of CMAKE_FIND_ROOT_PATH (usually for cross compiling). I think the fix is for the find_package command to ignore prefixes that do not start in a drive letter.
(0027489)
Brad King   
2011-09-26 11:29   
First some refactoring and cleanup to simplify the fix:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b0cd6305 [^]

Now the fix:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9149033c [^]
(0027490)
Brad King   
2011-09-28 15:33   
Bill disagrees with the fix, so I reverted the non-refactoring part:

  http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0089cf69 [^]

Root-relative paths work fine when there is only one drive letter, which is very common.
(0041907)
Kitware Robot   
2016-06-10 14:28   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.