def test_toolchain_win(self, compiler, version, runtime, cppstd): client = TestClient(path_with_spaces=False) settings = { "compiler": compiler, "compiler.version": version, "compiler.cppstd": cppstd, "compiler.runtime": runtime, "build_type": "Release", "arch": "x86" } profile = textwrap.dedent(""" [settings] os=Windows [conf] tools.microsoft.msbuild:vs_version=15 """) client.save({"myprofile": profile}) # Build the profile according to the settings provided settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v) client.run("new hello/0.1 -m=v2_cmake") client.run("create . hello/0.1@ %s" % (settings, )) # Prepare the actual consumer package client.save( { "conanfile.py": self.conanfile, "MyProject.sln": sln_file, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": self.app, "myprofile": profile }, clean_first=True) # Run the configure corresponding to this test case client.run("install . %s -if=conan -pr=myprofile" % (settings, )) self.assertIn( "conanfile.py: MSBuildToolchain created conantoolchain_release_win32.props", client.out) client.run("build . -if=conan") self.assertIn("Visual Studio 2017", client.out) self.assertIn("[vcvarsall.bat] Environment initialized for: 'x86'", client.out) self._run_app(client, "x86", "Release") self.assertIn("Hello World Release", client.out) compiler_version = version if compiler == "msvc" else "19.1" check_exe_run(client.out, "main", "msvc", compiler_version, "Release", "x86", cppstd, { "DEFINITIONS_BOTH": "True", "DEFINITIONS_CONFIG": "Release" }) check_vs_runtime("Release/MyApp.exe", client, "15", static=True, build_type="Release")
def test_locally_build_msvc(build_type, shared, client): msvc_version = "15" settings = "-s build_type={} -o hello:shared={}".format(build_type, shared) client.run("install . {}".format(settings)) client.run_command('conanvcvars.bat && cmake . -G "Ninja" ' '-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake ' '-DCMAKE_BUILD_TYPE={}'.format(build_type)) client.run_command("conanvcvars.bat && ninja") libname = "mylibrary.dll" if shared else "mylibrary.lib" assert libname in client.out client.run_command("myapp.exe") # TODO: Need full msvc version check check_exe_run(client.out, ["main", "hello"], "msvc", "19", build_type, "x86_64", cppstd="14") check_vs_runtime("myapp.exe", client, msvc_version, build_type, architecture="amd64") check_vs_runtime(libname, client, msvc_version, build_type, architecture="amd64") # create should also work client.run("create . hello/1.0@ {}".format(settings)) assert 'cmake -G "Ninja"' in client.out assert "main: {}!".format(build_type) in client.out client.run("install hello/1.0@ -g=deploy -if=mydeploy {}".format(settings)) client.run_command(r"mydeploy\hello\myapp.exe") check_exe_run(client.out, ["main", "hello"], "msvc", "19", build_type, "x86_64", cppstd="14")
def test_toolchain_win_debug(self): client = TestClient(path_with_spaces=False) settings = [("compiler", "Visual Studio"), ("compiler.version", "15"), ("compiler.toolset", "v140"), ("compiler.runtime", "MDd"), ("build_type", "Debug"), ("arch", "x86_64")] # Build the profile according to the settings provided settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings if v) client.run("new hello/0.1 -s") client.run("create . hello/0.1@ %s" % (settings,)) # Prepare the actual consumer package client.save({"conanfile.py": self.conanfile, "MyProject.sln": sln_file, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": self.app}, clean_first=True) # Run the configure corresponding to this test case client.run("install . %s -if=conan" % (settings, )) self.assertIn("conanfile.py: MSBuildToolchain created conantoolchain_debug_x64.props", client.out) client.run("build . -if=conan") self.assertIn("Visual Studio 2017", client.out) self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'", client.out) self._run_app(client, "x64", "Debug") self.assertIn("Hello World Debug", client.out) check_exe_run(client.out, "main", "msvc", "19.0", "Debug", "x86_64", "14", {"DEFINITIONS_BOTH": "True", "DEFINITIONS_CONFIG": "Debug"}) check_vs_runtime("x64/Debug/MyApp.exe", client, "15", static=False, build_type="Debug")
def test_locally_build_msvc_toolset(client): msvc_version = "15" profile = textwrap.dedent(""" [settings] os=Windows compiler=msvc compiler.version=190 compiler.runtime=dynamic compiler.cppstd=14 build_type=Release arch=x86_64 [conf] tools.cmake.cmaketoolchain:generator=Ninja tools.microsoft.msbuild:vs_version = 15 """) client.save({"profile": profile}) client.run("install . -pr=profile") client.run_command('conanvcvars.bat && cmake . -G "Ninja" ' '-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake ' '-DCMAKE_BUILD_TYPE=Release') client.run_command("conanvcvars.bat && ninja") client.run_command("myapp.exe") # Checking that compiler is indeed version 19.0, not 19.1-default of VS15 check_exe_run(client.out, ["main", "hello"], "msvc", "190", "Release", "x86_64", cppstd="14") check_vs_runtime("myapp.exe", client, msvc_version, "Release", architecture="amd64") check_vs_runtime("mylibrary.lib", client, msvc_version, "Release", architecture="amd64")
def test_locally_build_msvc(build_type, shared, client): """ Ninja build must proceed using default profile and cmake build (Windows Release) """ msvc_version = "15" client.run("install . -s build_type={} -o hello:shared={}".format( build_type, shared)) client.run_command('conanvcvars.bat && cmake . -G "Ninja" ' '-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake ' '-DCMAKE_BUILD_TYPE={}'.format(build_type)) client.run_command("conanvcvars.bat && ninja") libname = "mylibrary.dll" if shared else "mylibrary.lib" assert libname in client.out client.run_command("myapp.exe") # TODO: Need full msvc version check check_exe_run(client.out, ["main", "hello"], "msvc", "19", build_type, "x86_64", cppstd="14") check_vs_runtime("myapp.exe", client, msvc_version, build_type, architecture="amd64") check_vs_runtime(libname, client, msvc_version, build_type, architecture="amd64")
def check_toolchain_win(self, compiler, version, runtime, cppstd): client = TestClient(path_with_spaces=False) settings = [("compiler", compiler), ("compiler.version", version), ("compiler.cppstd", cppstd), ("compiler.runtime", runtime), ("build_type", "Release"), ("arch", "x86")] profile = textwrap.dedent(""" [settings] os=Windows [conf] tools.microsoft.msbuild:vs_version={vs_version} """.format(vs_version=self.vs_version)) client.save({"myprofile": profile}) # Build the profile according to the settings provided settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings if v) client.run("new hello/0.1 -m=cmake_lib") client.run("create . hello/0.1@ %s" % (settings, )) # Prepare the actual consumer package client.save({"conanfile.py": self.conanfile, "MyProject.sln": sln_file, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": self.app, "myprofile": profile}, clean_first=True) # Run the configure corresponding to this test case client.run("install . %s -if=conan -pr=myprofile" % (settings, )) self.assertIn("conanfile.py: MSBuildToolchain created conantoolchain_release_win32.props", client.out) client.run("build . -if=conan") self.assertIn("Visual Studio {ide_year}".format(ide_year=self.ide_year), client.out) self.assertIn("[vcvarsall.bat] Environment initialized for: 'x86'", client.out) self._run_app(client, "x86", "Release") self.assertIn("Hello World Release", client.out) compiler_version = version if compiler == "msvc" else self.msvc_version check_exe_run(client.out, "main", "msvc", compiler_version, "Release", "x86", cppstd, {"DEFINITIONS_BOTH": 'True', "DEFINITIONS_BOTH2": "True", "DEFINITIONS_BOTH_INT": "123", "DEFINITIONS_CONFIG": 'Release', "DEFINITIONS_CONFIG2": 'Release', "DEFINITIONS_CONFIG_INT": "456"}) static_runtime = True if runtime == "static" or "MT" in runtime else False check_vs_runtime("Release/MyApp.exe", client, self.vs_version, build_type="Release", static_runtime=static_runtime)
def test_toolchain_win(self, compiler, version, runtime): client = TestClient(path_with_spaces=False) settings = { "compiler": compiler, "compiler.version": version, "compiler.cppstd": "17", "compiler.runtime": runtime, "build_type": "Release", "arch": "x86" } # Build the profile according to the settings provided settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v) client.run("new hello/0.1 -m=v2_cmake") client.run("create . hello/0.1@ %s" % (settings, )) # Prepare the actual consumer package client.save( { "conanfile.py": self.conanfile, "MyProject.sln": sln_file, "MyApp/MyApp.vcxproj": myapp_vcxproj, "MyApp/MyApp.cpp": self.app }, clean_first=True) # Run the configure corresponding to this test case client.run("install . %s -if=conan" % (settings, )) self.assertIn( "conanfile.py: MSBuildToolchain created conantoolchain_release_win32.props", client.out) client.run("build . -if=conan") self.assertIn("Visual Studio 2017", client.out) self.assertIn("[vcvarsall.bat] Environment initialized for: 'x86'", client.out) self._run_app(client, "x86", "Release") check_msc_ver("v141", client.out) self.assertIn("main _MSVC_LANG2017", client.out) check_vs_runtime("Release/MyApp.exe", client, "15", static=True, build_type="Release")
def test_locally_build_windows_debug(self): """ Ninja build must proceed using default profile and cmake build (Windows Debug) """ client = TestClient(path_with_spaces=False) client.save({ "conanfile.py": self.conanfile, "main.cpp": self.main_cpp, "CMakeLists.txt": self.cmake }) win_host = textwrap.dedent(""" [settings] os=Windows arch=x86 compiler=Visual Studio compiler.version=15 compiler.runtime=MTd build_type=Debug """) client.save({"win": win_host}) client.run("install . -pr=win") # Ninja is single-configuration # It is necessary to set architecture=x86 here, otherwise final architecture is wrong vcvars = vcvars_command("15", architecture="x86") client.run("install . -pr=win") client.run_command( '{} && cmake . -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake ' .format(vcvars)) client.run_command("{} && cmake --build .".format(vcvars)) client.run_command("App") self.assertIn("main: Debug!", client.out) self.assertIn("main _M_IX86 defined", client.out) self.assertIn("main _MSC_VER19", client.out) self.assertIn("main _MSVC_LANG2014", client.out) check_vs_runtime("App.exe", client, "15", build_type="Debug", static=True)
def test_locally_build_windows(self): """ Ninja build must proceed using default profile and cmake build (Windows Release) """ client = TestClient(path_with_spaces=False) client.save({ "conanfile.py": self.conanfile, "main.cpp": self.main_cpp, "CMakeLists.txt": self.cmake }) win_host = textwrap.dedent(""" [settings] os=Windows arch=x86_64 compiler=Visual Studio compiler.version=15 compiler.runtime=MD build_type=Release """) client.save({"win": win_host}) client.run("install . -pr=win") # Ninja is single-configuration vcvars = vcvars_command("15", architecture="amd64") client.run_command( '{} && cmake . -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake ' .format(vcvars)) client.run_command("{} && cmake --build .".format(vcvars)) client.run_command("App") self.assertIn("main: Release!", client.out) self.assertIn("main _M_X64 defined", client.out) self.assertIn("main _MSC_VER19", client.out) self.assertIn("main _MSVC_LANG2014", client.out) check_vs_runtime("App.exe", client, "15", build_type="Release", static=False)
def test_toolchain_win(self, compiler, build_type, runtime, version, cppstd, arch, toolset, shared): settings = { "compiler": compiler, "compiler.version": version, "compiler.toolset": toolset, "compiler.runtime": runtime, "compiler.cppstd": cppstd, "arch": arch, "build_type": build_type, } options = {"shared": shared} save(self.client.cache.new_config_path, "tools.cmake.cmaketoolchain:msvc_parallel_compile=1") install_out = self._run_build(settings, options) self.assertIn( "WARN: Toolchain: Ignoring fPIC option defined for Windows", install_out) # FIXME: Hardcoded VS version and partial toolset check toolchain_path = os.path.join(self.client.current_folder, "build", "conan_toolchain.cmake").replace( "\\", "/") self.assertIn( 'CMake command: cmake -G "Visual Studio 15 2017" ' '-DCMAKE_TOOLCHAIN_FILE="{}"'.format(toolchain_path), self.client.out) if toolset == "v140": self.assertIn("Microsoft Visual Studio 14.0", self.client.out) else: self.assertIn("Microsoft Visual Studio/2017", self.client.out) generator_platform = "x64" if arch == "x86_64" else "Win32" arch_flag = "x64" if arch == "x86_64" else "X86" shared_str = "ON" if shared else "OFF" vals = { "CMAKE_GENERATOR_PLATFORM": generator_platform, "CMAKE_BUILD_TYPE": "", "CMAKE_CXX_FLAGS": "/MP1 /DWIN32 /D_WINDOWS /GR /EHsc", "CMAKE_CXX_FLAGS_DEBUG": "/Zi /Ob0 /Od /RTC1", "CMAKE_CXX_FLAGS_RELEASE": "/O2 /Ob2 /DNDEBUG", "CMAKE_C_FLAGS": "/MP1 /DWIN32 /D_WINDOWS", "CMAKE_C_FLAGS_DEBUG": "/Zi /Ob0 /Od /RTC1", "CMAKE_C_FLAGS_RELEASE": "/O2 /Ob2 /DNDEBUG", "CMAKE_SHARED_LINKER_FLAGS": "/machine:%s" % arch_flag, "CMAKE_EXE_LINKER_FLAGS": "/machine:%s" % arch_flag, "CMAKE_CXX_STANDARD": cppstd, "CMAKE_CXX_EXTENSIONS": "OFF", "BUILD_SHARED_LIBS": shared_str } def _verify_out(marker=">>"): if shared: self.assertIn("app_lib.dll", self.client.out) else: self.assertNotIn("app_lib.dll", self.client.out) out = str(self.client.out).splitlines() for k, v in vals.items(): self.assertIn("%s %s: %s" % (marker, k, v), out) _verify_out() opposite_build_type = "Release" if build_type == "Debug" else "Debug" settings["build_type"] = opposite_build_type if runtime == "MTd": settings["compiler.runtime"] = "MT" if runtime == "MD": settings["compiler.runtime"] = "MDd" self._run_build(settings, options) self._run_app("Release", bin_folder=True) if compiler == "msvc": visual_version = version else: visual_version = "19.0" if toolset == "v140" else "19.1" check_exe_run( self.client.out, "main", "msvc", visual_version, "Release", arch, cppstd, { "MYVAR": "MYVAR_VALUE", "MYVAR_CONFIG": "MYVAR_RELEASE", "MYDEFINE": "MYDEF_VALUE", "MYDEFINE_CONFIG": "MYDEF_RELEASE" }) self._run_app("Debug", bin_folder=True) check_exe_run( self.client.out, "main", "msvc", visual_version, "Debug", arch, cppstd, { "MYVAR": "MYVAR_VALUE", "MYVAR_CONFIG": "MYVAR_DEBUG", "MYDEFINE": "MYDEF_VALUE", "MYDEFINE_CONFIG": "MYDEF_DEBUG" }) static_runtime = True if runtime == "static" or "MT" in runtime else False check_vs_runtime("build/Release/app.exe", self.client, "15", build_type="Release", static_runtime=static_runtime) check_vs_runtime("build/Debug/app.exe", self.client, "15", build_type="Debug", static_runtime=static_runtime) self._modify_code() time.sleep(1) self._incremental_build(build_type=build_type) _verify_out(marker="++>>") self._run_app(build_type, bin_folder=True, msg="AppImproved") self._incremental_build(build_type=opposite_build_type) self._run_app(opposite_build_type, bin_folder=True, msg="AppImproved")
def test_toolchain_win(self, compiler, build_type, runtime, version, cppstd, arch, toolset, shared): settings = { "compiler": compiler, "compiler.version": version, "compiler.toolset": toolset, "compiler.runtime": runtime, "compiler.cppstd": cppstd, "arch": arch, "build_type": build_type, } options = {"shared": shared} install_out = self._run_build(settings, options) self.assertIn( "WARN: Toolchain: Ignoring fPIC option defined for Windows", install_out) # FIXME: Hardcoded VS version and partial toolset check self.assertIn( 'CMake command: cmake -G "Visual Studio 15 2017" ' '-DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake"', self.client.out) if toolset == "v140": self.assertIn("Microsoft Visual Studio 14.0", self.client.out) else: self.assertIn("Microsoft Visual Studio/2017", self.client.out) generator_platform = "x64" if arch == "x86_64" else "Win32" arch = "x64" if arch == "x86_64" else "X86" shared_str = "ON" if shared else "OFF" vals = { "CMAKE_GENERATOR_PLATFORM": generator_platform, "CMAKE_BUILD_TYPE": "", "CMAKE_CXX_FLAGS": "/MP1 /DWIN32 /D_WINDOWS /GR /EHsc", "CMAKE_CXX_FLAGS_DEBUG": "/Zi /Ob0 /Od /RTC1", "CMAKE_CXX_FLAGS_RELEASE": "/O2 /Ob2 /DNDEBUG", "CMAKE_C_FLAGS": "/MP1 /DWIN32 /D_WINDOWS", "CMAKE_C_FLAGS_DEBUG": "/Zi /Ob0 /Od /RTC1", "CMAKE_C_FLAGS_RELEASE": "/O2 /Ob2 /DNDEBUG", "CMAKE_SHARED_LINKER_FLAGS": "/machine:%s" % arch, "CMAKE_EXE_LINKER_FLAGS": "/machine:%s" % arch, "CMAKE_CXX_STANDARD": cppstd, "CMAKE_CXX_EXTENSIONS": "OFF", "BUILD_SHARED_LIBS": shared_str } def _verify_out(marker=">>"): if shared: self.assertIn("app_lib.dll", self.client.out) else: self.assertNotIn("app_lib.dll", self.client.out) out = str(self.client.out).splitlines() for k, v in vals.items(): self.assertIn("%s %s: %s" % (marker, k, v), out) _verify_out() opposite_build_type = "Release" if build_type == "Debug" else "Debug" settings["build_type"] = opposite_build_type if runtime == "MTd": settings["compiler.runtime"] = "MT" if runtime == "MD": settings["compiler.runtime"] = "MDd" self._run_build(settings, options) self._run_app("Release", bin_folder=True) check_msc_ver(toolset or "v141", self.client.out) self.assertIn("main _MSVC_LANG20{}".format(cppstd), self.client.out) self._run_app("Debug", bin_folder=True) check_msc_ver(toolset or "v141", self.client.out) self.assertIn("main _MSVC_LANG20{}".format(cppstd), self.client.out) static = (runtime == "static" or "MT" in runtime) check_vs_runtime("build/Release/app.exe", self.client, "15", build_type="Release", static=static) check_vs_runtime("build/Debug/app.exe", self.client, "15", build_type="Debug", static=static) self._modify_code() time.sleep(1) self._incremental_build(build_type=build_type) _verify_out(marker="++>>") self._run_app(build_type, bin_folder=True, msg="AppImproved") self._incremental_build(build_type=opposite_build_type) self._run_app(opposite_build_type, bin_folder=True, msg="AppImproved")