Exemplo n.º 1
0
    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")
Exemplo n.º 2
0
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")
Exemplo n.º 3
0
    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")
Exemplo n.º 4
0
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")
Exemplo n.º 5
0
def test_locally_build_gcc(build_type, shared, client):
    """ Ninja build must proceed using default profile and cmake build (Windows Release)
    """
    # FIXME: Note the gcc version is still incorrect
    gcc = (
        "-s os=Windows -s compiler=gcc -s compiler.version=4.9 -s compiler.libcxx=libstdc++ "
        "-s arch=x86_64 -s build_type={}".format(build_type))

    client.run("install . {} -o hello:shared={}".format(gcc, shared))

    client.run_command('cmake . -G "Ninja" '
                       '-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake '
                       '-DCMAKE_BUILD_TYPE={}'.format(build_type))

    libname = "mylibrary.dll" if shared else "libmylibrary.a"
    client.run_command("ninja")
    assert libname in client.out

    client.run_command("myapp.exe")
    # TODO: Need full gcc version check
    check_exe_run(client.out, ["main", "hello"],
                  "gcc",
                  None,
                  build_type,
                  "x86_64",
                  cppstd=None)
Exemplo n.º 6
0
def test_locally_build_linux(build_type, shared, client):
    settings = "-s os=Linux -s arch=x86_64 -s build_type={} -o hello:shared={}".format(
        build_type, shared)
    client.run("install . {}".format(settings))
    client.run_command('cmake . -G "Ninja" -DCMAKE_TOOLCHAIN_FILE={}'.format(
        CMakeToolchain.filename))

    client.run_command('ninja')
    if shared:
        assert "Linking CXX shared library libmylibrary.so" in client.out
    else:
        assert "Linking CXX static library libmylibrary.a" in client.out

    client.run_command("./myapp")
    check_exe_run(client.out, ["main", "hello"],
                  "gcc",
                  None,
                  build_type,
                  "x86_64",
                  cppstd=None)

    # 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))
    ldpath = os.path.join(client.current_folder, "mydeploy", "hello", "lib")
    client.run_command(
        "LD_LIBRARY_PATH='{}' ./mydeploy/hello/bin/myapp".format(ldpath))
    check_exe_run(client.out, ["main", "hello"],
                  "gcc",
                  None,
                  build_type,
                  "x86_64",
                  cppstd=None)
Exemplo n.º 7
0
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")
Exemplo n.º 8
0
def build_windows_subsystem(profile, make_program):
    """ The AutotoolsDeps can be used also in pure Makefiles, if the makefiles follow
    the Autotools conventions
    """
    # FIXME: cygwin in CI (my local machine works) seems broken for path with spaces
    client = TestClient(path_with_spaces=False)
    client.run("new hello/0.1 --template=cmake_lib")
    # TODO: Test Windows subsystems in CMake, at least msys is broken
    os.rename(os.path.join(client.current_folder, "test_package"),
              os.path.join(client.current_folder, "test_package2"))
    client.save({"profile": profile})
    client.run("create . --profile=profile")

    main = gen_function_cpp(name="main", includes=["hello"], calls=["hello"])
    makefile = gen_makefile(apps=["app"])

    conanfile = textwrap.dedent("""
        from conans import ConanFile
        from conan.tools.gnu import AutotoolsToolchain, Autotools, AutotoolsDeps

        class TestConan(ConanFile):
            requires = "hello/0.1"
            settings = "os", "compiler", "arch", "build_type"
            exports_sources = "Makefile"
            generators = "AutotoolsDeps", "AutotoolsToolchain"

            def build(self):
                autotools = Autotools(self)
                autotools.make()
        """)
    client.save({"app.cpp": main,
                 "Makefile": makefile,
                 "conanfile.py": conanfile,
                 "profile": profile}, clean_first=True)

    client.run("install . --profile=profile")
    cmd = environment_wrap_command(["conanbuildenv",
                                    "conanautotoolstoolchain",
                                    "conanautotoolsdeps"], client.current_folder, make_program)
    client.run_command(cmd)
    client.run_command("app")
    # TODO: fill compiler version when ready
    check_exe_run(client.out, "main", "gcc", None, "Release", "x86_64", None)
    assert "hello/0.1: Hello World Release!" in client.out

    client.save({"app.cpp": gen_function_cpp(name="main", msg="main2",
                                             includes=["hello"], calls=["hello"])})
    # Make sure it is newer
    t = time.time() + 1
    touch(os.path.join(client.current_folder, "app.cpp"), (t, t))

    client.run("build .")
    client.run_command("app")
    # TODO: fill compiler version when ready
    check_exe_run(client.out, "main2", "gcc", None, "Release", "x86_64", None, cxx11_abi=0)
    assert "hello/0.1: Hello World Release!" in client.out
    return client.out
Exemplo n.º 9
0
    def test_toolchain_mingw_win(self, build_type, libcxx, version, cppstd, arch, shared):
        # FIXME: The version and cppstd are wrong, toolchain doesn't enforce it
        settings = {"compiler": "gcc",
                    "compiler.version": version,
                    "compiler.libcxx": libcxx,
                    "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)
        self.assertIn("The C compiler identification is GNU", self.client.out)
        toolchain_path = os.path.join(self.client.current_folder, "build",
                                      "conan_toolchain.cmake").replace("\\", "/")
        self.assertIn('CMake command: cmake -G "MinGW Makefiles" '
                      '-DCMAKE_TOOLCHAIN_FILE="{}"'.format(toolchain_path), self.client.out)
        assert '-DCMAKE_SH="CMAKE_SH-NOTFOUND"' in self.client.out

        def _verify_out(marker=">>"):
            cmake_vars = {"CMAKE_GENERATOR_PLATFORM": "",
                          "CMAKE_BUILD_TYPE": build_type,
                          "CMAKE_CXX_FLAGS": "-m64",
                          "CMAKE_CXX_FLAGS_DEBUG": "-g",
                          "CMAKE_CXX_FLAGS_RELEASE": "-O3 -DNDEBUG",
                          "CMAKE_C_FLAGS": "-m64",
                          "CMAKE_C_FLAGS_DEBUG": "-g",
                          "CMAKE_C_FLAGS_RELEASE": "-O3 -DNDEBUG",
                          "CMAKE_SHARED_LINKER_FLAGS": "-m64",
                          "CMAKE_EXE_LINKER_FLAGS": "-m64",
                          "CMAKE_CXX_STANDARD": cppstd,
                          "CMAKE_CXX_EXTENSIONS": "OFF",
                          "BUILD_SHARED_LIBS": "ON" if shared else "OFF"}
            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 cmake_vars.items():
                self.assertIn("%s %s: %s" % (marker, k, v), out)

        _verify_out()
        self._run_app(build_type)
        check_exe_run(self.client.out, "main", "gcc", None, build_type, arch, None,
                      {"MYVAR": "MYVAR_VALUE",
                       "MYVAR_CONFIG": "MYVAR_{}".format(build_type.upper()),
                       "MYDEFINE": "MYDEF_VALUE",
                       "MYDEFINE_CONFIG": "MYDEF_{}".format(build_type.upper())
                       })

        self._modify_code()
        time.sleep(2)
        self._incremental_build()
        _verify_out(marker="++>>")
        self._run_app(build_type, msg="AppImproved")
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
def test_autotools_bash_complete():
    client = TestClient(path_with_spaces=False)
    bash_path = tools_locations["msys2"]["system"]["path"][
        "Windows"] + "/bash.exe"
    save(
        client.cache.new_config_path,
        textwrap.dedent("""
            tools.microsoft.bash:subsystem=msys2
            tools.microsoft.bash:path={}
            """.format(bash_path)))

    main = gen_function_cpp(name="main")
    # The autotools support for "cl" compiler (VS) is very limited, linking with deps doesn't
    # work but building a simple app do
    makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp")
    configure_ac = gen_configure_ac()

    conanfile = textwrap.dedent("""
        from conans import ConanFile
        from conan.tools.gnu import Autotools
        from conan.tools.env import Environment

        class TestConan(ConanFile):
            settings = "os", "compiler", "arch", "build_type"
            exports_sources = "configure.ac", "Makefile.am", "main.cpp"
            generators = "AutotoolsToolchain"
            win_bash = True

            def build(self):
                # These commands will run in bash activating first the vcvars and
                # then inside the bash activating the
                self.run("aclocal")
                self.run("autoconf")
                self.run("automake --add-missing --foreign")
                autotools = Autotools(self)
                autotools.configure()
                autotools.make()
        """)

    client.save({
        "conanfile.py": conanfile,
        "configure.ac": configure_ac,
        "Makefile.am": makefile_am,
        "main.cpp": main
    })
    client.run("install . -s:b os=Windows -s:h os=Windows")
    client.run("build .")
    client.run_command("main.exe")
    check_exe_run(client.out, "main", "msvc", None, "Release", "x86_64", None)

    bat_contents = client.load("conanbuild.bat")
    assert "conanvcvars.bat" in bat_contents
Exemplo n.º 12
0
    def test_mingw64(self):
        """
        64-bit GCC, binaries for generic Windows (no dependency on MSYS runtime)
        """
        client = TestClient()
        # pacman -S mingw-w64-x86_64-gcc
        self._build(client, generator="MinGW Makefiles")

        check_exe_run(client.out, "main", "gcc", None, "Debug", "x86_64", None)

        assert "__MINGW64__" in client.out
        assert "__CYGWIN__" not in client.out
        assert "__MSYS__" not in client.out
Exemplo n.º 13
0
    def test_mingw32(self):
        """
        32-bit GCC, binaries for generic Windows (no dependency on MSYS runtime)
        """
        client = TestClient()
        # pacman -S mingw-w64-i686-gcc
        self._build(client)

        check_exe_run(client.out, "main", "gcc", None, "Debug", "x86", None)

        assert "__MINGW32__" in client.out
        assert "__CYGWIN__" not in client.out
        assert "__MSYS__" not in client.out
Exemplo n.º 14
0
    def test_msys(self):
        """
        native MSYS environment, binaries depend on MSYS runtime (msys-2.0.dll)
        posix-compatible, intended to be run only in MSYS environment (not in pure Windows)
        """
        client = TestClient()
        # pacman -S gcc
        self._build(client)

        check_exe_run(client.out, "main", "gcc", None, "Debug", "x86_64", None)

        assert "__MINGW32__" not in client.out
        assert "__MINGW64__" not in client.out
        assert "__MSYS__" in client.out
Exemplo n.º 15
0
    def test_cygwin(self):
        """
        Cygwin environment, binaries depend on Cygwin runtime (cygwin1.dll)
        posix-compatible, intended to be run only in Cygwin environment (not in pure Windows)
        """
        client = TestClient()
        # install "gcc-c++" and "make" packages
        self._build(client)
        check_exe_run(client.out, "main", "gcc", None, "Debug", "x86_64", None)

        assert "__CYGWIN__" in client.out
        assert "__MINGW32__" not in client.out
        assert "__MINGW64__" not in client.out
        assert "__MSYS__" not in client.out
Exemplo n.º 16
0
def test_autotools():
    client = TestClient(path_with_spaces=False)
    client.run("new hello/0.1 --template=cmake_lib")
    client.run("create .")

    main = gen_function_cpp(name="main", includes=["hello"], calls=["hello"])
    makefile_am = gen_makefile_am(main="main", main_srcs="main.cpp")
    configure_ac = gen_configure_ac()

    conanfile = textwrap.dedent("""
        from conans import ConanFile
        from conan.tools.gnu import Autotools

        class TestConan(ConanFile):
            requires = "hello/0.1"
            settings = "os", "compiler", "arch", "build_type"
            exports_sources = "configure.ac", "Makefile.am", "main.cpp"
            generators = "AutotoolsDeps", "AutotoolsToolchain"

            def build(self):
                self.run("aclocal")
                self.run("autoconf")
                self.run("automake --add-missing --foreign")
                autotools = Autotools(self)
                autotools.configure()
                autotools.make()
        """)

    client.save(
        {
            "conanfile.py": conanfile,
            "configure.ac": configure_ac,
            "Makefile.am": makefile_am,
            "main.cpp": main
        },
        clean_first=True)
    client.run("install .")
    client.run("build .")
    client.run_command("./main")
    cxx11_abi = 0 if platform.system() == "Linux" else None
    check_exe_run(client.out,
                  "main",
                  "gcc",
                  None,
                  "Release",
                  "x86_64",
                  None,
                  cxx11_abi=cxx11_abi)
    assert "hello/0.1: Hello World Release!" in client.out
Exemplo n.º 17
0
def test_locally_build_macos(build_type, shared, client):
    client.run('install . -s os=Macos -s arch=x86_64 -s build_type={} -o hello:shared={}'
               .format(build_type, shared))
    client.run_command('cmake . -G"Ninja" -DCMAKE_TOOLCHAIN_FILE={}'
                       .format(CMakeToolchain.filename))

    client.run_command('ninja')
    if shared:
        assert "Linking CXX shared library libmylibrary.dylib" in client.out
    else:
        assert "Linking CXX static library libmylibrary.a" in client.out

    command_str = 'DYLD_LIBRARY_PATH="%s" ./myapp' % client.current_folder
    client.run_command(command_str)
    check_exe_run(client.out, ["main", "hello"], "apple-clang", None, build_type, "x86_64",
                  cppstd=None)
Exemplo n.º 18
0
def test_msvc_vs_versiontoolset(version, vs_version):
    settings = {
        "compiler": "msvc",
        "compiler.version": version,
        "compiler.runtime": "static",
        "compiler.cppstd": "14",
        "arch": "x86_64",
        "build_type": "Release",
    }
    client = TestClient()
    save(client.cache.new_config_path,
         "tools.microsoft.msbuild:vs_version={}".format(vs_version))
    conanfile = textwrap.dedent("""
            from conans import ConanFile
            from conan.tools.cmake import CMake
            class App(ConanFile):
                settings = "os", "arch", "compiler", "build_type"
                generators = "CMakeToolchain"
                options = {"shared": [True, False], "fPIC": [True, False]}
                default_options = {"shared": False, "fPIC": True}
                exports_sources = "*"

                def build(self):
                    cmake = CMake(self)
                    cmake.configure()
                    cmake.build()
                    self.run("Release\\myapp.exe")
            """)
    cmakelists = gen_cmakelists(appname="myapp", appsources=["app.cpp"])
    main = gen_function_cpp(name="main")
    client.save({
        "conanfile.py": conanfile,
        "CMakeLists.txt": cmakelists,
        "app.cpp": main,
    })
    settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items()
                        if v)
    client.run("create . app/1.0@ {}".format(settings))
    assert '-G "Visual Studio 15 2017"' in client.out

    check_exe_run(client.out, "main", "msvc", version, "Release", "x86_64",
                  "14")
Exemplo n.º 19
0
def test_locally_build_linux(build_type, shared, client):
    """ Ninja build must proceed using default profile and cmake build (Linux)
    """
    client.run(
        'install . -s os=Linux -s arch=x86_64 -s build_type={} -o hello:shared={}'
        .format(build_type, shared))
    client.run_command('cmake . -G"Ninja" -DCMAKE_TOOLCHAIN_FILE={}'.format(
        CMakeToolchain.filename))

    client.run_command('ninja')
    if shared:
        assert "Linking CXX shared library libmylibrary.so" in client.out
    else:
        assert "Linking CXX static library libmylibrary.a" in client.out

    client.run_command("./myapp")
    check_exe_run(client.out, ["main", "hello"],
                  "gcc",
                  None,
                  build_type,
                  "x86_64",
                  cppstd=None)
Exemplo n.º 20
0
    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")
Exemplo n.º 21
0
    def test_toolchain_win_multi(self):
        client = TestClient(path_with_spaces=False)
        settings = {
            "compiler": "Visual Studio",
            "compiler.version": "15",
            "compiler.cppstd": "17"
        }
        settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items()
                            if v)
        client.run("new hello/0.1 -s")
        configs = [("Release", "x86", True), ("Release", "x86_64", True),
                   ("Debug", "x86", False), ("Debug", "x86_64", False)]
        for build_type, arch, shared in configs:
            # Build the profile according to the settings provided
            runtime = "MT" if build_type == "Release" else "MTd"
            client.run(
                "create . hello/0.1@ %s -s build_type=%s -s arch=%s -s compiler.runtime=%s "
                " -o hello:shared=%s" %
                (settings, build_type, arch, runtime, shared))

        # 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
        for build_type, arch, shared in configs:
            runtime = "MT" if build_type == "Release" else "MTd"
            client.run(
                "install . %s -s build_type=%s -s arch=%s -s compiler.runtime=%s -if=conan"
                " -o hello:shared=%s" %
                (settings, build_type, arch, runtime, shared))

        vs_path = vs_installation_path("15")
        vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat")

        for build_type, arch, shared in configs:
            platform_arch = "x86" if arch == "x86" else "x64"
            if build_type == "Release" and shared:
                configuration = "ReleaseShared"
            else:
                configuration = build_type

            # The "conan build" command is not good enough, cannot do the switch between configs
            cmd = ('set "VSCMD_START_DIR=%%CD%%" && '
                   '"%s" x64 && msbuild "MyProject.sln" /p:Configuration=%s '
                   '/p:Platform=%s ' %
                   (vcvars_path, configuration, platform_arch))
            client.run_command(cmd)
            self.assertIn("Visual Studio 2017", client.out)
            self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'",
                          client.out)

            self._run_app(client, arch, build_type, shared)
            check_exe_run(client.out, "main", "msvc", "19.1", build_type, arch,
                          "17", {
                              "DEFINITIONS_BOTH": "True",
                              "DEFINITIONS_CONFIG": build_type
                          })

            new_cmd = "conan\\%s\\%s\\MyApp.exe" % (arch, configuration)
            vcvars = vcvars_command(version="15", architecture="amd64")
            cmd = ('%s && dumpbin /dependents "%s"' % (vcvars, new_cmd))
            client.run_command(cmd)
            if shared:
                self.assertIn("hello.dll", client.out)
            else:
                self.assertNotIn("hello.dll", client.out)
            self.assertIn("KERNEL32.dll", client.out)