macro(readIfExists VAR_NAME FILE TYPE DEFAULT_VALUE)
    if (EXISTS ${FILE})
        file(READ ${FILE} ${VAR_NAME})
    endif()
    message(STATUS ${${VAR_NAME}})
    if (DEFINED ENV{${VAR_NAME}})
        set(${VAR_NAME} $ENV{${VAR_NAME}})
    endif()
    message(STATUS ${${VAR_NAME}})
    if(NOT DEFINED ${VAR_NAME} AND DEFINED DEFAULT_VALUE)
        set(${VAR_NAME} ${DEFAULT_VALUE})
    endif()
    if(DEFINED ${VAR_NAME})
        set(${VAR_NAME}_TYPE "${TYPE}")
        list(APPEND SECRETS_LIST ${VAR_NAME})
    endif()
endmacro()


readIfExists(ADB_APP_ID "${ADB_ROOT_DIR}/cfg/secrets/appId.txt" INT 0)
readIfExists(ADB_PUBLIC_KEY "${ADB_ROOT_DIR}/cfg/secrets/publicKey.txt" STR "0")
readIfExists(ADB_CLIENT_ID "${ADB_ROOT_DIR}/cfg/secrets/clientId.txt" INT 0)
readIfExists(ADB_CLIENT_SECRET "${ADB_ROOT_DIR}/cfg/secrets/clientSecret.txt" STR "0")
readIfExists(ADB_BOT_TOKEN "${ADB_ROOT_DIR}/cfg/secrets/botToken.txt" STR "0")

function(target_secrets TARGET_NAME)
    foreach(VAR_NAME IN LISTS SECRETS_LIST)
        if (${${VAR_NAME}_TYPE} STREQUAL STR)
            target_compile_definitions(${TARGET_NAME} PRIVATE ${VAR_NAME}="${${VAR_NAME}}")
        else()
            target_compile_definitions(${TARGET_NAME} PRIVATE ${VAR_NAME}=${${VAR_NAME}})
        endif()
    endforeach()
endfunction()
