Request help with conditional compile syntax

I could use some help with the syntax of a conditional compile.

#define SENSOR_NONE    0
#define SENSOR_BMP180  1  // Set to 1 BMP180 Barometric Pressure sensor is installed -- OR
#define SENSOR_HTU21D  2  // set to 2 if HTU21D Temp & Humidity sensor is installed -- OR
#define SENSOR_DS18B20 3  // Set to 3 if DS18B20 Temp sensor is installed on the TinyRTC
#define SENSOR_TYPE SENSOR_HTU21D
                        
#if SENSOR_TYPE == SENSOR_BMP180
	#include <BMP180.h>
	BMP180 weather;
#endif
#if SENSOR_TYPE == SENSOR_HTU21D
	#include <HTU21D.h>
	HTU21D weather;
#endif
#if SENSOR_TYPE == SENSOR_DS18B20
	//TODO: Add code for this sensor
#endif

If the sensor_type is BMP180 (the first one) it compiles. If the sensor_type is HTU21D or DS18B20 I get a ton of compile errors like 'suchAndSuch' was not declared in this scope as if never finds the #endif or like a close brace is missing.
According to some google searches I've done, this should work as I have posted it here, but it doesn't. I've tried a variety of formats including using () and can't seem to find the correct one.

It is more likely that it can't find the header files.

Yeah probably. It works just fine here (making weather an int and including some random .h as I don't have the ones you're using).

Your problem should be somewhere else, not in the directives.

Your problem should be somewhere else, not in the directives.

I suspect that the variable weather is the culprit, because it is not always defined.

OP: You need to study the compiler directives. They have corresponding directives to match if/else if/else. You MUST make sure that weather is ALWAYS defined, because one and only one of the clauses is executed.

#if SENSOR_TYPE == SENSOR_BMP180

The arduino pre-processor can get confused by pre-processor conditional expressions near the start of the file.
Try adding a dummy "real C statement" before any of your conditionals:

static const dummy_c_statement = 0;

#define SENSOR_HTU21D  2  // set to 2 if HTU21D Temp & Humidity sensor is installed -- OR
#define SENSOR_DS18B20 3  // Set to 3 if DS18B20 Temp sensor is installed on the TinyRTC
#define SENSOR_TYPE SENSOR_HTU21D
                        
#if SENSOR_TYPE == SENSOR_BMP180
	#include <BMP180.h>
	BMP180 weather;
#endif