SET(PARSE_IF_DEBUG OFF)
SET(IF_PARAM1 "")
SET(IF_PARAM2 "")

function(marchIfBrackets in out)
    set(marchIfBrackets_str "${in}")
    set(marchIfBrackets_num "0")
    set(marchIfBrackets_split "")
    string(LENGTH "${marchIfBrackets_str}" marchIfBrackets_length)
    math(EXPR marchIfBrackets_last_index "${marchIfBrackets_length} - 1")
    foreach(marchIfBrackets_index RANGE "${marchIfBrackets_last_index}" "0")
        string(SUBSTRING "${marchIfBrackets_str}" "${marchIfBrackets_index}" "1" marchIfBrackets_sub)

        if("${marchIfBrackets_sub}" STREQUAL ")" )
            math(EXPR marchIfBrackets_num "${marchIfBrackets_num} + 1")
        elseif("${marchIfBrackets_sub}" STREQUAL "(" )
            math(EXPR marchIfBrackets_num "${marchIfBrackets_num} - 1")
        elseif("${marchIfBrackets_sub}" STREQUAL ",")
            #判断是否有括号对
            if("${marchIfBrackets_num}" EQUAL "1" )
                math(EXPR marchIfBrackets_index_end "${marchIfBrackets_index} + 1")
                string(SUBSTRING "${marchIfBrackets_str}" "${marchIfBrackets_index_end}" "65536" marchIfBrackets_tmp_str)
                string(SUBSTRING "${marchIfBrackets_str}" "0" "${marchIfBrackets_index}" marchIfBrackets_str)
                string(STRIP ${marchIfBrackets_tmp_str} marchIfBrackets_tmp_str)
                list(INSERT marchIfBrackets_split "0" "${marchIfBrackets_tmp_str}")
            endif()
        endif()
    endforeach()

    if(NOT marchIfBrackets_split)
        set(marchIfBrackets_split "${in}")
    endif()

    if(marchIfBrackets_str)
        list(INSERT marchIfBrackets_split "0" "${marchIfBrackets_str}")
    endif()

    if (PARSE_IF_DEBUG)
        message("marchIfBrackets_split:${marchIfBrackets_split}")
    endif ()
    set(${out} "${marchIfBrackets_split}" PARENT_SCOPE)
endfunction()

function(parseIf line param1 param2)
    string(STRIP ${line} parseIf_line)
    marchIfBrackets("${parseIf_line}" parseIf_line_out)

    string(REGEX REPLACE "^\\(" "" parseIf_line_out "${parseIf_line_out}")
    string(REGEX REPLACE "\\)$" "" parseIf_line_out "${parseIf_line_out}")
#    if( "${parseIf_line}" MATCHES "^,.*" )
#        string(REGEX REPLACE "^," ";" parseIf_line_list ${parseIf_line})
#    elseif("${parseIf_line}" MATCHES ".*,$")
#        string(REGEX REPLACE ",$" ";" parseIf_line_list ${parseIf_line})
#    else()
#
#        string(REPLACE "," ";" parseIf_line_list ${parseIf_line})
#    endif()
    list(GET parseIf_line_out 0 parseIf_local_param1)
    list(GET parseIf_line_out 1 parseIf_local_param2)
    if(PARSE_IF_DEBUG)
        message("parseIf: param1 = ${parseIf_local_param1}")
        message("parseIf: param2 = ${parseIf_local_param2}")
    endif()

    parseMakeFileFunc("${parseIf_local_param1}" parseIf_local_param1)
    SET(${param1} ${parseIf_local_param1} PARENT_SCOPE)
    parseMakeFileFunc("${parseIf_local_param2}" parseIf_local_param2)
    SET(${param2} ${parseIf_local_param2} PARENT_SCOPE)
endfunction()

function(doIfeq line block)
    parseIf(${line} doIfeq_IF_PARAM1 doIfeq_IF_PARAM2)
    if(PARSE_IF_DEBUG)
        message("doIfeq: IF_PARAM1 = ${doIfeq_IF_PARAM1}")
        message("doIfeq: IF_PARAM2 = ${doIfeq_IF_PARAM2}")
    endif()
    if( "${doIfeq_IF_PARAM1}" STREQUAL "${doIfeq_IF_PARAM2}" )
        SET(${block} OFF PARENT_SCOPE)
    else()
        SET(${block} ON  PARENT_SCOPE)
    endif()
endfunction()

function(doIfneq line block)
    parseIf(${line} doIfneq_IF_PARAM1 doIfneq_IF_PARAM2)
    if(PARSE_IF_DEBUG)
        message("doIfneq: IF_PARAM1 = ${doIfneq_IF_PARAM1}")
        message("doIfneq: IF_PARAM2 = ${doIfneq_IF_PARAM2}")
    endif()
    if( "${doIfneq_IF_PARAM1}" STREQUAL "${doIfneq_IF_PARAM2}" )
        if(PARSE_IF_DEBUG)
            message("doIfneq: block = ON")
        endif()
        SET(${block} ON PARENT_SCOPE)
    else()
        if(PARSE_IF_DEBUG)
            message("doIfneq: block = OFF")
        endif()
        SET(${block} OFF  PARENT_SCOPE)
    endif()
endfunction()