Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to build c++ project with scons 2.3 visual express 2012?

I try:

env = Environment(ENV = {'PATH' : os.environ['PATH'], \
            'INCLUDE' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\include\\', \
            'LIB' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\lib\\'})

but it not working. error message: "cl" is not command ...

I found description in scons wiki(http://www.scons.org/wiki/PlatformSpecificNotes#Visual_C.2B-.2B-): If using Microsoft Visual C++, you need to set 'INCLUDE', 'LIB' and 'PATH' in your environment, then import them when you create your 'Environment' object. These will be used to locate the MSVC++ tools and set 'CPPFLAGS' etc.

What am I doing wrong?

complete sconstruct(it works on ubuntu, and on windows with mingw):

import os
import sys

if ARGUMENTS.get('ndk', 0):
    current_dir = os.getcwd()#os.path.dirname(os.path.abspath(__file__))
    os.environ["NDK_PROJECT_PATH"] = current_dir + '/android-project'
    os.system("ndk-build") # use V=1 if can't compile for android
    exit(0)

if ARGUMENTS.get('ant', 0):
    current_dir = os.getcwd()#os.path.dirname(os.path.abspath(__file__))
    android_prj_path = current_dir + '/android-project'
    os.chdir(android_prj_path)
    os.system("ant debug") # use V=1 if can't compile for android
    exit(0)

VariantDir('obj', 'src', duplicate = 0)

if sys.platform == 'win32':
    if ARGUMENTS.get('msvc', 0) == "1":
        env = Environment(ENV = {'PATH' : os.environ['PATH'], \
            'INCLUDE' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\include\\', \
            'LIB' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\lib\\'})
    else:
        env = Environment(tools = ['mingw'])
        env.Append(CCFLAGS = '-U__STRICT_ANSI__') # for boost::program_options on mingw 4.7
        env.Append(LINKFLAGS = '-mwindows')
        env.Append(LIBS = ['mingw32', 'SDL2', 'SDL2main', 'm', 'user32', 'gdi32', \
                    'winmm', 'imm32', 'ole32', 'oleaut32', 'version', \
                    'uuid', 'glew32', 'opengl32'])
else:
    env = Environment()
    env.Append(CCFLAGS = '-rdynamic')
    env.Append(LIBS = ['SDL2', 'pthread', 'm', 'dl', 'GL'])

env.Append(CCFLAGS = '-fno-strict-aliasing') # for angelscript compile see doc
cur_dir = os.getcwd()
env.Append(CCFLAGS = '-I ' + cur_dir) # for boost find in include path
env.Append(CCFLAGS = '-g -std=c++0x -Wall -Wfatal-errors') #-msse2 -pg
env.Append(LINKFLAGS=[]) # -pg

src = Glob('obj/*.cpp')
src += Glob('obj/scene2d/*.cpp')
src += Glob('obj/pugixml/*.cpp')
src += Glob('obj/debug_support/*.cpp')
src += Glob('obj/angelscript/*.cpp')
src += Glob('obj/scriptarray/*.cpp')
src += Glob('obj/scriptstdstring/*.cpp')
src += Glob('obj/scriptbuilder/*.cpp')
src += Glob('obj/boost_libs_src/program_options/src/*.cpp')
src += Glob('obj/boost_libs_src/smart_ptr/src/*.cpp')
src += Glob('obj/boost_libs_src/system/src/*.cpp')
src += Glob('obj/boost_libs_src/filesystem/src/*.cpp')
src += Glob('obj/libwebp/*/*.c')
src += Glob('obj/zlib/*.c')
src += Glob('obj/libpng/*.c')

env.Program(target = 'start', source = src)
like image 417
leanid.chaika Avatar asked Apr 10 '13 19:04

leanid.chaika


1 Answers

Full script that works for me

import os
import sys

current_dir = os.getcwd()#os.path.dirname(os.path.abspath(__file__))

if ARGUMENTS.get('ndk', 0):
    os.environ["NDK_PROJECT_PATH"] = current_dir + '/android-project'
    os.system("ndk-build") # use V=1 if can't compile for android
    Exit(0)

if ARGUMENTS.get('ant', 0):
    android_prj_path = current_dir + '/android-project'
    os.chdir(android_prj_path)
    os.system("ant debug") # use V=1 if can't compile for android
    Exit(0)

VariantDir('obj', 'src', duplicate = 0)

if sys.platform == 'win32':
    if ARGUMENTS.get('msvc', 0) == "1":
        #os.system('"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\bin\\vcvars32"')
        env = Environment(ENV = {'PATH' : os.environ['PATH'], \
            'INCLUDE' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\include\\;c:\\Program Files (x86)\\Windows Kits\\8.0\\Include\um\\;c:\\Program Files (x86)\\Windows Kits\\8.0\\Include\\shared\\', \
            'LIB' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\lib\\;c:\\Program Files (x86)\\Windows Kits\\8.0\\Lib\\win8\\um\\x86\\'})
        env.Append(CCFLAGS = '-I ' + current_dir + '/dep/msvc/include') # for SDL2 on windows
        env.Append(CCFLAGS = '/Od /EHsc -DBOOST_ALL_NO_LIB')
        env.Append(LINKFLAGS = '/LIBPATH:' + current_dir + '/dep/msvc/lib/')
        env.Append(LINKFLAGS = '/SUBSYSTEM:WINDOWS')
        env.Append(LIBS = ['user32', 'gdi32', \
                    'winmm', 'imm32', 'ole32', 'oleaut32', 'version', \
                    'uuid', 'glew32s', 'opengl32'])
    else:
        env = Environment(tools = ['mingw'])
        env.Append(CCFLAGS = '-U__STRICT_ANSI__') # for boost::program_options on mingw 4.7
        env.Append(LINKFLAGS = '-mwindows')
        env.Append(LIBS = ['mingw32', 'SDL2', 'SDL2main', 'm', 'user32', 'gdi32', \
                    'winmm', 'imm32', 'ole32', 'oleaut32', 'version', \
                    'uuid', 'glew32', 'opengl32'])
else:
    env = Environment()
    env.Append(LIBS = ['SDL2', 'pthread', 'm', 'dl', 'GL'])

if ARGUMENTS.get('msvc', 0) != "1":
    env.Append(CCFLAGS = '-fno-strict-aliasing') # for angelscript compile see doc
    env.Append(CCFLAGS = '-std=c++0x -Wall -Wfatal-errors')

env.Append(CCFLAGS = '-I ' + current_dir) # for boost find in include path

if ARGUMENTS.get('release', 0) == "1":
    if sys.platform != 'win32':
        env.Append(CCFLAGS = '-DNO_OPENGL_CHECK -DSDL_ASSERT_LEVEL=1 -O2 -msse2') #-DNO_OPENGL_CHECK -DSDL_ASSERT_LEVEL=1 -O3 -msse2
    else:
        env.Append(CCFLAGS = '/MD')
        env.Append(LIBS = ['SDLmain', 'SDL', 'msvcrt'])
else:
    if sys.platform != 'win32':
        env.Append(LINKFLAGS=['-rdynamic']) # $(sdl2-config --static-libs)
        env.Append(CCFLAGS = '-g')
    else:
        env.Append(CCFLAGS = '/MDd /Gm- /Zi -D_DEBUG /Od ')
        env.Append(LINKFLAGS=['/INCREMENTAL'])
        env['PDB'] = ['start.pdb']
        env['CCPDBFLAGS'] = ['${(PDB and "/Zi /Fd%s" % File(PDB)) or ""}']
        env.Append(LIBS = ['SDLmain_d', 'SDL_d', 'MSVCRTD', 'libcmt'])

src = Glob('obj/*.cpp')
src += Glob('obj/scene2d/*.cpp')
src += Glob('obj/pugixml/*.cpp')
src += Glob('obj/debug_support/*.cpp')
src += Glob('obj/angelscript/*.cpp')
src += Glob('obj/scriptarray/*.cpp')
src += Glob('obj/scriptstdstring/*.cpp')
src += Glob('obj/scriptbuilder/*.cpp')
src += Glob('obj/scripthelper/*.cpp')
src += Glob('obj/boost_libs_src/program_options/src/*.cpp')
src += Glob('obj/boost_libs_src/smart_ptr/src/*.cpp')
src += Glob('obj/boost_libs_src/system/src/*.cpp')
src += Glob('obj/boost_libs_src/filesystem/src/*.cpp')
src += Glob('obj/libwebp/*/*.c')
src += Glob('obj/zlib/*.c')
src += Glob('obj/libpng/*.c')

prog = env.Program(target = 'start', source = src)
like image 105
leanid.chaika Avatar answered Oct 21 '22 19:10

leanid.chaika