Context-aware pervasive systems are emerging as an important class of applications. We present a declarative approach to building context-aware pervasive systems, and introduce the notion of the situation program which highlights the primacy of the situation abstraction for building context-aware pervasive systems. We show how to manipulate situation programs using meta-programming within an extension of the Prolog logic programming language which we call LogicCAP. Such meta-reasoning enables complex situations to be described in terms of other situations. We also discuss 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.