View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0002861CMakeCMakepublic2006-02-08 04:112006-02-10 12:44
ReporterChristian Ehrlicher 
Assigned ToBill Hoffman 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0002861: cmake.exe not found in win32 command line
DescriptionWhen I call cmake.exe from command line (cmake.exe is in PATH) I get the following error:
-----------------------8<------
C:\tmp\CMake_bin>cmake ..\cmake-cvs
CMake Error: CMAKE can not find the command line program cmake.
  argv[0] = "cmake"
  Attempted paths:
    "cmake"
    "C:/Programme/CMake 2.3-KDE/bin/bin/./cmake.exe"
    "C:/Programme/CMake/bin/cmake"
-----------------------8<------

Since nobody could help me, I had to do some investigations by myself. The problem is that argv[0] on windows contains (in difference to unix) not the full path to the executable but the command cmake.exe is called. In my case it contained 'cmake.exe' as you can see above. When I call cmake.exe with full path, all works fine.
You have to fill m_CMakeCommand with the result of GetModuleFilename instead argv[0]:

-----------------------8<------
  // set the cmake command
#if defined(_WIN32) || defined(_WIN64)
  char szFile[MAX_PATH];
  GetModuleFileNameA(NULL, szFile, MAX_PATH);
  szFile[MAX_PATH] = '\0';
  m_CMakeCommand = szFile;
#else
  m_CMakeCommand = args[0];
#endif
-----------------------8<------
-> cmake.cxx line 1438

This behaviour is quite annoying for someone who can't take a look into the sources / don't know the difference of argv[0]
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0003704)
Bill Hoffman (manager)
2006-02-08 11:06

There must be something you are doing differently. I run cmake from the command line all the time on windows and it has worked for years now. Did you copy cmake.exe by hand? If you use cmake from the build tree or the install tree it will work find without this change. Can you describe the exact steps you took to build and run cmake? Thanks.
(0003705)
Christian Ehrlicher (reporter)
2006-02-08 11:38

It works for you because the second search path (CMAKE_BUILD_DIR/bin/cmake.exe) matches.
Put some debug output around the place where m_CMakeCommand is assigned and you'll see that you don't get the full pathname in args[0]...
Also you can add some debug output into cmake::AddCMakePaths().

But make sure not to call it from a debugger because they call the executable with the full path (at least msvs).
(0003706)
Bill Hoffman (manager)
2006-02-08 12:19

This call should fix that problem:
 cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str());
  cmSystemTools::ConvertToUnixSlashes(cMakeSelf);

It should look for self in the PATH. So,
if cmake is given as a full path it will work, and if it is given with no path it will find it.

I think your fix is good, but I would like to be able to reproduce the problem. We have yet to be able to do that. Using GetModuleFileName is better than looking in the PATH, but looking in the PATH should work.
(0003707)
Bill Hoffman (manager)
2006-02-08 16:10

There is a problem with using GetModulePath, sometimes cmake is called from ctest, and GetModulePath will give the wrong answer. You must be copying the cmake executable out of the build tree to some other place than the install tree for this to happen. Even then, I am not sure how it can happen, because it is either in your PATH or you gave a full path to the program, either way the code we have should be able to find it. Also, copying by hand is dangerous becuase all of the support files are found relative to the executables, like the Modules and Templates directories.
(0003709)
Christian Ehrlicher (reporter)
2006-02-09 01:51

The problem with GetModuleFileName() can be - it's because hModule = NULL.
I don't understand you correct - what should work fine? The current cvs or your fix with cmSystemTools::FindProgram() ?

I know that 'copying by hand' isn't a good idea, but this also happens when you use the installer - then the install tree != current directory.
(0003710)
Bill Hoffman (manager)
2006-02-09 10:52

The FindProgram was not a fix, it has been like that for years. I am still not sure why it is not working for you? For the installer, CMAKE_PREFIX is also searched, and that is where things will be installed. The problem is that ctest.exe sometimes calls this function to run cmake.exe, and if we use the GetModuleName it will find ctest and not cmake, and things break.

Could describe how to repeat the problem you are encountering? Thanks.
(0003714)
Christian Ehrlicher (reporter)
2006-02-10 00:33

think I've got it now:

------------------------8<-------------------
E:\kde\kde-bin>set PATH="d:\Programme\CMake 2.3-KDE\bin"

E:\kde\kde-bin>cmake ..\kdelibs
CMake Error: CMAKE can not find the command line program cmake.
  argv[0] = "cmake"
  Attempted paths:
    "cmake"
    "C:/home/kingb/My Programs/CMake-vc-7.1-release/bin/Release/cmake.exe"
    "c:/home/kingb/CMakeReleaseInstall/bin/cmake"

CMake Error: Error executing cmake::LoadCache(). Aborting.


E:\kde\kde-bin>set PATH=d:\Programme\CMake 2.3-KDE\bin

E:\kde\kde-bin>cmake ..\kdelibs
-- Check for working C compiler: cl
------------------------8<-------------------


Seems like you don't unqote the PATH correct.
Tested with latest cmake kde release.
(0003716)
Bill Hoffman (manager)
2006-02-10 09:19

What OS/Shell are you using? I am still unable to reproduce this problem. But, it does look like this may be the problem.

(0003717)
Christian Ehrlicher (reporter)
2006-02-10 09:49

cmd.exe on win2ksp4
but I think it also happens on my laptop -> xpsp2
(0003718)
Bill Hoffman (manager)
2006-02-10 11:47

C:\Hoffman\foo\b>set PATH="C:\Hoffman\My Builds\CMakeDev-msys\bin"

C:\Hoffman\foo\b>cmake .
1
1
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Hoffman/foo/b

I even built a cmake with msys, as I assume that is what you did. Perhaps it is an odd bug in the version of msys being used....

(0003719)
Christian Ehrlicher (reporter)
2006-02-10 11:58

Sorry,
I build with msvc vcproj (msvc8 & msvc71)

But I will do some more investigations and let you know when I find something.
Did you try if your access() finds a programm which has " in the name -> "C:\\windows\\system32\\"user32.dll ?
(0003720)
Bill Hoffman (manager)
2006-02-10 12:19

OK, I reprocuded it! I was forgetting to copy the cmake.exe, but I added some print statements to the FindProgram stuff, and saw that it did not handle the "" stuff correctly. I will think of a fix.
(0003721)
Bill Hoffman (manager)
2006-02-10 12:43

$ cvs commit -m "ENH: fix for bug 28618, cmake.exe can not find itself" kwsys/S
ystemTools.cxx
Checking for path: /cvsroot/CMake/CMake/Source/kwsys
Unrestricted user: hoffman
/cvsroot/CMake/CMake/Source/kwsys/SystemTools.cxx,v <-- SystemTools.cxx
new revision: 1.143; previous revision: 1.142


I am not sure it is a good idea to have " in your PATH variable in the first place, but I suppose it can happen and cmd.exe handles it correctly. The fix should work, thanks.

 Issue History
Date Modified Username Field Change


Copyright © 2000 - 2018 MantisBT Team