diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-06-17 09:47:35 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-06-29 12:09:09 +0530 |
commit | 30066723d029688cbb9d67afb370a610b8d8457d (patch) | |
tree | abf5199ba94d7ad06afd7770cf41331352f5c672 /config/windows.config | |
parent | 62618b10dc79c85bc158101c9a462045b3cf23e2 (diff) |
cerbero: Build Meson projects with MSVC on Windows
Unless the 'visualstudio' variant is disabled in the config by enabling
the `novisualstudio` variant, recipes that use Meson will be built
using Visual Studio.
Cerbero will attempt to find either Visual Studio 2015 or Visual Studio
2017 and set the correct environment to use the MSVC toolchain. This
is done once at startup, and then used by each recipe at build time.
To get this environment in shell form, use the `win32-msvc-shell.cbc`
and `win64-msvc-shell.cbc` config files.
https://bugzilla.gnome.org/show_bug.cgi?id=796641
Diffstat (limited to 'config/windows.config')
-rw-r--r-- | config/windows.config | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/config/windows.config b/config/windows.config index f129637c..0fb2c470 100644 --- a/config/windows.config +++ b/config/windows.config @@ -38,34 +38,38 @@ if not mingw_perl_prefix: def cmd(command): return '%s-%s' % (host, command) -# Default compiler flags -os.environ['CFLAGS'] = '-Wall -g -O2 ' -os.environ['CXXFLAGS'] = '-Wall -g -O2 ' -os.environ['OBJCFLAGS'] = '-Wall -g -O2 ' +export_msvc = ('CERBERO_MSVC_SHELL' in os.environ) and (platform == Platform.WINDOWS) + +# Default GCC compiler flags +if not export_msvc: + os.environ['CFLAGS'] = '-Wall -g -O2 ' + os.environ['CXXFLAGS'] = '-Wall -g -O2 ' + os.environ['OBJCFLAGS'] = '-Wall -g -O2 ' ccache = use_ccache and 'ccache ' or '' # Toolchain environment os.environ['CFLAGS'] += "-DWINVER=0x0600 -D_WIN32_WINNT=0x0600" -os.environ['LIBRARY_PATH'] = "{0}/lib{1}".format(prefix, lib_suffix) os.environ['CXXFLAGS']=os.environ['CFLAGS'] -os.environ['CC']= '%s%s' % (ccache, cmd('gcc')) -os.environ['CXX']= '%s%s' % (ccache, cmd('g++')) -os.environ['LD']= cmd('ld') -os.environ['CPP']= cmd('cpp') -os.environ['RANLIB']= cmd('ranlib') -os.environ['AR']= cmd('ar') -os.environ['AS']= cmd('as') +os.environ['PERL'] = 'perl' os.environ['NM']= cmd('nm') -os.environ['STRIP']= cmd('strip') -os.environ['WINDRES']= cmd('windres') -os.environ['RC']= cmd('windres') os.environ['DLLTOOL']= cmd('dlltool') -os.environ['PERL'] = 'perl' -# PATH -toolchainbin = os.path.join(toolchain_prefix, 'bin') -if os.path.isdir(toolchainbin) and not toolchainbin in os.environ['PATH']: - os.environ['PATH'] = '%s%s%s' % (toolchainbin, separator, os.environ['PATH']) +if not export_msvc: + os.environ['LIBRARY_PATH'] = "{0}/lib{1}".format(prefix, lib_suffix) + os.environ['CC']= '%s%s' % (ccache, cmd('gcc')) + os.environ['CXX']= '%s%s' % (ccache, cmd('g++')) + os.environ['LD']= cmd('ld') + os.environ['CPP']= cmd('cpp') + os.environ['RANLIB']= cmd('ranlib') + os.environ['AR']= cmd('ar') + os.environ['AS']= cmd('as') + os.environ['STRIP']= cmd('strip') + os.environ['WINDRES']= cmd('windres') + os.environ['RC']= cmd('windres') + # PATH + toolchainbin = os.path.join(toolchain_prefix, 'bin') + if os.path.isdir(toolchainbin) and not toolchainbin in os.environ['PATH']: + os.environ['PATH'] = '%s%s%s' % (toolchainbin, separator, os.environ['PATH']) os.environ['ne_cv_libsfor_socket'] = '-lws2_32' os.environ['ne_cv_libsfor_gethostbyname'] = '-lws2_32' @@ -84,3 +88,20 @@ os.environ['DIRECTX_LDFLAGS'] = '-L%s/lib' % toolchain_prefix if platform == Platform.WINDOWS: os.environ['ACLOCAL'] = 'aclocal-1.11' + # We use Visual Studio by default on Windows + if 'novisualstudio' not in variants: + variants.append('visualstudio') + from cerbero.ide.vs.env import vcvarsall, get_msvc_env, append_path + # Contains only the env vars that MSVC needs, including any existing vars + # that were appended/prepended and have new values + msvc_toolchain_env = get_msvc_env(vcvarsall, arch, target_arch) + # We want the MSVC compiler and linker to find the headers and libraries + # provided by recipes built by us, so append to INCLUDE and LIB. + # NOTE: We do not want to add the MinGW toolchain paths here + msvc_toolchain_env['INCLUDE'] = append_path(msvc_toolchain_env['INCLUDE'], + os.path.join(prefix, 'include')) + msvc_toolchain_env['LIB'] = append_path(msvc_toolchain_env['LIB'], + os.path.join(prefix, 'lib' + lib_suffix)) + if export_msvc: + for var, val in msvc_toolchain_env.items(): + os.environ[var] = val |