[CMake] Detecting MinGW MSYS or Cygwin unix style file system

William A. Hoffman billlist at nycap.rr.com
Tue Nov 22 17:33:20 EST 2005


At 09:35 AM 11/22/2005, Brandon J. Van Every wrote:
>Hi, I'm going up the CMake Windows learning curve on behalf of Chicken Scheme.
>http://www.call-with-current-continuation.org/index.html
>I have read the archives quite a bit and I think it's time to ask the question.
>
>I notice that on Windows the default CMAKE_INSTALL_PREFIX is "C:/Program Files".  However, this doesn't actually make sense to a MinGW user employing MSYS.  MSYS implements a unix-style file system, so a proper prefix would more likely be "/usr/local".  However, the wrinkle is it's also perfectly legitimate to use MinGW sans MSYS, and install things to "C:/Program Files" in the normal Windows way.  It's really MSYS that's the dependency here, not MinGW.  And so, I would like to detect MSYS and "do the right thing" for people who are using Windows as a Unix-alike.  
>Not because I love Unix, but because I want to keep my MSYS and "normal Windows" environments completely separate from each other.  When people try out Chicken, I want to be able to ask "are you using the MinGW, the Cygwin, or the VC++ build?" and not have there be any confusion about what got installed where.

This is a bug, for MINGW, it should not be "C:/Program Files".   Please create a bug report
www.cmake.org/Bug


>Does a similar issue pertain to Cygwin?  Maybe not, as the archives seemed to indicate that it may use /usr/local by default.  I am not wishing to try this out if I can avoid it.  :-)  Aside from being highly biased towards MinGW support issues, it happens that Eclipse gets messed up if both are on one's system.

For cygwin, you should use the cmake built for cygwin, it is available via the cygwin setup program.  It will use unix paths.

>Gleaning knowledge from the archives, I have created a PreLoad.cmake which successfully detects MSYS.  My understanding is that this command must be in PreLoad.cmake, that it cannot just be in CMakeLists.txt, as it must be set before anything else happens.  Correct?
>
>IF(WIN32)
> IF("$ENV{OSTYPE}" STREQUAL "msys")
>    SET(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH
>        "MSYS default install path")
> ENDIF("$ENV{OSTYPE}" STREQUAL "msys")
>ENDIF(WIN32)
>
>I am wondering if CMake has its own, native, more reliable way of doing this.  If it doesn't, I'm thinking it should, because MinGW and MSYS are like bread and butter, even if bread can be eaten without butter.  :-)  
>I am also wondering if anyone knows if OSTYPE is a reliable indicator.  
>I just looked at what was in the environment and figured, heh, this looks like it'll work.

Anther way to do this until the bug is fixed is just to add the following into the chicken cmakelist file:

IF(MINGW)
  SET(CHICKEN_INSTALL_PREFIX "/usr/local" CACHE PATH "Mingw  default install path")
ELSE(MINGW)
  SET(CHICKEN_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "default install path")
ENDIF(MINGW)
SET(CMAKE_INSTALL_PREFIX ${CHICKEN_INSTALL_PREFIX} CACHE INTERNAL "")

This is a common way of overriding a cmake variable.   It will hide the cmake variable CMAKE_INSTALL_PREFIX
and make it always the same as CHICKEN_INSTALL_PREFIX.   I tested the above, and it sets the install
prefix to /usr/local if you pick "Unix Makefiles" from a CMakeSetup run from msys.

-Bill



More information about the CMake mailing list