当前位置: 动力学知识库 > 问答 > 编程问答 >

scons - How to correclty use MSVSSolution and MSVSProject

问题描述:

My goal is to have one sln file for all vcxproject created by all my SConscript.

My SConstruct takes care of creating the sln file at the root of the project :

vcxprojList = []

for script in getSConscript():

#SConscript imports and appends vcxproject in vcxprojList

SConscript(str(script).strip(), exports='envService vcxprojList', variant_dir=myVariantDir, duplicate=0)

Alias('msvs', env.MSVSSolution(target = 'faa_mxA' + env['MSVSSOLUTIONSUFFIX'],

projects = vcxprojList,

variant = 'Debug'))

My SConscript creates 2 vcxproject, see :

prj1 = env.MSVSProject(target = env.libName() + env['MSVSPROJECTSUFFIX'],

srcs = sourcesLib,

incs = [''],

localincs = headerFiles,

resources = [''],

misc = [''],

buildtarget = lib,

variant = 'Debug',

auto_build_solution=0)

prj2 = Default(Alias('msvs',env.MSVSProject(target = 'FlatGuiSpeechController' + env['MSVSPROJECTSUFFIX'],

srcs = ['main.cpp'],

incs = [''],

localincs = [''],

resources = ['main.rc'],

misc = [''],

buildtarget = program,

variant = 'Debug',

auto_build_solution=0)))

print 'prj1 : ' + str(prj1)

print 'prj2 : ' + str(prj2)

Default(Alias('msvc', prj1))

vcxprojList.append(prj1[0])

vcxprojList.append(prj2)

I am almost happy, but the sln file is incorrect, he tries to use vcxproject from variant dir when it should use the ones in src dir :

Microsoft Visual Studio Solution File, Format Version 11.00

# Visual Studio 2010

Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsr_sra_src_flatGui-debug.vcxproj", "build\debug\sr\sra\src\flatGui\libsr_sra_src_flatGui-debug.vcxproj", "{D4E37B2A-A33C-E0A6-3776-346AC39668E2}"

EndProject

Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "None", "None", "{6ADF97F8-3ACF-6453-D4A6-A4B1070F3754}"

EndProject

.

.

.

1 - I am still confused why the real vcxprojects are located in src dir and there are dummy vcxprojects in variant dir. sln file tries to use the dummy vcxproject, which is incorrect. Is it because MSVSProject cannot be used with variant dir?

2 - I have another problem. Default and Alias mechanism does not work as intended with MSVSProject. I want MSVSProject to be executed with 'msvs' target. My SConscript above generates the output :

prj1 : ['libsr_sra_src_flatGui-debug.vcxproj', 'libsr_sra_src_flatGui-debug.vcxproj.filters']

prj2 : None

scons: done reading SConscript files.

scons: Building targets ...

_GenerateV10DSP.Parse()

Adding 'FlatGuiSpeechController - Debug|Win32' to 'sr\sra\src\flatGui\FlatGuiSpeechController.vcxproj'

prj2 = Default(Alias...) returns a empty target while Default(Alias('msvc', prj1)) is not executed!

What am I doing wrong here?

网友答案:

In case where someone has same questions has mine, I will post solution I found :

1 - First problem was MSVSProject generating project file in both variant dir and src dir. I did the following workaround to resolve the problem, in my SConsctruct :

vcxprojList = [] 
for script in getSConscript(): 
    if 'msvs' in COMMAND_LINE_TARGETS: 
        SConscript(str(script).strip(), exports='envService vcxprojList', duplicate=0) 
    else: 
        variantDir =  os.path.join(envService.get_envWin32()['VARIANTDIRROOT'], envService.get_envWin32()['BUILDMODE'], os.path.dirname(script)[2:]) 
        SConscript(str(script).strip(), exports='envService vcxprojList', variant_dir=variantDir, duplicate=0) 

Alias('msvs', envService.get_envWin32().MSVSSolution(target = 'faa_mxA' + envService.get_envWin32()['MSVSSOLUTIONSUFFIX'], 
                                                     projects = vcxprojList, 
                                                     variant = 'Debug')) 

If you type scons msvc, no variant dir is given to SConscript, then, msvs project file is generated only src dir.

2 - My other problem was a misusing of Default and Alias. I realized that when typing scons msvs like I want, Alias is enough. I did something like that in my SConscript :

Creates the library

tgt = env.buildLibrary(env.libName(), Glob('*.cpp'))

################################  Visual Studio ####################################
if 'msvs' in COMMAND_LINE_TARGETS:
        prj1 = env.MSVSProject(target = env.libName() + env['MSVSPROJECTSUFFIX'],
                               srcs = env.getBaseName(Glob('*.cpp')),
                               incs = [''],
                               localincs = env.getBaseName(Glob('*.h')),
                               resources = [''],
                               misc = [''],
                               buildtarget = tgt,
                               variant = 'Debug',
                               auto_build_solution=0)

        env.Alias('msvs', prj1)
        vcxprojList.append(prj1[0])

et voilà

分享给朋友:
您可能感兴趣的文章:
随机阅读: