if ((CMAKE_MAJOR_VERSION GREATER_EQUAL 3) AND (CMAKE_MINOR_VERSION GREATER_EQUAL 14))
  # CMake 3.14 added support for Apple platform cross-building
  # Platform/CMAKE_SYSTEM_NAME.cmake will be called later
  # Those files have broken quite a lot of things
  set(CMAKE_SYSTEM_NAME $ENV{CONAN_CMAKE_SYSTEM_NAME})
else()
  set(CMAKE_SYSTEM_NAME Darwin)
endif()

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)

if(DEFINED ENV{CONAN_CMAKE_XCODE_ATTRIBUTE_EMBED_BITCODE})
  set(CMAKE_XCODE_ATTRIBUTE_EMBED_BITCODE "$ENV{CONAN_CMAKE_XCODE_ATTRIBUTE_EMBED_BITCODE}")
endif()
if(DEFINED ENV{CONAN_CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE})
  set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE "$ENV{CONAN_CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE}")
endif()
set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "$ENV{CONAN_CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC}")
set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "$ENV{CONAN_CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN}")
set(CMAKE_XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN "$ENV{CONAN_CMAKE_XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN}")
set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO")

set(CMAKE_OSX_SYSROOT "$ENV{CONAN_CMAKE_OSX_SYSROOT}")
# FORCE seems to be required override cmake's default.
set(CMAKE_OSX_ARCHITECTURES "$ENV{CONAN_CMAKE_OSX_ARCHITECTURES}" CACHE STRING "" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "$ENV{CONAN_CMAKE_OSX_DEPLOYMENT_TARGET}" CACHE STRING "" FORCE)

# Setting CMAKE_SYSTEM_NAME results it CMAKE_SYSTEM_VERSION not being set
# For some reason, it must be the Darwin version (otherwise Platform/Darwin.cmake will not set some flags)
# Most probably a CMake bug... (https://gitlab.kitware.com/cmake/cmake/issues/20036)
set(CMAKE_SYSTEM_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
set(CMAKE_SYSTEM_PROCESSOR "$ENV{CONAN_CMAKE_SYSTEM_PROCESSOR}")
