How to check the operating system is MacOSX?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to check the operating system is MacOSX?

Loaden
Follow this wiki: http://www.itk.org/Wiki/CMake/Examples#Check_operating_system
There say:
 IF(WIN32)
   ...do something...
 ELSE(WIN32)
   ...do something else...
 ENDIF(WIN32)

or:


IF(CMAKE_SYSTEM_NAME STREQUAL Linux)

As I know:
if (APPLE)
...
endif()
is not enough.

For now I have to using:

if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    set(WINDOWS TRUE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    set(LINUX TRUE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    set(MACOSX TRUE)
endif()

My question:
How to check the operating system is MacOSX?

--
Best Regards
Yuchen


--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Alexander Neundorf-3
On Saturday 15 September 2012, Loaden wrote:

> Follow this wiki:
> http://www.itk.org/Wiki/CMake/Examples#Check_operating_system
>
> There say:
> >  IF(WIN32)
> >  
> >    ...do something...
> >  
> >  ELSE(WIN32)
> >  
> >    ...do something else...
> >  
> >  ENDIF(WIN32)
> >
> >  or:
> > IF(CMAKE_SYSTEM_NAME STREQUAL Linux)
>
> As I know:
> if (APPLE)
> ...
> endif()
> is not enough.


Why do you think it is not enough ?

Alex
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Loaden
http://www.cmake.org/Wiki/CMake_Useful_Variables

UNIX 
is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
WIN32 
is TRUE on Windows, including CygWin
APPLE 
is TRUE on Apple systems. Note this does not imply the system is Mac OS X, only that __APPLE__ is #defined in C/C++ header files. Obtain more specific system information via CMAKE_SYSTEM_VERSION, i.e. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin"), then it's Mac OS X.

2012/9/15 Alexander Neundorf <[hidden email]>
Why do you think it is not enough ?



--
Best Regards
Yuchen


--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Andreas Pakulat-2
Hi,

On Sat, Sep 15, 2012 at 12:46 PM, Loaden <[hidden email]> wrote:
> http://www.cmake.org/Wiki/CMake_Useful_Variables
>
>> UNIX  is TRUE on all UNIX-like OS's, including Apple OS X and CygWin WIN32
>> is TRUE on Windows, including CygWin APPLE  is TRUE on Apple systems. Note
>> this does not imply the system is Mac OS X, only that __APPLE__ is #defined
>> in C/C++ header files. Obtain more specific system information via
>> CMAKE_SYSTEM_VERSION, i.e. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin"), then
>> it's Mac OS X.

I think that mostly refers to MacOS 9 and older which are also apple
systems. So doing a if(UNIX && APPLE) should put you on the safe side
since MacOS 9 and older are not unix systems.

Andreas
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Michael Jackson
On Sep 15, 2012, at 1:32 PM, Andreas Pakulat wrote:

> Hi,
>
> On Sat, Sep 15, 2012 at 12:46 PM, Loaden <[hidden email]> wrote:
>> http://www.cmake.org/Wiki/CMake_Useful_Variables
>>
>>> UNIX  is TRUE on all UNIX-like OS's, including Apple OS X and CygWin WIN32
>>> is TRUE on Windows, including CygWin APPLE  is TRUE on Apple systems. Note
>>> this does not imply the system is Mac OS X, only that __APPLE__ is #defined
>>> in C/C++ header files. Obtain more specific system information via
>>> CMAKE_SYSTEM_VERSION, i.e. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin"), then
>>> it's Mac OS X.
>
> I think that mostly refers to MacOS 9 and older which are also apple
> systems. So doing a if(UNIX && APPLE) should put you on the safe side
> since MacOS 9 and older are not unix systems.
>
> Andreas

Does CMake even run on OS 9? I don't think so. IMO, I think what the CMake devs mean is that one can cross-compile OS X apps on Linux. In this case the __APPLE__ would be defined in the headers but the "host" system would be Linux (or something else).
  And "technically" if the system is Darwin it is NOT OS X. Darwin is the Unix underpinnings of OS X and it is Open Source. I could run a Darwin system and have it NOT be OS X.
--
Mike Jackson <www.bluequartz.net>

--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Eric Wing
On 9/16/12, Michael Jackson <[hidden email]> wrote:

> On Sep 15, 2012, at 1:32 PM, Andreas Pakulat wrote:
>
>> Hi,
>>
>> On Sat, Sep 15, 2012 at 12:46 PM, Loaden <[hidden email]> wrote:
>>> http://www.cmake.org/Wiki/CMake_Useful_Variables
>>>
>>>> UNIX  is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
>>>> WIN32
>>>> is TRUE on Windows, including CygWin APPLE  is TRUE on Apple systems.
>>>> Note
>>>> this does not imply the system is Mac OS X, only that __APPLE__ is
>>>> #defined
>>>> in C/C++ header files. Obtain more specific system information via
>>>> CMAKE_SYSTEM_VERSION, i.e. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin"),
>>>> then
>>>> it's Mac OS X.
>>
>> I think that mostly refers to MacOS 9 and older which are also apple
>> systems. So doing a if(UNIX && APPLE) should put you on the safe side
>> since MacOS 9 and older are not unix systems.
>>
>> Andreas
>
> Does CMake even run on OS 9? I don't think so. IMO, I think what the CMake
> devs mean is that one can cross-compile OS X apps on Linux. In this case the
> __APPLE__ would be defined in the headers but the "host" system would be
> Linux (or something else).
>   And "technically" if the system is Darwin it is NOT OS X. Darwin is the
> Unix underpinnings of OS X and it is Open Source. I could run a Darwin
> system and have it NOT be OS X.


Being able to distinguish between Mac OS X and iOS would be useful.
Both technically fall under APPLE and Darwin.


-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Doug
As far as I'm aware the only real way to detect OSX itself is by something like:

#if __APPLE__
  #include "TargetConditionals.h"
  #if TARGET_OS_IPHONE
    ...
  #elif TARGET_IPHONE_SIMULATOR
    ...
  #elif TARGET_OS_MAC
    ...
  #endif
#endif

__APPLE__ is the only constant attached to compiler itself.

~
Doug.

On Mon, Sep 17, 2012 at 6:08 AM, Eric Wing <[hidden email]> wrote:

> On 9/16/12, Michael Jackson <[hidden email]> wrote:
>> On Sep 15, 2012, at 1:32 PM, Andreas Pakulat wrote:
>>
>>> Hi,
>>>
>>> On Sat, Sep 15, 2012 at 12:46 PM, Loaden <[hidden email]> wrote:
>>>> http://www.cmake.org/Wiki/CMake_Useful_Variables
>>>>
>>>>> UNIX  is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
>>>>> WIN32
>>>>> is TRUE on Windows, including CygWin APPLE  is TRUE on Apple systems.
>>>>> Note
>>>>> this does not imply the system is Mac OS X, only that __APPLE__ is
>>>>> #defined
>>>>> in C/C++ header files. Obtain more specific system information via
>>>>> CMAKE_SYSTEM_VERSION, i.e. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin"),
>>>>> then
>>>>> it's Mac OS X.
>>>
>>> I think that mostly refers to MacOS 9 and older which are also apple
>>> systems. So doing a if(UNIX && APPLE) should put you on the safe side
>>> since MacOS 9 and older are not unix systems.
>>>
>>> Andreas
>>
>> Does CMake even run on OS 9? I don't think so. IMO, I think what the CMake
>> devs mean is that one can cross-compile OS X apps on Linux. In this case the
>> __APPLE__ would be defined in the headers but the "host" system would be
>> Linux (or something else).
>>   And "technically" if the system is Darwin it is NOT OS X. Darwin is the
>> Unix underpinnings of OS X and it is Open Source. I could run a Darwin
>> system and have it NOT be OS X.
>
>
> Being able to distinguish between Mac OS X and iOS would be useful.
> Both technically fall under APPLE and Darwin.
>
>
> -Eric
> --
> Beginning iPhone Games Development
> http://playcontrol.net/iphonegamebook/
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Doug
Just idly though, I've never yet encountered a situation where:

if(APPLE)
  ...
elseif(UNIX)
  ...
endif()

Wasn't sufficient. The only time I've come close is having to build
automake projects with different flags depending on the os base, and
then (since it only worked under cygwin or msys anyway) if(WIN32) ...
elseif(APPLE) ... else ... endif worked fine.

~
Doug.

On Tue, Sep 18, 2012 at 9:52 PM, Doug <[hidden email]> wrote:

> As far as I'm aware the only real way to detect OSX itself is by something like:
>
> #if __APPLE__
>   #include "TargetConditionals.h"
>   #if TARGET_OS_IPHONE
>     ...
>   #elif TARGET_IPHONE_SIMULATOR
>     ...
>   #elif TARGET_OS_MAC
>     ...
>   #endif
> #endif
>
> __APPLE__ is the only constant attached to compiler itself.
>
> ~
> Doug.
>
> On Mon, Sep 17, 2012 at 6:08 AM, Eric Wing <[hidden email]> wrote:
>> On 9/16/12, Michael Jackson <[hidden email]> wrote:
>>> On Sep 15, 2012, at 1:32 PM, Andreas Pakulat wrote:
>>>
>>>> Hi,
>>>>
>>>> On Sat, Sep 15, 2012 at 12:46 PM, Loaden <[hidden email]> wrote:
>>>>> http://www.cmake.org/Wiki/CMake_Useful_Variables
>>>>>
>>>>>> UNIX  is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
>>>>>> WIN32
>>>>>> is TRUE on Windows, including CygWin APPLE  is TRUE on Apple systems.
>>>>>> Note
>>>>>> this does not imply the system is Mac OS X, only that __APPLE__ is
>>>>>> #defined
>>>>>> in C/C++ header files. Obtain more specific system information via
>>>>>> CMAKE_SYSTEM_VERSION, i.e. IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin"),
>>>>>> then
>>>>>> it's Mac OS X.
>>>>
>>>> I think that mostly refers to MacOS 9 and older which are also apple
>>>> systems. So doing a if(UNIX && APPLE) should put you on the safe side
>>>> since MacOS 9 and older are not unix systems.
>>>>
>>>> Andreas
>>>
>>> Does CMake even run on OS 9? I don't think so. IMO, I think what the CMake
>>> devs mean is that one can cross-compile OS X apps on Linux. In this case the
>>> __APPLE__ would be defined in the headers but the "host" system would be
>>> Linux (or something else).
>>>   And "technically" if the system is Darwin it is NOT OS X. Darwin is the
>>> Unix underpinnings of OS X and it is Open Source. I could run a Darwin
>>> system and have it NOT be OS X.
>>
>>
>> Being able to distinguish between Mac OS X and iOS would be useful.
>> Both technically fall under APPLE and Darwin.
>>
>>
>> -Eric
>> --
>> Beginning iPhone Games Development
>> http://playcontrol.net/iphonegamebook/
>> --
>>
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Eric Wing
On 9/18/12, Doug <[hidden email]> wrote:
> Just idly though, I've never yet encountered a situation where:
>
> if(APPLE)
>   ...
> elseif(UNIX)
>   ...
> endif()
>
> Wasn't sufficient.

I have plenty of these situations :P

The most common case though is that 3rd party dynamic libraries are
not allowed on iOS so generally I have to build things differently for
iOS.

Another case is sometimes features need to be removed to avoid the
risk of rejection by the AppStore (e.g. don't compile in calls to
mprotect()).

And sometimes sub-components need to be different/replaced/removed
compared to their Mac counterparts. LGPL libraries are a frequent
issue. But specializations such as Ogg Vorbis vs. Ogg Tremor (integer
version) also require different build instructions depending on the
platform (Mac vs. iOS). x86 is not an indicator because the iOS
Simulator is i386 which needs to be compiled like any other iOS
device.

-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Eric Wing
In reply to this post by Eric Wing
On 9/18/12, Stefan Reuschl <[hidden email]> wrote:
> How do you crosscompile for iOS?
> If using a CMake toolchain you could simply set a variable in that file, I
> which you could check later...

Right now I'm not brave enough to try using CMake for iOS and Android.
I maintain separate projects. But someday I would like to do away with
that.

-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to check the operating system is MacOSX?

Doug
Perhaps use check_c_source_compiles?

## Check for specific apple platforms
macro(check_apple_platform)
  if(APPLE)
    include(CheckCSourceCompiles)
    check_c_source_compiles("
      #include \"TargetConditionals.h\"
      int main(int argc, char *argv[]) {
      #if !TARGET_OS_MAC
        -1
      #endif
      }
    " OS_OSX)
    check_c_source_compiles("
      #include \"TargetConditionals.h\"
      int main(int argc, char *argv[]) {
      #if !TARGET_OS_IPHONE
        -1
      #endif
      }
    " OS_IPHONE)
  endif()
endmacro()

check_apple_platform()
if(OS_OSX)
  message("Found OSX")
else()
  message("Found no OSX")
endif()
if(OS_IPHONE)
  message("Found IPHONE")
else()
  message("Found no IPHONE")
endif()

~
Doug.

On Wed, Sep 19, 2012 at 4:52 AM, Eric Wing <[hidden email]> wrote:

> On 9/18/12, Stefan Reuschl <[hidden email]> wrote:
>> How do you crosscompile for iOS?
>> If using a CMake toolchain you could simply set a variable in that file, I
>> which you could check later...
>
> Right now I'm not brave enough to try using CMake for iOS and Android.
> I maintain separate projects. But someday I would like to do away with
> that.
>
> -Eric
> --
> Beginning iPhone Games Development
> http://playcontrol.net/iphonegamebook/
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake