
function(get_c_compiler_id COMPILER_ID)
    if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
        set(${COMPILER_ID} "gcc" PARENT_SCOPE)
    elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "clang")
        set(${COMPILER_ID} "clang" PARENT_SCOPE)
    elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
        set(${COMPILER_ID} "intel" PARENT_SCOPE)
    elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
        set(${COMPILER_ID} "msvc" PARENT_SCOPE)
        # message(STATUS "get_c_compiler_id() msvc: COMPILER_ID = ${COMPILER_ID}")
    else()
        set(${COMPILER_ID} "" PARENT_SCOPE)
        # message(STATUS "get_c_compiler_id() unknown: COMPILER_ID = ${COMPILER_ID}")
    endif()
endfunction(get_c_compiler_id)

function(get_cxx_compiler_id COMPILER_ID)
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        set(${COMPILER_ID} "gcc" PARENT_SCOPE)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "clang")
        set(${COMPILER_ID} "clang" PARENT_SCOPE)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
        set(${COMPILER_ID} "intel" PARENT_SCOPE)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
        set(${COMPILER_ID} "msvc" PARENT_SCOPE)
        # message(STATUS "get_cxx_compiler_id() msvc: COMPILER_ID = ${COMPILER_ID}")
    else()
        set(${COMPILER_ID} "" PARENT_SCOPE)
        # message(STATUS "get_cxx_compiler_id() unknown: COMPILER_ID = ${COMPILER_ID}")
    endif()
endfunction(get_cxx_compiler_id)

function(get_compiler_id COMPILER_ID IS_C_OR_CXX)
    set(LOCAL_COMPILER_ID)
    if ((IS_C_OR_CXX STREQUAL "cxx") OR (IS_C_OR_CXX STREQUAL "cpp") OR (IS_C_OR_CXX STREQUAL "cc"))
        get_cxx_compiler_id(LOCAL_COMPILER_ID)
    else()
        get_c_compiler_id(LOCAL_COMPILER_ID)
    endif()
    # message(STATUS "get_compiler_id(): LOCAL_COMPILER_ID = ${LOCAL_COMPILER_ID}")
    set(${COMPILER_ID} "${LOCAL_COMPILER_ID}" PARENT_SCOPE)
endfunction(get_compiler_id)

function(GetCompilerToolset TOOLSET IS_C_OR_CXX)
    # message(STATUS "IS_C_OR_CXX = ${IS_C_OR_CXX}")
    set(LOCAL_COMPILER_ID)
    get_compiler_id(LOCAL_COMPILER_ID ${IS_C_OR_CXX})
    if (JLANG_CMAKE_SHOW_DETAIL)
        message(STATUS "LOCAL_COMPILER_ID = ${LOCAL_COMPILER_ID}")
    endif()
    if (MSVC_IDE)
        if (MSVC60)
            set(${TOOLSET} "vc60" PARENT_SCOPE)
        elseif (MSVC70)
            set(${TOOLSET} "vc2003" PARENT_SCOPE)
        elseif (MSVC71)
            set(${TOOLSET} "vc2003" PARENT_SCOPE)
        elseif (MSVC80)
            set(${TOOLSET} "vc2005" PARENT_SCOPE)
        elseif (CMAKE_COMPILER_2005)
            set(${TOOLSET} "vc2005" PARENT_SCOPE)
        elseif (MSVC90)
            set(${TOOLSET} "vc2008" PARENT_SCOPE)
        elseif (MSVC10)
            set(${TOOLSET} "vc2010" PARENT_SCOPE)
        elseif (MSVC11)
            set(${TOOLSET} "vc2012" PARENT_SCOPE)
        elseif (MSVC12)
            set(${TOOLSET} "vc2013" PARENT_SCOPE)
        elseif (MSVC13)
            set(${TOOLSET} "vc2014" PARENT_SCOPE)
        else()
            if (NOT LOCAL_COMPILER_ID STREQUAL "")
                set(${TOOLSET} "${LOCAL_COMPILER_ID}" PARENT_SCOPE)
            else()
                set(${TOOLSET} "msvc" PARENT_SCOPE)
            endif()
        endif()
    elseif (MINGW)
        if (NOT LOCAL_COMPILER_ID STREQUAL "")
            set(${TOOLSET} "mingw_${LOCAL_COMPILER_ID}" PARENT_SCOPE)
        else()
            set(${TOOLSET} "mingw" PARENT_SCOPE)
        endif()
    elseif (CYGWIN)
        if (NOT LOCAL_COMPILER_ID STREQUAL "")
            set(${TOOLSET} "cygwin_${LOCAL_COMPILER_ID}" PARENT_SCOPE)
        else()
            set(${TOOLSET} "cygwin" PARENT_SCOPE)
        endif()
    elseif (BORLAND)
        if (NOT LOCAL_COMPILER_ID STREQUAL "")
            set(${TOOLSET} "borland_${LOCAL_COMPILER_ID}" PARENT_SCOPE)
        else()
            set(${TOOLSET} "borland" PARENT_SCOPE)
        endif()
    elseif (WATCOM)
        if (NOT LOCAL_COMPILER_ID STREQUAL "")
            set(${TOOLSET} "watcom_${LOCAL_COMPILER_ID}" PARENT_SCOPE)
        else()
            set(${TOOLSET} "watcom" PARENT_SCOPE)
        endif()
    else()
        set(${TOOLSET} "" PARENT_SCOPE)
    endif(MSVC_IDE)
endfunction(GetCompilerToolset)
