简体   繁体   中英

SCONS env.Library() does not get the expected environment compilation flags

I'm running the following problem: we have a large project (inherited from other company) compiling many sub-mules of SW.The contruction of the FW is sub-divided in several SConscripts that we invoke from the main SConstruct. The point is that all the submodules share the same compilation flags and defines.

I intended to solve this with the following solution:

In the main entry point , the SConstruct we define certain compilation options :

COMPILER_FLAGS = '-g \\ -O3 \\ -fshort-double \\ -gdwarf-2 \\ -Wall \\ -W \\ -Werror-implicit-function-declaration \\ -Wno-unused-variable \\ -Wno-empty-body \\ -Wbad-function-cast \\ -Wstrict-prototypes \\ -Wmissing-noreturn \\ -Wnested-externs \\ -fno-builtin \\ -Wno-unused-parameter \\ -Wno-pointer-to-int-cast \\ ..........

This COMPILER_FLAGS are present the Construction environment which is passed to each Sconscript as argument Then inside each Sconscript I make a clone of the environment and modify some of the options for each submodule

*SConstruct

log_path    = os.path.join('../../CDD/LogPrint/Build/logprint.SC')
objects += SConscript(log_path, exports='env', variant_dir=log_build_dir, duplicate=1)
dbg_exe     = env.Program(dbg_path, objects)

*logprint.SC

\#Customize Compilation options for this component
own_env = env.Clone()
own_env['COMPILER_FLAGS'] += '-O0 '

\# COMPILE SOURCE FILES
objects += own_env.Library(sources)

\# RETURN                     
Return('objects')

The point is that when I compile (and build a Library) for the logprint submodule I don't see the own_env extended compiled Flags. I still see in the compilation command line printed the initial env options inherited from the main SConstruct file.

Any reason why this may be happening? Is there any top level SCONS option/configuration setting this behaviour? Let me also highlight that I probed this concept of env.Clone in a new small project from the scratch and there it works. So I wonder is some top SCONS configuration might be blocking the own_env.Library behaviour I want in the 'large' project.

The following should do what I believe you're trying to do.

SConstruct

env=Environment()
env['CCFLAGS'] ='-g -O3 -fshort-double -gdwarf-2 -Wall -W -Werror-implicit-function-declaration -Wno-unused-variable -Wno-empty-body -Wbad-function-cast -Wstrict-prototypes -Wmissing-noreturn  -Wnested-externs -fno-builtin -Wno-unused-parameter -Wno-pointer-to-int-cast'
log_path = os.path.join('../../CDD/LogPrint/Build/logprint.SC')
objects = SConscript(log_path, exports='env', variant_dir=log_build_dir, duplicate=1)
dbg_exe = env.Program(dbg_path, objects)

SConscript

#Customize Compilation options for this component
own_env = env.Clone()
own_env.Append('CCFLAGS' = '-O0 ')

# COMPILE SOURCE FILES
objects = own_env.Library(sources)

# RETURN                     
Return('objects')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM