[CMake] Differentiate between Linux and FreeBSD

Horacio Sanson hsanson at gmail.com
Mon Apr 21 21:22:34 EDT 2008


On Mon, Apr 21, 2008 at 7:01 PM, Pau Garcia i Quiles
<pgquiles at elpauer.org> wrote:
>
> Quoting Horacio Sanson <hsanson at gmail.com>:
>
>
> > I can use IF(WIN32) and IF(UNIX) to set some variables depending if
> > cmake is executed in Windows or UNIX systems. The problem is that UNIX
> > in this context includes both Linux and FreeBSD.
> >
> > Has CMake a way to know if it is running in a Linux box or a FreeBSD box??
> >
>
>  Use the CMAKE_SYSTEM_NAME variable:

I tried using this variable but for some reason it seems to be empty
(i.e. calling MESSAGE with this var as parameter does not print
anything). This happens in both Linux (Kubuntu 7.10) and FreeBSD 7.1.

My solution now is to use EXEC_PROGRAM with uname:

###################################
# start CMakeFiles.txt
###################################
EXEC_PROGRAM(uname OUTPUT_VARIABLE SYSTEM_NAME)
SET(SYSTEM_NAME "${SYSTEM_NAME}" CACHE INTERNAL "")

IF(SYSTEM_NAME STREQUAL "Linux")
   MESSAGE("LINUX BOX")
ENDIF(SYSTEM_NAME STREQUAL "Linux")

IF(SYSTEM_NAME STREQUAL "FreeBSD")
   MESSAGE("FREEBSD BOX")
ENDIF(SYSTEM_NAME STREQUAL "FreeBSD")

###################################
# end CMakeFiles.txt
###################################

regards,
Horacio

>

> http://www.cmake.org/Wiki/CMake_Useful_Variables#System_.26_Compiler_Information
>
>  --
>  Pau Garcia i Quiles
>  http://www.elpauer.org
>  (Due to my workload, I may need 10 days to answer)
>
>  _______________________________________________
>  CMake mailing list
>  CMake at cmake.org
>  http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list