0

I have been porting a project that used Make to SCons. Generally, I am pleased by how easy it is to use SCons, relatively to make. However, there is one thing that has resisted several hours of attempts. The files in my projects are contained into a tree which starts at ProjectHome. The srouces are in several subdirectories contained in ProjectHome/src/

I have a SConstruct file in ProjectHome which defines the build enviroment and then calls a SConscript (in ProjectHome) which builds the object files, which are then put into a library in ProjectHome/lib by SConstruct. Everything works fine, except that I would like to separate where the .o files are kept from where the source files are. So here's what I have

#SConstruct.py
...
# The environment is defined above, no issues 
cppobj, chfobj=SConscript('./SConscript.py', 'env', variant_dir='build', src_dir='.', duplicate=False)
env.Install('lib/'+str(Dim)+'D', env.SharedLibrary(target='Grade'+str(n), source=cppobj+chfobj))

and this is for the SConscript.py

#SConscript.py
import platform
import os
import sys

def getSubdirs(abs_path_dir) :
    """ returns a sorted list with the subdirectoris in abs_path_dir"""  
    lst=[x[0] for x in os.walk(abs_path_dir)]
    lst.sort()
    return lst
Dirs=getSubdirs(os.getcwd()+'/src') # gives me list of the directories in src

CppNodes=[]
ChFNodes=[]

Import('env')

for directory in Dirs[2:3]:

    CppNodes+=Glob(directory+'/*.cpp')
    ChFNodes+=Glob(directory+'/*.ChF')



# env.Object can work on lists
ChFobj=env.SharedObject(ChFNodes)
# This builder likes to work one at a time 
# this build an internal representation of _F.H headers 
# so that when an #include in encountered, scons look
# at this list too, and not just what specified by the IncDirs
if len(ChFNodes)==1: # this is ridiculous but having only one ChF file causes troubles
    os.system('touch dummyF.ChF')
    ChFNodes.append('dummyF.ChF')
ChFHeader=[]
for file in ChFNodes:
    ChFHeader+=env._H(source=file) 

Cppobj=env.SharedObject(CppNodes)



Return('Cppobj ChFobj')

However, for the life of me, build is ignored completely. I have tried different combinations, even placing SConscript.py in the build dir, cally SConscript('build/SCoscript.py', 'env',...) you name it: Scons stubbornly refuses to do anything with build. Any help is appreciated. To be clear, it works in creating the libraries. It just that it places the intermediate object files in the src dirs.

user3646557
  • 299
  • 2
  • 9
  • The second answer in this post solved my problem https://stackoverflow.com/questions/11050211/use-a-glob-in-variantdir-einvironment-to-find-files-recursively-in-python – user3646557 Apr 01 '20 at 14:25
  • Essential;ly, this is not legal usage: `variant_dir='build', src_dir='.'` - the variant dir is not supposed to be a subdir of the source dir. The variant dir isn't an alternate place to put build artifacts, it's a (partially virtual) image of the source dir that you can build in instead of in the source dir. Glad you were able to resolve the problem! – Mats Wichmann Apr 03 '20 at 16:32

0 Answers0