Science fiction often deals with artificial intelligence. Usually machines are self-aware by design. Sometimes they are self-aware by accident. As an artificial intelligence becomes more complicated it passes some critical threshold and wakes up. This is what happened in the Terminator movies and in a more benign form what happened to Mike in The Moon is a Harsh Mistress.
I think that if and when we create an artificial self-aware intelligence it won't be by accident.
Life and consciousness are often described as emergent phenomena. That is they are phenomena that occur in systems. They are not properties of any individual part of a system. This is certainly the case for life and almost certainly the case for consciousness.
They depend on complexity in the systems that generate them but complexity by itself is not sufficient to generate them. It has to be complexity in the right structures. For life this is things like DNA molecules , cell membranes etc. The idea that complexity gives rise to life is a misunderstanding of emergence. Complexity is necessary but not sufficient for life.
The same is probably the case for consciousness. It probably depends on specific structures and interactions and is not an accidental consequence of complexity.
In humans and great apes we may be beginning to identify some of the crucial structures involved in consciousness. Biologists have recently found that humans and great apes have a type of nerve cell that no other animals possess. These recently discovered spindle cells are found in two parts of the brain. The concentration of them is highest in humans, then in bobonos, then chimpanzees, then gorillas, then orang otangs. They appear in humans at four months after birth. There is a great increase in their number in the second and third years.
The speculation is that they tie together different parts of the brain. It has been suggested that they are the channel between emotional and cognitive regions of the brain. They make possible connections in the brain that cannot occur in other animals.
I suspect that self-awareness is part of the same phenomenon as mind modeling. For creatures with complex social interactions it is an advantage to be able to reproduce what is going on inside another's mind as a way of understanding another's behavior. The ability to inspect ones own mental processes gives mind modelers something to compare another's behavior to and helps predict the reactions of others to one's own actions.
Self-awareness certainly made the development of symbols and syntactic language easier. It may be an essential requirement for the ability to attach meanings to symbols. Humans and great apes are the only animals that any one has been able to teach a syntactic language to.
It looks as if consciousness developed incrementally in humans and pongoids. It didn't just appear like some sort of phase change. I don't think it will just happen in machines either.