Пример #1
0
def parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set):
    newlib = find_3rd_party_library_mapping(lib)
    if not newlib:
        print(f'    XXXX Unknown library "{lib}".')
        return

    if newlib.packageName is None:
        print(f'    **** Skipping library "{lib}" -- was masked.')
        return

    print(f"    mapped library {lib} to {newlib.targetName}.")

    # Avoid duplicate find_package calls.
    if newlib.targetName in cmake_find_packages_set:
        return

    # If certain libraries are used within a feature, but the feature
    # is only emitted conditionally with a simple condition (like
    # 'on Windows' or 'on Linux'), we should enclose the find_package
    # call for the library into the same condition.
    emit_if = newlib.emit_if

    # Only look through features if a custom emit_if wasn't provided.
    if not emit_if:
        for feature in data["features"]:
            feature_data = data["features"][feature]
            if (
                "condition" in feature_data
                and f"libs.{lib}" in feature_data["condition"]
                and "emitIf" in feature_data
                and "config." in feature_data["emitIf"]
            ):
                emit_if = feature_data["emitIf"]
                break

    if emit_if:
        emit_if = map_condition(emit_if)

    cmake_find_packages_set.add(newlib.targetName)

    find_package_kwargs = {"emit_if": emit_if}
    if newlib.is_bundled_with_qt:
        # If a library is bundled with Qt, it has 2 FindFoo.cmake
        # modules: WrapFoo and WrapSystemFoo.
        # FindWrapSystemFoo.cmake will try to find the 'Foo' library in
        # the usual CMake locations, and will create a
        # WrapSystemFoo::WrapSystemFoo target pointing to the library.
        #
        # FindWrapFoo.cmake will create a WrapFoo::WrapFoo target which
        # will link either against the WrapSystemFoo or QtBundledFoo
        # target depending on certain feature values.
        #
        # Because the following qt_find_package call is for
        # configure.cmake consumption, we make the assumption that
        # configure.cmake is interested in finding the system library
        # for the purpose of enabling or disabling a system_foo feature.
        find_package_kwargs["use_system_package_name"] = True

    cm_fh.write(generate_find_package_info(newlib, **find_package_kwargs))
Пример #2
0
def parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set):
    newlib = find_3rd_party_library_mapping(lib)
    if not newlib:
        print(f'    XXXX Unknown library "{lib}".')
        return

    if newlib.packageName is None:
        print(f'    **** Skipping library "{lib}" -- was masked.')
        return

    print(f"    mapped library {lib} to {newlib.targetName}.")

    # Avoid duplicate find_package calls.
    if newlib.targetName in cmake_find_packages_set:
        return

    # If certain libraries are used within a feature, but the feature
    # is only emitted conditionally with a simple condition (like
    # 'on Windows' or 'on Linux'), we should enclose the find_package
    # call for the library into the same condition.
    emit_if = newlib.emit_if

    # Only look through features if a custom emit_if wasn't provided.
    if not emit_if:
        for feature in data["features"]:
            feature_data = data["features"][feature]
            if ("condition" in feature_data
                    and f"libs.{lib}" in feature_data["condition"]
                    and "emitIf" in feature_data
                    and "config." in feature_data["emitIf"]):
                emit_if = feature_data["emitIf"]
                break

    if emit_if:
        emit_if = map_condition(emit_if)

    cmake_find_packages_set.add(newlib.targetName)

    cm_fh.write(generate_find_package_info(newlib, emit_if=emit_if))
Пример #3
0
def parseTest(ctx, test, data, cm_fh):
    skip_tests = {
        "c11",
        "c99",
        "gc_binaries",
        "posix-iconv",
        "sun-iconv",
        "precomile_header",
        "reduce_exports",
        "gc_binaries",
        "libinput_axis_api",
        "wayland-scanner",
        "xlib",
    }

    if test in skip_tests:
        print(f"    **** Skipping features {test}: masked.")
        return

    if data["type"] == "compile":
        knownTests.add(test)

        if "test" in data:
            details = data["test"]
        else:
            details = test

        write_compile_test(ctx, test, details, data, cm_fh)

    elif data["type"] == "libclang":
        knownTests.add(test)

        cm_fh.write(f"# {test}\n")
        lib_clang_lib = find_3rd_party_library_mapping("libclang")
        cm_fh.write(generate_find_package_info(lib_clang_lib))
        cm_fh.write(
            dedent("""
        if(TARGET WrapLibClang::WrapLibClang)
            set(TEST_libclang "ON" CACHE BOOL "Required libclang version found." FORCE)
        endif()
        """))
        cm_fh.write("\n")

    elif data["type"] == "x86Simd":
        knownTests.add(test)

        label = data["label"]

        cm_fh.write(f"# {test}\n")
        cm_fh.write(f'qt_config_compile_test_x86simd({test} "{label}")\n')
        cm_fh.write("\n")

    #    "features": {
    #        "android-style-assets": {
    #            "label": "Android Style Assets",
    #            "condition": "config.android",
    #            "output": [ "privateFeature" ],
    #            "comment": "This belongs into gui, but the license check needs it here already."
    #        },
    else:
        print(
            f"    XXXX UNHANDLED TEST TYPE {data['type']} in test description")
Пример #4
0
def parseTest(ctx, test, data, cm_fh):
    skip_tests = {
        "c11",
        "c99",
        "gc_binaries",
        "posix-iconv",
        "sun-iconv",
        "precomile_header",
        "reduce_exports",
        "separate_debug_info",  # FIXME: see if cmake can do this
        "gc_binaries",
        "libinput_axis_api",
        "wayland-scanner",
        "xlib",
    }

    if test in skip_tests:
        print(f"    **** Skipping features {test}: masked.")
        return

    if data["type"] == "compile":
        knownTests.add(test)

        details = data["test"]

        if isinstance(details, str):
            if not ctx["test_dir"]:
                print(f"    XXXX UNHANDLED TEST SUB-TYPE {details} in test description")
                return

            cm_fh.write(
                f"""
if(EXISTS "${{CMAKE_CURRENT_SOURCE_DIR}}/{ctx['test_dir']}/{data['test']}/CMakeLists.txt")
    qt_config_compile_test("{data['test']}"
                           LABEL "{data['label']}"
                           PROJECT_PATH "${{CMAKE_CURRENT_SOURCE_DIR}}/{ctx['test_dir']}/{data['test']}")
endif()
"""
            )
            return

        head = details.get("head", "")
        if isinstance(head, list):
            head = "\n".join(head)

        sourceCode = head + "\n"

        include = details.get("include", "")
        if isinstance(include, list):
            include = "#include <" + ">\n#include <".join(include) + ">"
        elif include:
            include = f"#include <{include}>"

        sourceCode += include + "\n"

        tail = details.get("tail", "")
        if isinstance(tail, list):
            tail = "\n".join(tail)

        sourceCode += tail + "\n"

        sourceCode += "int main(int argc, char **argv)\n"
        sourceCode += "{\n"
        sourceCode += "    (void)argc; (void)argv;\n"
        sourceCode += "    /* BEGIN TEST: */\n"

        main = details.get("main", "")
        if isinstance(main, list):
            main = "\n".join(main)

        sourceCode += main + "\n"

        sourceCode += "    /* END TEST: */\n"
        sourceCode += "    return 0;\n"
        sourceCode += "}\n"

        sourceCode = sourceCode.replace('"', '\\"')

        librariesCmakeName = ""
        languageStandard = ""
        qmakeFixme = ""

        cm_fh.write(f"# {test}\n")
        if "qmake" in details:  # We don't really have many so we can just enumerate them all
            if details["qmake"] == "unix:LIBS += -lpthread":
                librariesCmakeName = format(featureName(test)) + "_TEST_LIBRARIES"
                cm_fh.write("if (UNIX)\n")
                cm_fh.write("    set(" + librariesCmakeName + " pthread)\n")
                cm_fh.write("endif()\n")
            elif details["qmake"] == "linux: LIBS += -lpthread -lrt":
                librariesCmakeName = format(featureName(test)) + "_TEST_LIBRARIES"
                cm_fh.write("if (LINUX)\n")
                cm_fh.write("    set(" + librariesCmakeName + " pthread rt)\n")
                cm_fh.write("endif()\n")
            elif details["qmake"] == "!winrt: LIBS += runtimeobject.lib":
                librariesCmakeName = format(featureName(test)) + "_TEST_LIBRARIES"
                cm_fh.write("if (NOT WINRT)\n")
                cm_fh.write("    set(" + librariesCmakeName + " runtimeobject)\n")
                cm_fh.write("endif()\n")
            elif details["qmake"] == "CONFIG += c++11":
                # do nothing we're always in c++11 mode
                pass
            elif details["qmake"] == "CONFIG += c++11 c++14":
                languageStandard = "CXX_STANDARD 14"
            elif details["qmake"] == "CONFIG += c++11 c++14 c++17":
                languageStandard = "CXX_STANDARD 17"
            elif details["qmake"] == "CONFIG += c++11 c++14 c++17 c++2a":
                languageStandard = "CXX_STANDARD 20"
            else:
                qmakeFixme = f"# FIXME: qmake: {details['qmake']}\n"

        library_list = []
        if "use" in data:
            for library in data["use"].split(" "):
                if len(library) == 0:
                    continue

                mapped_library = find_3rd_party_library_mapping(library)
                if not mapped_library:
                    qmakeFixme += f"# FIXME: use: unmapped library: {library}\n"
                    continue
                library_list.append(mapped_library.targetName)

        cm_fh.write(f"qt_config_compile_test({featureName(test)}\n")
        cm_fh.write(lineify("LABEL", data.get("label", "")))
        if librariesCmakeName != "" or len(library_list) != 0:
            cm_fh.write("    LIBRARIES\n")
            if librariesCmakeName != "":
                cm_fh.write(lineify("", "${" + librariesCmakeName + "}"))
            if len(library_list) != 0:
                cm_fh.write("        ")
                cm_fh.write("\n        ".join(library_list))
                cm_fh.write("\n")
        cm_fh.write("    CODE\n")
        cm_fh.write('"' + sourceCode + '"')
        if qmakeFixme != "":
            cm_fh.write(qmakeFixme)
        if languageStandard != "":
            cm_fh.write(f"\n    {languageStandard}\n")
        cm_fh.write(")\n\n")

    elif data["type"] == "libclang":
        knownTests.add(test)

        cm_fh.write(f"# {test}\n")
        lib_clang_lib = find_3rd_party_library_mapping("libclang")
        cm_fh.write(generate_find_package_info(lib_clang_lib))
        cm_fh.write(
            dedent(
                """
        if(TARGET WrapLibClang::WrapLibClang)
            set(TEST_libclang "ON" CACHE BOOL "Required libclang version found." FORCE)
        endif()
        """
            )
        )
        cm_fh.write("\n")

    elif data["type"] == "x86Simd":
        knownTests.add(test)

        label = data["label"]

        cm_fh.write(f"# {test}\n")
        cm_fh.write(f'qt_config_compile_test_x86simd({test} "{label}")\n')
        cm_fh.write("\n")

    #    "features": {
    #        "android-style-assets": {
    #            "label": "Android Style Assets",
    #            "condition": "config.android",
    #            "output": [ "privateFeature" ],
    #            "comment": "This belongs into gui, but the license check needs it here already."
    #        },
    else:
        print(f"    XXXX UNHANDLED TEST TYPE {data['type']} in test description")
Пример #5
0
def parseLib(ctx, lib, data, cm_fh, cmake_find_packages_set):
    newlib = find_3rd_party_library_mapping(lib)
    if not newlib:
        print(f'    XXXX Unknown library "{lib}".')
        return

    if newlib.packageName is None:
        print(f'    **** Skipping library "{lib}" -- was masked.')
        return

    print(f"    mapped library {lib} to {newlib.targetName}.")

    # Avoid duplicate find_package calls.
    if newlib.targetName in cmake_find_packages_set:
        return

    # If certain libraries are used within a feature, but the feature
    # is only emitted conditionally with a simple condition (like
    # 'on Windows' or 'on Linux'), we should enclose the find_package
    # call for the library into the same condition.
    emit_if = newlib.emit_if

    # Only look through features if a custom emit_if wasn't provided.
    if not emit_if:
        for feature in data["features"]:
            feature_data = data["features"][feature]
            if ("condition" in feature_data
                    and f"libs.{lib}" in feature_data["condition"]
                    and "emitIf" in feature_data
                    and "config." in feature_data["emitIf"]):
                emit_if = feature_data["emitIf"]
                break

    if emit_if:
        emit_if = map_condition(emit_if)

    cmake_find_packages_set.add(newlib.targetName)

    find_package_kwargs = {"emit_if": emit_if}
    if newlib.is_bundled_with_qt:
        # If a library is bundled with Qt, it has 2 FindFoo.cmake
        # modules: WrapFoo and WrapSystemFoo.
        # FindWrapSystemFoo.cmake will try to find the 'Foo' library in
        # the usual CMake locations, and will create a
        # WrapSystemFoo::WrapSystemFoo target pointing to the library.
        #
        # FindWrapFoo.cmake will create a WrapFoo::WrapFoo target which
        # will link either against the WrapSystemFoo or QtBundledFoo
        # target depending on certain feature values.
        #
        # Because the following qt_find_package call is for
        # configure.cmake consumption, we make the assumption that
        # configure.cmake is interested in finding the system library
        # for the purpose of enabling or disabling a system_foo feature.
        find_package_kwargs["use_system_package_name"] = True
    find_package_kwargs["module"] = ctx["module"]

    cm_fh.write(generate_find_package_info(newlib, **find_package_kwargs))

    if "use" in data["libraries"][lib]:
        use_entry = data["libraries"][lib]["use"]
        if isinstance(use_entry, str):
            print(f"1use: {use_entry}")
            cm_fh.write(
                f"qt_add_qmake_lib_dependency({newlib.soName} {use_entry})\n")
        else:
            for use in use_entry:
                print(f"2use: {use}")
                indentation = ""
                has_condition = False
                if "condition" in use:
                    has_condition = True
                    indentation = "    "
                    condition = map_condition(use["condition"])
                    cm_fh.write(f"if({condition})\n")
                cm_fh.write(
                    f"{indentation}qt_add_qmake_lib_dependency({newlib.soName} {use['lib']})\n"
                )
                if has_condition:
                    cm_fh.write("endif()\n")

    run_library_test = False
    mapped_library = find_3rd_party_library_mapping(lib)
    if mapped_library:
        run_library_test = mapped_library.run_library_test

    if run_library_test and "test" in data["libraries"][lib]:
        test = data["libraries"][lib]["test"]
        write_compile_test(ctx,
                           lib,
                           test,
                           data,
                           cm_fh,
                           manual_library_list=[lib],
                           is_library_test=True)