Scons appending a random '1' to macro definition on OSX only

Viewed 160

I have a command line argument that defines the type to use for a Vector3 class. It is defined in the SConstruct file as follows:

EnumVariable('vector3_type', 'The type to use for Vector3\'s xyz coordinates', 'float', allowed_values=['float', 'double', 'long_double'], ignorecase=2)

This variable is added to the environment here:

if env['vector3_type'] != 'long_double':
    env.Append(CPPDEFINES = ["BIGROCK_VEC3_TYPE %s" % env['vector3_type']])
else:
    env.Append(CPPDEFINES = ["BIGROCK_VEC3_TYPE long double"])

This works fine on Windows 10, but when I try to compile on OSX, I get the following error:

In file included from src/octree.cpp:1:
In file included from src/octree.h:5:
src/vector3.h:15:9: error: expected member name or ';' after declaration specifiers
    BIGROCK_VEC3_TYPE x, y, z;
    ^~~~~~~~~~~~~~~~~
<command line>:1:33: note: expanded from here
#define BIGROCK_VEC3_TYPE float 1
                          ~~~~~ ^

Either scons or g++ is adding an extra '1' to the end of my macro, causing the rest of my code to break.

When I print env['vector3_type'] in scons, it doesn't have a 1 attached. I have no idea where this 1 is being added.

1 Answers

This makes me feel a bit foolish. Scons assumes that a lone string within CPPDEFINES is a flag name, and will append 1 to it for #ifdef and #ifndef directives. The proper way to pass this #define is:

if env['vector3_type'] != 'long_double':
    env.Append(CPPDEFINES = [("BIGROCK_VEC3_TYPE", env['vector3_type'])])
else:
    env.Append(CPPDEFINES = [("BIGROCK_VEC3_TYPE", "long double")])
Related