diff options
Diffstat (limited to 'platform/windows/detect.py')
-rw-r--r-- | platform/windows/detect.py | 158 |
1 files changed, 125 insertions, 33 deletions
diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 1ad0f164d2..97d2461e58 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -1,4 +1,4 @@ -# +# # tested on | Windows native | Linux cross-compilation # ------------------------+-------------------+--------------------------- # MSVS C++ 2010 Express | WORKS | n/a @@ -24,11 +24,11 @@ # ( example : "C:/Mingw-w32", "C:/Mingw-w64" ) # # - if you want to compile faster using the "-j" option, don't forget -# to install the appropriate version of the Pywin32 python extension +# to install the appropriate version of the Pywin32 python extension # available from : http://sourceforge.net/projects/pywin32/files/ # -# - before running scons, you must add into the environment path -# the path to the "/bin" directory of the Mingw version you want +# - before running scons, you must add into the environment path +# the path to the "/bin" directory of the Mingw version you want # to use : # # set PATH=C:/Mingw-w32/bin;%PATH% @@ -37,9 +37,9 @@ # - Mingw-w32 only compiles 32bits. # - Mingw-w64 only compiles 64bits. # -# - it is possible to add them both at the same time into the PATH env, -# if you also define the MINGW32_PREFIX and MINGW64_PREFIX environment -# variables. +# - it is possible to add them both at the same time into the PATH env, +# if you also define the MINGW32_PREFIX and MINGW64_PREFIX environment +# variables. # For instance, you could store that set of commands into a .bat script # that you would run just before scons : # @@ -61,14 +61,14 @@ # # - it is possible to manually override prefixes by defining # the MINGW32_PREFIX and MINGW64_PREFIX environment variables. -# +# ##### # Notes about Mingw under Windows : # -# - this is the MinGW version from http://mingw.org/ +# - this is the MinGW version from http://mingw.org/ # - install it into a path that does not contain spaces # ( example : "C:/MinGW" ) -# - several DirectX headers might be missing. You can copy them into +# - several DirectX headers might be missing. You can copy them into # the C:/MinGW/include" directory from this page : # https://code.google.com/p/mingw-lib/source/browse/trunk/working/avcodec_to_widget_5/directx_include/ # - before running scons, add the path to the "/bin" directory : @@ -84,7 +84,7 @@ # - confirm it works well with other Visual Studio versions. # - update the wiki about the pywin32 extension required for the "-j" option under Windows. # - update the wiki to document MINGW32_PREFIX and MINGW64_PREFIX -# +# import os @@ -93,16 +93,16 @@ import sys def is_active(): return True - + def get_name(): return "Windows" def can_build(): - + if (os.name=="nt"): #building natively on windows! if (os.getenv("VSINSTALLDIR")): - return True + return True else: print("\nMSVC not detected, attempting Mingw.") mingw32 = "" @@ -111,7 +111,7 @@ def can_build(): mingw32 = os.getenv("MINGW32_PREFIX") if ( os.getenv("MINGW64_PREFIX") ) : mingw64 = os.getenv("MINGW64_PREFIX") - + test = "gcc --version > NUL 2>&1" if os.system(test)!= 0 and os.system(mingw32+test)!=0 and os.system(mingw64+test)!=0 : print("- could not detect gcc.") @@ -119,27 +119,27 @@ def can_build(): return False else: print("- gcc detected.") - + return True - + if (os.name=="posix"): mingw = "i586-mingw32msvc-" mingw64 = "x86_64-w64-mingw32-" mingw32 = "i686-w64-mingw32-" - + if (os.getenv("MINGW32_PREFIX")): mingw32=os.getenv("MINGW32_PREFIX") mingw = mingw32 if (os.getenv("MINGW64_PREFIX")): mingw64=os.getenv("MINGW64_PREFIX") - + test = "gcc --version &>/dev/null" if (os.system(mingw+test) == 0 or os.system(mingw64+test) == 0 or os.system(mingw32+test) == 0): return True - + return False - + def get_opts(): mingw="" @@ -149,10 +149,10 @@ def get_opts(): mingw = "i586-mingw32msvc-" mingw32 = "i686-w64-mingw32-" mingw64 = "x86_64-w64-mingw32-" - + if os.system(mingw32+"gcc --version &>/dev/null") != 0 : mingw32 = mingw - + if (os.getenv("MINGW32_PREFIX")): mingw32=os.getenv("MINGW32_PREFIX") mingw = mingw32 @@ -164,14 +164,14 @@ def get_opts(): ('mingw_prefix','Mingw Prefix',mingw32), ('mingw_prefix_64','Mingw Prefix 64 bits',mingw64), ] - + def get_flags(): return [ ('freetype','builtin'), #use builtin freetype ('openssl','builtin'), #use builtin openssl ] - + def build_res_file( target, source, env ): cmdbase = "" @@ -204,8 +204,8 @@ def configure(env): if (env["freetype"]!="no"): env.Append(CCFLAGS=['/DFREETYPE_ENABLED']) - env.Append(CPPPATH=['#tools/freetype']) - env.Append(CPPPATH=['#tools/freetype/freetype/include']) + env.Append(CPPPATH=['#drivers/freetype']) + env.Append(CPPPATH=['#drivers/freetype/freetype/include']) if (env["target"]=="release"): @@ -245,7 +245,7 @@ def configure(env): env.Append(CCFLAGS=['/DGLEW_ENABLED']) LIBS=['winmm','opengl32','dsound','kernel32','ole32','oleaut32','user32','gdi32', 'IPHLPAPI','Shlwapi', 'wsock32', 'shell32','advapi32','dinput8','dxguid'] env.Append(LINKFLAGS=[p+env["LIBSUFFIX"] for p in LIBS]) - + env.Append(LIBPATH=[os.getenv("WindowsSdkDir")+"/Lib"]) if (os.getenv("DXSDK_DIR")): DIRECTX_PATH=os.getenv("DXSDK_DIR") @@ -262,7 +262,35 @@ def configure(env): env.Append(CCFLAGS=["/I"+DIRECTX_PATH+"/Include"]) env.Append(LIBPATH=[DIRECTX_PATH+"/Lib/x86"]) env['ENV'] = os.environ; + + # This detection function needs the tools env (that is env['ENV'], not SCons's env), and that is why it's this far bellow in the code + compiler_version_str = detect_visual_c_compiler_version(env['ENV']) + + # Note: this detection/override code from here onward should be here instead of in SConstruct because it's platform and compiler specific (MSVC/Windows) + if(env["bits"] != "default"): + print "Error: bits argument is disabled for MSVC" + print ("Bits argument is not supported for MSVC compilation. Architecture depends on the Native/Cross Compile Tools Prompt/Developer Console (or Visual Studio settings)" + +" that is being used to run SCons. As a consequence, bits argument is disabled. Run scons again without bits argument (example: scons p=windows) and SCons will attempt to detect what MSVC compiler" + +" will be executed and inform you.") + sys.exit() + + # Forcing bits argument because MSVC does not have a flag to set this through SCons... it's different compilers (cl.exe's) called from the propper command prompt + # that decide the architecture that is build for. Scons can only detect the os.getenviron (because vsvarsall.bat sets a lot of stuff for cl.exe to work with) + env["bits"]="32" env["x86_opt_vc"]=True + + print "Detected MSVC compiler: "+compiler_version_str + # If building for 64bit architecture, disable assembly optimisations for 32 bit builds (theora as of writting)... vc compiler for 64bit can not compile _asm + if(compiler_version_str == "amd64" or compiler_version_str == "x86_amd64"): + env["bits"]="64" + env["x86_opt_vc"]=False + print "Compiled program architecture will be a 64 bit executable (forcing bits=64)." + elif (compiler_version_str=="x86" or compiler_version_str == "amd64_x86"): + print "Compiled program architecture will be a 32 bit executable. (forcing bits=32)." + else: + print "Failed to detect MSVC compiler architecture version... Defaulting to 32bit executable settings (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this build is compiled for. You should check your settings/compilation setup." + if env["bits"]=="64": + env.Append(CCFLAGS=['/D_WIN64']) else: # Workaround for MinGW. See: @@ -304,7 +332,7 @@ def configure(env): # sys.exit(255) if (env["target"]=="release"): - + env.Append(CCFLAGS=['-msse2']) if (env["bits"]=="64"): @@ -319,13 +347,14 @@ def configure(env): env.Append(CCFLAGS=['-O2','-DDEBUG_ENABLED']) elif (env["target"]=="debug"): - + env.Append(CCFLAGS=['-g', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) if (env["freetype"]!="no"): env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) - env.Append(CPPPATH=['#tools/freetype']) - env.Append(CPPPATH=['#tools/freetype/freetype/include']) + env.Append(CPPPATH=['#drivers/freetype']) + env.Append(CPPPATH=['#drivers/freetype/freetype/include']) + env["CC"]=mingw_prefix+"gcc" env['AS']=mingw_prefix+"as" @@ -366,4 +395,67 @@ def configure(env): env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) - +def detect_visual_c_compiler_version(tools_env): + # tools_env is the variable scons uses to call tools that execute tasks, SCons's env['ENV'] that executes tasks... + # (see the SCons documentation for more information on what it does)... + # in order for this function to be well encapsulated i choose to force it to recieve SCons's TOOLS env (env['ENV'] + # and not scons setup environment (env)... so make sure you call the right environment on it or it will fail to detect + # the propper vc version that will be called + + # These is no flag to give to visual c compilers to set the architecture, ie scons bits argument (32,64,ARM etc) + # There are many different cl.exe files that are run, and each one compiles & links to a different architecture + # As far as I know, the only way to figure out what compiler will be run when Scons calls cl.exe via Program() + # is to check the PATH varaible and figure out which one will be called first. Code bellow does that and returns: + # the following string values: + + # "" Compiler not detected + # "amd64" Native 64 bit compiler + # "amd64_x86" 64 bit Cross Compiler for 32 bit + # "x86" Native 32 bit compiler + # "x86_amd64" 32 bit Cross Compiler for 64 bit + + # There are other architectures, but Godot does not support them currently, so this function does not detect arm/amd64_arm + # and similar architectures/compilers + + # Set chosen compiler to "not detected" + vc_chosen_compiler_index = -1 + vc_chosen_compiler_str = "" + + # find() works with -1 so big ifs bellow are needed... the simplest solution, in fact + # First test if amd64 and amd64_x86 compilers are present in the path + vc_amd64_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"]+"BIN\\amd64;") + if(vc_amd64_compiler_detection_index > -1): + vc_chosen_compiler_index = vc_amd64_compiler_detection_index + vc_chosen_compiler_str = "amd64" + + vc_amd64_x86_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"]+"BIN\\amd64_x86;") + if(vc_amd64_x86_compiler_detection_index > -1 + and (vc_chosen_compiler_index == -1 + or vc_chosen_compiler_index > vc_amd64_x86_compiler_detection_index)): + vc_chosen_compiler_index = vc_amd64_x86_compiler_detection_index + vc_chosen_compiler_str = "amd64_x86" + + + # Now check the 32 bit compilers + vc_x86_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"]+"BIN;") + if(vc_x86_compiler_detection_index > -1 + and (vc_chosen_compiler_index == -1 + or vc_chosen_compiler_index > vc_x86_compiler_detection_index)): + vc_chosen_compiler_index = vc_x86_compiler_detection_index + vc_chosen_compiler_str = "x86" + + vc_x86_amd64_compiler_detection_index = tools_env["PATH"].find(tools_env['VCINSTALLDIR']+"BIN\\x86_amd64;") + if(vc_x86_amd64_compiler_detection_index > -1 + and (vc_chosen_compiler_index == -1 + or vc_chosen_compiler_index > vc_x86_amd64_compiler_detection_index)): + vc_chosen_compiler_index = vc_x86_amd64_compiler_detection_index + vc_chosen_compiler_str = "x86_amd64" + + # debug help + #print vc_amd64_compiler_detection_index + #print vc_amd64_x86_compiler_detection_index + #print vc_x86_compiler_detection_index + #print vc_x86_amd64_compiler_detection_index + #print "chosen "+str(vc_chosen_compiler_index)+ " | "+str(vc_chosen_compiler_str) + + return vc_chosen_compiler_str |