I want to use scons for the building process of a small game I wrote. https://github.com/Dobiasd/Dron

I generally works including the recursion through the source directories, but I would like to not pollute src directory with .o files. VariantDir should help me, but the following SConstruct does not work (.o files still in ./src)

import fnmatch
import os

matches = []
for root, dirnames, filenames in os.walk('src/'):
    for filename in filenames:
        if fnmatch.fnmatch(filename, '*.cpp'):
            matches.append(str(os.path.join(root, filename)))

env = Environment()
env.Append(LIBS = ['sfml-audio', 'sfml-graphics','sfml-window','sfml-system'])
env.Append(LIBPATH = '/usr/local/lib')
env.Append(CXXFLAGS = '-std=c++11 -Wall -Wextra -pedantic -Werror')
env.VariantDir('build', 'src')
env.Program(target = 'Dron', source = matches)

compilation (my expectation):

g++ -o obj/main.o -c -std=c++11 -Wall -Wextra -pedantic -Werror src/main.cpp

compilation (reality):

g++ -o src/main.o -c -std=c++11 -Wall -Wextra -pedantic -Werror src/main.cpp

It would be great if someone could tell me what I am doing wrong. :)

有帮助吗?

解决方案

When using the SCons VariantDir() function, you have to refer to your source files as if they were in the variant_dir, not the source_dir.

Here is an answer to a different question, that should serve as a good example and should help.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top