def test_msbuild_standard(): test_folder = temp_folder() settings = Settings({ "build_type": ["Release"], "compiler": { "msvc": { "version": ["193"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(test_folder) conanfile.folders.set_base_install(test_folder) conanfile.conf = Conf() conanfile.conf["tools.microsoft.msbuild:installation_path"] = "." conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "msvc" conanfile.settings.compiler.version = "193" conanfile.settings.compiler.cppstd = "20" conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) props_file = os.path.join(test_folder, 'conantoolchain_release_x64.props') msbuild.generate() assert '<LanguageStandard>stdcpp20</LanguageStandard>' in load(props_file)
def test_msbuild_standard(): settings = Settings({ "build_type": ["Release"], "compiler": { "msvc": { "version": ["19.3"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(".") conanfile.install_folder = os.getcwd() conanfile.conf = ConfDefinition() conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "msvc" conanfile.settings.compiler.version = "19.3" conanfile.settings.compiler.cppstd = "20" conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) with mock.patch("conan.tools.microsoft.visual.vcvars_path", mock.MagicMock(return_value=".")): msbuild.generate() assert '<LanguageStandard>stdcpp20</LanguageStandard>' in load( 'conantoolchain_release_x64.props')
def test_msbuildtoolchain_changing_flags_via_attributes(): test_folder = temp_folder() settings = Settings({ "build_type": ["Release"], "compiler": { "msvc": { "version": ["193"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(test_folder) conanfile.folders.set_base_install(test_folder) conanfile.conf = Conf() conanfile.conf["tools.microsoft.msbuild:installation_path"] = "." conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.settings_build = settings conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "msvc" conanfile.settings.compiler.version = "193" conanfile.settings.compiler.cppstd = "20" conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) msbuild.cxxflags.append("/flag1") msbuild.cflags.append("/flag2") msbuild.ldflags.append("/link1") msbuild.generate() toolchain = load( os.path.join(test_folder, "conantoolchain_release_x64.props")) expected_cl_compile = """ <ClCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalOptions>/flag1 /flag2 %(AdditionalOptions)</AdditionalOptions>""" expected_link = """ <Link> <AdditionalOptions>/link1 %(AdditionalOptions)</AdditionalOptions> </Link>""" expected_resource_compile = """ <ResourceCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalOptions>/flag1 /flag2 %(AdditionalOptions)</AdditionalOptions> </ResourceCompile>""" assert expected_cl_compile in toolchain assert expected_link in toolchain assert expected_resource_compile in toolchain
def test_resource_compile(): test_folder = temp_folder() settings = Settings({ "build_type": ["Release"], "compiler": { "msvc": { "version": ["193"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(test_folder) conanfile.folders.set_base_install(test_folder) conanfile.conf = Conf() conanfile.conf["tools.microsoft.msbuild:installation_path"] = "." conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.settings_build = settings conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "msvc" conanfile.settings.compiler.version = "193" conanfile.settings.compiler.cppstd = "20" conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) msbuild.preprocessor_definitions["MYTEST"] = "MYVALUE" props_file = os.path.join(test_folder, 'conantoolchain_release_x64.props') msbuild.generate() expected = """ <ResourceCompile> <PreprocessorDefinitions> MYTEST=MYVALUE;%(PreprocessorDefinitions) </PreprocessorDefinitions> <AdditionalOptions> %(AdditionalOptions)</AdditionalOptions> </ResourceCompile>""" props_file = load(props_file) # Remove all blanks and CR to compare props_file = "".join(s.strip() for s in props_file.splitlines()) assert "".join(s.strip() for s in expected.splitlines()) in props_file
def test_msbuild_and_intel_cc_props(mode, expected_toolset): test_folder = temp_folder() settings = Settings({ "build_type": ["Release"], "compiler": { "intel-cc": { "version": ["2021.3"], "mode": [mode] }, "msvc": { "version": ["193"], "cppstd": ["20"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.folders.set_base_generators(test_folder) conanfile.folders.set_base_install(test_folder) conanfile.conf = Conf() conanfile.conf["tools.intel:installation_path"] = "my/intel/oneapi/path" conanfile.conf["tools.microsoft.msbuild:installation_path"] = "." conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.compiler = "intel-cc" conanfile.settings.compiler.version = "2021.3" conanfile.settings.compiler.mode = mode conanfile.settings.os = "Windows" conanfile.settings.arch = "x86_64" msbuild = MSBuildToolchain(conanfile) props_file = os.path.join(test_folder, 'conantoolchain_release_x64.props') msbuild.generate() assert '<PlatformToolset>%s</PlatformToolset>' % expected_toolset in load( props_file)