if(APPLE)
    set(ORIGINAL_APPLE 1)
elseif(UNIX)
    set(ORIGINAL_UNIX 1)
elseif(WIN32)
    set(ORIGINAL_WIN32 1)
endif()

macro(mask_host_to_target)
    if(CMAKE_HOST_WIN32)
        set(WIN32 1)
        unset(APPLE)
        unset(UNIX)
    elseif(CMAKE_HOST_APPLE)
        set(APPLE 1)
        unset(WIN32)
        unset(UNIX)
    elseif(CMAKE_HOST_UNIX)
        set(UNIX 1)
        unset(WIN32)
        unset(APPLE)
    endif()
endmacro()

macro(restore_target)
    unset(APPLE)
    unset(UNIX)
    unset(WIN32)
    if(ORIGINAL_APPLE)
        set(APPLE 1)
    elseif(ORIGINAL_UNIX)
        set(UNIX 1)
    elseif(ORIGINAL_WIN32)
        set(WIN32 1)
    endif()
endmacro()

# macro to find packages on the host OS
macro(find_host_package)
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
    mask_host_to_target()
    find_package(${ARGN})
    restore_target()
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endmacro()

# macro to find programs on the host OS
macro(find_host_program)
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
    mask_host_to_target()
    find_program(${ARGN})
    restore_target()
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endmacro()
