Question

Short Version of my Question

I want to compile a .hpp file using Scons and for that I use the following target:

env.Object('file.o', 'file.hpp')

Running Scons with this target gives me the following error:

Don't know how to build from a source file with suffix `.hpp'.  Expected a suffix in this list: [...]

Can I somehow tell Scons that it should treat the .hpp file as it would treat a .cpp file?

Why do I want this

I use emacs together with flymake (http://flymake.sourceforge.net/), which basically calls a specific make target in the background, parses the output and highlights errors and warnings in the editor. However, I want to use Scons as build system and not make. To use flymake I have a Makefile containing a single target that just calls Scons:

SCONS_TARGETS = $(CHK_SOURCES:=.syntax_target)

check-syntax:
    LANG=en scons mode=syntax $(SCONS_TARGETS)

And in the SContruct file I have something like the following really doing the syntax check:

### checking syntax (for flymake)
if (mode == 'syntax'):
    env.Append(CCFLAGS = ['-fsyntax-only'])
    for target in COMMAND_LINE_TARGETS:
        env.Object(target,
                   target.replace('.syntax_target', ''))

This works fine for my source (.cpp) files, however it does not for the header (.hpp) files, for which I get the error mentioned above.

I already came up with the obvious "solution" to just copy the header file that needs to be checked to a file with suffix .cpp and do the syntax check on this file. This approach has the problem that the compiler outputs the errors for the new file and thus flymake of course does not highlight the errors in the file where they actually occur.

Was it helpful?

Solution

Update your flymake section as follows:

### checking syntax (for flymake)
if (mode == 'syntax'):
    import SCons.Tool
    static_obj, shared_obj = SCons.Tool.createObjBuilders(env)

    static_obj.add_action('.hpp', SCons.Defaults.CXXAction)
    shared_obj.add_action('.hpp', SCons.Defaults.ShCXXAction)
    static_obj.add_emitter('.hpp', SCons.Defaults.StaticObjectEmitter)
    shared_obj.add_emitter('.hpp', SCons.Defaults.SharedObjectEmitter)

    env.Append(CCFLAGS = ['-fsyntax-only'])
    for target in COMMAND_LINE_TARGETS:
        env.Object(target,
                   target.replace('.syntax_target', ''))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top