We present an optimal procedure for the resource-constrained project scheduling problem (RCPSP) with generalized precedence relations (further denoted as RCPSP-GPR) with the objective of minimizing the project makespan. The RCPSP-GPR extends the RCPSP to arbitrary minimal and maximal time lags between the starting and completion times of activities. The procedure is a depth-first branch-and-bound algorithm in which the nodes in the search tree represent the original project network extended with extra precedence relations which resolve a resource conflict present in the parent node. Resource conflicts are resolved using the concept of minimal delaying alternatives, i.e. minimal sets of activities which, when delayed, release enough resources to resolve the conflict. Precedence and resource-based lower bounds as well as dominance rules are used to fathom large portions of the search tree. The procedure can be extended to other regular measures of performance by some minor modifications. Even non-regular measures of performance, such as the maximinization of the net present value of the project or resource levelling objectives, can be handled. The procedure has been programmed in Microsoft* Visual C++ for use on a personal computer. Extensive computational experience is obtained.