scons_logo SConsΒΆ

SCons can be used both to generate and consume conan packages, via the scons generator generator. The package recipe build() method could be similar to:

class PkgConan(ConanFile):
    settings = 'os', 'compiler', 'build_type', 'arch'
    requires = 'Hello/1.0@user/stable'
    generators = "scons"

    ...

    def build(self):
        debug_opt = '--debug-build' if self.settings.build_type == 'Debug' else ''
        os.makedirs("build")
        # FIXME: Compiler, version, arch are hardcoded, not parametrized
        with tools.chdir("build"):
            self.run('scons -C {}/src {}'.format(self.source_folder, debug_opt))

    ...

The SConscript build script can load the generated SConscript_conan file that contains the information of the dependencies, and use it to build

conan = SConscript('{}/SConscript_conan'.format(build_path_relative_to_sconstruct))
if not conan:
    print 'File `SConscript_conan` is missing.'
    print 'It should be generated by running `conan install`.'
    sys.exit(1)

env.MergeFlags(conan['conan'])
env.Library("hello", "hello.cpp")

A complete example, with a test_package that also uses SCons is in a github repository, you can try it:

$ git clone https://github.com/memsharded/conan-scons-template
$ cd conan-scons-template
$ conan test_package
> Hello World Release!
$ conan test_package -s build_type=Debug
> Hello World Debug!