Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. CMake: Detect platform MacOS. How?
Forum Updated to NodeBB v4.3 + New Features

CMake: Detect platform MacOS. How?

Scheduled Pinned Locked Moved Solved Installation and Deployment
2 Posts 1 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bogong
    wrote on 7 Oct 2022, 15:07 last edited by
    #1

    Hello all!

    In my project need to be defined specified pieces of code for each of platform:

    if(IOS)
    	message(WARNING "iOS Build")
    elseif(ANDROID)
    	message(WARNING "Android Build")
    elseif( (!!!) OSX|MAC|MACOSX )
    	message(WARNING "MacOS build")
    else()
    	message(WARNING "Undefined build")
    endif()
    

    The question is which keyword need to be used for detecting MacOS? Been testing: "MAC", "MACOS" and "MACOSX". Nothing working properly. For iOS and Android all is working properly.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bogong
      wrote on 7 Oct 2022, 15:45 last edited by bogong 10 Oct 2022, 09:34
      #2

      Solution found. Issue closed.
      There need to be added in CMake file something like this:

      if(IOS)
      	if(${CMAKE_OSX_SYSROOT} MATCHES "iphonesimulator")
      		if (${CMAKE_OSX_ARCHITECTURES} MATCHES "arm64")
      			message("-- iOS Build for simulator arm64")
      		elseif(${CMAKE_OSX_ARCHITECTURES} MATCHES "x86_64")
      			message("-- iOS Build for simulator x86_64")
      		endif()
      	elseif(${CMAKE_OSX_SYSROOT} MATCHES "iphoneos")
      		message("-- iOS Build for iphone")
      	else()
      		message(FATAL_ERROR"-- iOS undefined build")
      	endif()
      elseif(ANDROID)
      	if(${ANDROID_ABI} STREQUAL "x86_64")
      		message("-- Android Build for x86_64")
      	elseif(${ANDROID_ABI} STREQUAL "x86")
      		message("-- Android Build for x86")
      	elseif(${ANDROID_ABI} STREQUAL "armeabi-v7a")
      		message("-- Android Build for armeabi-v7a")
      	elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
      		message("-- Android Build for arm64-v8a")
      	else()
      		message(FATAL_ERROR "-- Android undefined build")
      	endif()
      elseif(${CMAKE_OSX_SYSROOT} MATCHES "\/MacOSX.platform\/Developer\/SDKs")
      	message("-- MacOS Build")
      else()
      	message(FATAL_ERROR "-- Undefined build")
      endif()
      

      or use this:

      if(IOS)
      	if(${CMAKE_OSX_SYSROOT} MATCHES "iphonesimulator")
      		if (${CMAKE_OSX_ARCHITECTURES} MATCHES "arm64")
      			message("-- iOS Build for simulator arm64")
      		elseif(${CMAKE_OSX_ARCHITECTURES} MATCHES "x86_64")
      			message("-- iOS Build for simulator x86_64")
      		endif()
      	elseif(${CMAKE_OSX_SYSROOT} MATCHES "iphoneos")
      		message("-- iOS Build for iphone")
      	else()
      		message(FATAL_ERROR"-- iOS undefined build")
      	endif()
      elseif(ANDROID)
      	if(${ANDROID_ABI} STREQUAL "x86_64")
      		message("-- Android Build for x86_64")
      	elseif(${ANDROID_ABI} STREQUAL "x86")
      		message("-- Android Build for x86")
      	elseif(${ANDROID_ABI} STREQUAL "armeabi-v7a")
      		message("-- Android Build for armeabi-v7a")
      	elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
      		message("-- Android Build for arm64-v8a")
      	else()
      		message(FATAL_ERROR "-- Android undefined build")
      	endif()
      elseif(APPLE)
      	if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
      		message("-- MacOS Build for x86_64")
      	elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
      		message("-- MacOS Build for arm64")
      	else()
      		message(FATAL_ERROR "-- MacOS undefined build")
      	endif()
      else()
      	message(FATAL_ERROR "-- Undefined build")
      endif()
      
      1 Reply Last reply
      0

      1/2

      7 Oct 2022, 15:07

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved