[CMake] Windows CMake under cygwin

Fernando Cacciola fernando.cacciola at gmail.com
Thu Mar 27 12:56:15 EDT 2008


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.

I couldn't find any preset variable that could tell me this, so I'm using 
the follow code to that effect:

  if ( WIN32 )
    find_program(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
    if(CMAKE_UNAME)
      exec_program(uname ARGS -s OUTPUT_VARIABLE CMAKE_SYSTEM_NAME2)
      if ( CMAKE_SYSTEM_NAME2 MATCHES "CYGWIN" )
        message( STATUS "This is the Windows CMake running within the cygwin 
platform." )
        set( WIN32_CMAKE_ON_CYGWIN TRUE CACHE INTERNAL "This is the cygwin 
platform." )
      endif()
    endif()
  endif()

Any crictisim is more than welcome at this point :)

I needed this new WIN32_CMAKE_ON_CYGWIN variable to correctly handle 
installation within the cygwin hierarchy.
The follwing code:

if ( WIN32_CMAKE_ON_CYGWIN )
  exec_program(cygpath ARGS -w ${CMAKE_INSTALL_PREFIX} OUTPUT_VARIABLE 
CMAKE_INSTALL_PREFIX2 )
  file ( TO_CMAKE_PATH ${CMAKE_INSTALL_PREFIX2} CMAKE_INSTALL_PREFIX )
endif()

Allows my users to set the install prefix either 
as -DCMAKE_INSTALL_PREFIX=/usr/local 
or -DCMAKE_INSTALL_PREFIX=C:\MyLibraries\ProjectXYZ.

(NOTE: In Vista the default %PROGRAMFILES% prefix doesn't really work 
because of access restrictions which I couldn't get cygwin it to have.)


FYI, that transformation turns "/usr/local" into "C:/cygwin/usr/local", 
which I found to be needed by the windows cmake binary as it uses low-level 
FILE( INSTALL ) commands to do the actual installation when "nmake install" 
is executed.

Best


-- 
Fernando Cacciola
SciSoft
http://fcacciola.50webs.com
http://groups.google.com/group/cppba





More information about the CMake mailing list