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 
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:
C:\tmp\CMake_bin>cmake ..\cmake-cvs
CMake Error: CMAKE can not find the command line program cmake.
  argv[0] = "cmake"
  Attempted paths:
    "C:/Programme/CMake 2.3-KDE/bin/bin/./cmake.exe"

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]:

  // 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;
  m_CMakeCommand = args[0];
-> 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


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.
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).
Bill Hoffman (manager)
2006-02-08 12:19

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

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.
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.
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.
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.
Christian Ehrlicher (reporter)
2006-02-10 00:33

think I've got it now:

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:
    "C:/home/kingb/My Programs/CMake-vc-7.1-release/bin/Release/cmake.exe"

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

Seems like you don't unqote the PATH correct.
Tested with latest cmake kde release.
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.

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

cmd.exe on win2ksp4
but I think it also happens on my laptop -> xpsp2
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 .
-- 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....

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

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 ?
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.
Bill Hoffman (manager)
2006-02-10 12:43

$ cvs commit -m "ENH: fix for bug 28618, cmake.exe can not find itself" kwsys/S
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