[CMake] Windows CMake under cygwin

Bill Hoffman bill.hoffman at kitware.com
Thu Mar 27 13:57:00 EDT 2008


Fernando Cacciola wrote:
> Hi Bill,
> 
>> Fernando Cacciola wrote:
>>> Hi People,
>>>
>>> Due to some project specific constrains, I need to use cmake within
>>> cygwin but to compile using Visual C++ via nmake.
>>> Since the cygwin cmake doesn't support nmake I must use the windows
>>> cmake binary, but naturally knowing that I am running under cygwin.
>>>
>>
>> Can you explain better what you are trying to do?
>>
>> If you are going to use visual C++, then you can run cmake from a cygwin
>> shell and create nmake files no problem.
>>  I do this all the time.  What
>> is it that you want to do with cygwin from visual stuido C++?
>>
> 
> We have a testing system that I haven't yet ported to CTest, etc... 
> which is heavily based on shell scripts.
> To test against Visual C++  I run the testing script under cygwin, but 
> then I need to use the windows cmake binary since the cygwin version of 
> cmake doesn't generate NMakefiles (just ordinary makefiles)
> 
> 
> It all works out of the box provided the enviroment is properly set for 
> the command line Visual C++, but I stumble upon a problem yesterday: one 
> of my users wanted to do "nmake install" and get the results under 
> /usr/local within cygwin (as the previous non-cmake build system was 
> doing).
> 
> It turned out that "/usr/local" is not a valid path for the windows 
> cmake binary (which runs outside cygwin) so I needed to add some code to 
> "fix" that path, but of course, only in that specific condition: windows 
> cmake under cygwin (so I added the posted code that defines 
> WIN32_CMAKE_ON_CYGWIN).
> 
> As I said in a couple of occasions I am porting an existing build system 
> so I have lots of requirements that are perhaps unnatural for CMake, but 
> which I need to satisfy nonetheless.
> 
> Best
> 
> 

OK, so basically, for your project you want to set the install prefix to 
something other than the default.  And, you need it to be able to use 
cygwin paths.  That should not be that hard.

Something like this should work:

# if we are on windows and not cygwin, and the
# install path starts with /usr, then run cygpath to
# to convert the cygwin style path back to a windows path


if(WIN32 AND NOT CYGWIN)
   if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr")
       find_program(CYGPATH cygpath)
       if(NOT CYGPATH)
          message(FATAL_ERROR "Can't find cygpath but you have a cygwin 
path as your install prefix")
        # run cygpath to convert CMAKE_INSTALL_PREFIX
        set(CMAKE_INSTALL_PREFIX thenewpath)

Be careful about having / in your final path and not \.




-Bill


More information about the CMake mailing list