# MacOS-specific toolchain template file for clang running on {{ARCH}} {{OS}}
set(CMAKE_SYSTEM_NAME {{OS}})
set(CMAKE_SYSTEM_PROCESSOR {{ARCH}})
set(CMAKE_SYSTEM_VERSION 14.5)

# Extract out DARWIN_MAJOR_VERSION and DARWIN_MINOR_VERSION
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}")

# Enable rpath support
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")

set(CMAKE_SYSROOT /opt/{{TARGET}}/{{TARGET}}/sys-root)
set(CMAKE_SYSTEM_FRAMEWORK_PATH
    ${CMAKE_SYSROOT}/System/Library/Frameworks
    ${CMAKE_SYSROOT}/System/Library/PrivateFrameworks
)
set(CMAKE_INSTALL_PREFIX $ENV{prefix})

set(CMAKE_C_COMPILER /opt/x86_64-linux-gnu/tools/clang)
set(CMAKE_CXX_COMPILER /opt/x86_64-linux-gnu/tools/clang++)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target x86_64-apple-darwin14 --sysroot ${CMAKE_SYSROOT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -target x86_64-apple-darwin14 --sysroot ${CMAKE_SYSROOT} -stdlib=libc++")

if( $ENV{CC} MATCHES ccache )
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
endif()

