Context-aware pervasive systems are emerging as an important class of applications. Such systems can respond intelligently to contextual information about the physical world acquired via sensors and information about the computational environment. A declarative approach to building context-aware pervasive systems is presented, and the notion of the situation program is introduced, which highlights the primacy of the situation abstraction for building context-aware pervasive systems. There is also a demonstration of how to manipulate situation programs using meta-programming within an extension of the Prolog logic programming language which is called LogicCAP. Such meta-reasoning enables complex situations to be described in terms of other situations. Furthermore, a discussion is given on how the design of situation programs can affect the properties of a context-aware system. The approach encourages a high-level of abstraction for representing and reasoning with situations, and supports building context-aware systems incrementally by providing modularity and separation of concerns.