def __GetDstFilenameModifier(self, config: Config,
                                 dstPath: str,
                                 package: Package,
                                 appPackageTemplateInfo: AndroidGeneratorUtil.AppPackageTemplateInfo,
                                 template: CMakeGeneratorUtil.CodeTemplateCMake,
                                 androidProjectCMakeDir: str,
                                 androidABIList: List[str],
                                 templateFileProcessor: TemplateFileProcessor,
                                 cmakePackageRootVariables: str) -> Callable[[str], str]:
        androidHome = AndroidUtil.GetSDKPath()
        androidNDK = AndroidUtil.GetNDKPath()
        androidNDKForProp = self.__ToPropPath(androidNDK)
        androidHomeForProp = self.__ToPropPath(androidHome)

        androidABIList = self.__patchABIList(config, package, androidABIList)
        self.__CheckABI(package, androidABIList)

        packageVariantGradleAndroidABIList = self.__CreateGradleAndroidABIList(androidABIList)

        packageName = CMakeGeneratorUtil.GetPackageName(package)
        cmakePackageExeLib = CMakeGeneratorUtil.GetAliasName(packageName, package.ProjectContext.ProjectName)
        cmakePackageFindDirectExternalDependencies = CMakeGeneratorUtil.BuildFindDirectExternalDependencies(config, package, template.PackageDependencyFindPackage)
        cmakePackageDirectDependenciesAndSubDirectories = self.__BuildCMakeAddSubDirectoriesForDirectDependencies(config, package, template, androidProjectCMakeDir)

        addCMakeLibsList = self.__AddCMakeLibs(package)

        thirdPartyLibsList = []  # type: List[str]
        for entry in addCMakeLibsList:
            for staticLib in entry.StaticLibs:
                thirdPartyLibsList.append(staticLib.Name)

        thirdPartyAddLibs = ""
        for entry in addCMakeLibsList:
            for staticLib in entry.StaticLibs:
                content = template.AddImportedLibrary
                content = content.replace("##LIBRARY_NAME##", staticLib.Name)
                content = content.replace("##LIBRARY_TYPE##", "STATIC")
                content = content.replace("##LIBRARY_PATH##", staticLib.Path)
                thirdPartyAddLibs += "\n" + content

        # thirdPartyLibs is a space seperated list of third party lib names
        thirdPartyLibs = " ".join(thirdPartyLibsList)

        templateFileProcessor.Environment.Set("##CMAKE_THIRD_PARTY_LIBS##", thirdPartyLibs)
        templateFileProcessor.Environment.Set("##CMAKE_THIRD_PARTY_ADD_LIBS##", thirdPartyAddLibs)
        templateFileProcessor.Environment.Set("##CMAKE_PACKAGE_DIRECT_DEPENDENCIES_ADD_SUBDIRECTORIES##", cmakePackageDirectDependenciesAndSubDirectories)
        templateFileProcessor.Environment.Set("##CMAKE_PACKAGE_FIND_DIRECT_EXTERNAL_DEPENDENCIES##", cmakePackageFindDirectExternalDependencies)
        templateFileProcessor.Environment.Set("##CMAKE_PACKAGE_EXE_LIB##", cmakePackageExeLib)
        templateFileProcessor.Environment.Set("##CMAKE_DEFINE_PACKAGE_ROOT_VARIABLES##", cmakePackageRootVariables)

        templateFileProcessor.Environment.Set("##ENV_ANDROID_HOME_FOR_PROP##", androidHomeForProp)
        templateFileProcessor.Environment.Set("##ENV_ANDROID_NDK_FOR_PROP##", androidNDKForProp)
        templateFileProcessor.Environment.Set("##FSL_PACKAGE_GLES_VERSION##", appPackageTemplateInfo.MinGLESVersion)
        templateFileProcessor.Environment.Set("##FSL_PACKAGE_MIN_ANDROID_SDK_VERSION##", appPackageTemplateInfo.MinSDKVersion.VersionString)
        templateFileProcessor.Environment.Set("##FSL_PACKAGE_TARGET_ANDROID_SDK_VERSION##", appPackageTemplateInfo.TargetSDKVersion.VersionString)
        templateFileProcessor.Environment.Set("##PACKAGE_APP_PLATFORM##", appPackageTemplateInfo.MinSDKVersion.AppPlatform)
        templateFileProcessor.Environment.Set("##PACKAGE_VARIANT_ANDROID_ABIS##", packageVariantGradleAndroidABIList)
        templateFileProcessor.Environment.Set("##PREFIXED_PROJECT_NAME##", appPackageTemplateInfo.PrefixedProjectName)
        templateFileProcessor.Environment.Set("##PREFIXED_PROJECT_NAME_L##", appPackageTemplateInfo.PrefixedProjectName.lower())

        return appPackageTemplateInfo.UpdateFileName
    def __init__(self, config: Config, packages: List[Package],
                 platformName: str, androidABIList: List[str]) -> None:
        super().__init__()

        if config.SDKPathAndroidProjectDir is None:
            raise EnvironmentError(
                "Android environment variable {0} not defined".format(
                    ToolEnvironmentVariableName.
                    FSL_GRAPHICS_SDK_ANDROID_PROJECT_DIR))

        strAppTemplatePath = "AndroidGradleCMake"
        templateFilePath = IOUtil.Join(config.SDKConfigTemplatePath,
                                       strAppTemplatePath)
        templateFileRecordManager = TemplateFileRecordManager(templateFilePath)
        templateFileProcessor = TemplateFileProcessor(config, platformName)

        strTemplatePath = IOUtil.Join(strAppTemplatePath, "CMake")
        extTemplate = CMakeGeneratorUtil.CodeTemplateCMake(
            config, strTemplatePath, "Ext", False, None)
        libTemplate = CMakeGeneratorUtil.CodeTemplateCMake(
            config, strTemplatePath, "Lib", False, None)
        exeTemplate = CMakeGeneratorUtil.CodeTemplateCMake(
            config, strTemplatePath, "Exe", False, None)

        templatePath = IOUtil.Join(config.SDKConfigTemplatePath,
                                   strAppTemplatePath)
        exeFileList = self.__ParseExeFileList(
            IOUtil.Join(templatePath, "ExeFiles.txt"))

        localSnippets = AndroidGradleCMakeSnippets(templatePath)

        cmakePackageRootVariables = self.__GenerateCmakePackageRootVariables(
            config, localSnippets)

        totalExeCount = 0
        for mainPackage in packages:
            if mainPackage.Type == PackageType.Executable:
                totalExeCount = totalExeCount + 1
                appPackageTemplateInfo = AndroidGeneratorUtil.AppPackageTemplateInfo(
                    mainPackage)
                androidProjectDir = IOUtil.Join(
                    config.SDKPathAndroidProjectDir,
                    appPackageTemplateInfo.ProjectPathName)
                androidProjectCMakeDir = IOUtil.Join(androidProjectDir,
                                                     ".FslCMake")

                for package in mainPackage.ResolvedBuildOrder:
                    if not package.ResolvedPlatformNotSupported:
                        if package.Type == PackageType.ExternalLibrary or package.Type == PackageType.HeaderLibrary:
                            self.__GenerateCMakeFile(config, package,
                                                     platformName, extTemplate,
                                                     androidProjectDir,
                                                     androidProjectCMakeDir)
                        elif package.Type == PackageType.Library:
                            self.__GenerateCMakeFile(config, package,
                                                     platformName, libTemplate,
                                                     androidProjectDir,
                                                     androidProjectCMakeDir)
                        elif package.Type == PackageType.Executable:
                            self.__GenerateExecutable(
                                config, package, platformName, exeTemplate,
                                templateFileRecordManager,
                                templateFileProcessor, appPackageTemplateInfo,
                                androidProjectDir, androidProjectCMakeDir,
                                exeFileList, androidABIList,
                                cmakePackageRootVariables)

        # For now we only support doing 'exe' builds using full source for everything (like the old builder)
        if totalExeCount <= 0:
            config.DoPrint("No executables provided, nothing to build.")
    def __GenerateCMakeFile(self, config: Config,
                            package: Package,
                            platformName: str,
                            template: CMakeGeneratorUtil.CodeTemplateCMake,
                            androidProjectDir: str,
                            androidProjectCMakeDir: str) -> None:

        pathType = CMakeGeneratorUtil.CMakePathType.Relative

        packageName = CMakeGeneratorUtil.GetPackageName(package)

        # this ignore is a workaround allowing us to build using the same info as the old Android builder
        ignoreLibs = ["android_native_app_glue"]

        aliasPackageName = CMakeGeneratorUtil.GetAliasName(packageName, package.ProjectContext.ProjectName)
        targetIncludeDirectories = CMakeGeneratorUtil.BuildTargetIncludeDirectories(config, package, template.PackageTargetIncludeDirectories,
                                                                                    template.PackageTargetIncludeDirEntry, template.PackageTargetIncludeDirVirtualEntry, pathType)
        targetIncludeDirectories = targetIncludeDirectories.replace(Variable.RecipeVariant, "${ANDROID_ABI}")

        publicIncludeFiles = self.__ExpandPathAndJoin(config, package, package.ResolvedBuildPublicIncludeFiles)
        privateIncludeFiles = self.__ExpandPathAndJoin(config, package, package.ResolvedBuildPrivateIncludeFiles)
        includeFiles = self.__ExpandPathAndJoin(config, package, package.ResolvedBuildAllIncludeFiles)
        sourceFiles = self.__ExpandPathAndJoin(config, package, package.ResolvedBuildSourceFiles)
        linkLibrariesDirectDependencies = CMakeGeneratorUtil.BuildTargetLinkLibrariesForDirectDependencies(config, package,
                                                                                                           template.PackageDependencyTargetLinkLibraries,
                                                                                                           template.PackageDependencyFindPackage,
                                                                                                           ignoreLibs)
        linkLibrariesDirectDependencies = linkLibrariesDirectDependencies.replace(Variable.RecipeVariant, "${ANDROID_ABI}")
        directDefinitions = CMakeGeneratorUtil.BuildDirectDefinitions(config, package, template.PackageDependencyTargetCompileDefinitions)
        findDirectExternalDependencies = CMakeGeneratorUtil.BuildFindDirectExternalDependencies(config, package, template.PackageDependencyFindPackage)
        installInstructions = CMakeGeneratorUtil.BuildInstallInstructions(config, package, template.PackageInstall,
                                                                          template.PackageInstallTargets,
                                                                          template.PackageInstallHeaders,
                                                                          template.PackageInstallContent,
                                                                          template.PackageInstallDLL,
                                                                          template.PackageInstallAppInfo)
        targetCompileFeatures = CMakeGeneratorUtil.BuildCompileFeatures(config, package, template.SnippetTargetCompileFeaturesDefault,
                                                                        template.SnippetTargetCompileFeaturesInterface)
        targetCompileOptions = CMakeGeneratorUtil.BuildCompileOptions(config, package, template.SnippetTargetCompileOptionsDefault)

        buildCMakeFile = template.Master

        if package.Type == PackageType.Executable:
            if package.ContentPath is None:
                raise Exception("Invalid package")
            packageContentPath = CMakeGeneratorUtil.GetSDKBasedPathUsingCMakeVariable(config, package.ContentPath.AbsoluteDirPath)
            buildCMakeFile = buildCMakeFile.replace("##PACKAGE_CONTENT_PATH##", packageContentPath)
            buildCMakeFile = buildCMakeFile.replace("##PACKAGE_ANDROID_PROJECT_PATH##", androidProjectDir)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_INCLUDE_FILES##", includeFiles)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_PUBLIC_INCLUDE_FILES##", publicIncludeFiles)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_PRIVATE_INCLUDE_FILES##", privateIncludeFiles)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_SOURCE_FILES##", sourceFiles)
        buildCMakeFile = buildCMakeFile.replace("##TARGET_INCLUDE_DIRECTORIES##", targetIncludeDirectories)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_DIRECT_DEPENDENCIES_TARGET_LINK_LIBRARIES##", linkLibrariesDirectDependencies)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_DIRECT_DEPENDENCIES_TARGET_COMPILE_DEFINITIONS##", directDefinitions)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGES_FIND_DIRECT_EXTERNAL_DEPENDENCIES##", findDirectExternalDependencies)
        buildCMakeFile = buildCMakeFile.replace("##SNIPPET_DEFAULT_TARGET_COMPILE_OPTIONS##", targetCompileOptions)
        buildCMakeFile = buildCMakeFile.replace("##SNIPPET_DEFAULT_TARGET_COMPILE_FEATURES##", template.SnippetTargetCompileFeaturesDefault)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_GENERATE_INSTALL_INSTRUCTIONS##", installInstructions)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_NAME!##", packageName.upper())
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_NAME##", packageName)
        buildCMakeFile = buildCMakeFile.replace("##ALIAS_PACKAGE_NAME##", aliasPackageName)
        buildCMakeFile = buildCMakeFile.replace("##PROJECT_NAME##", package.ProjectContext.ProjectName)
        buildCMakeFile = buildCMakeFile.replace("##PROJECT_VERSION##", package.ProjectContext.ProjectVersion)

        if not config.DisableWrite:
            # We store all cmake build files in their own dir inside the 'android' exe-project's folder
            # to prevent collision with other more generic CMake builders
            packageCMakeDir = self.__GetPackageCMakeDir(androidProjectCMakeDir, package)
            IOUtil.SafeMakeDirs(packageCMakeDir)
            dstFileCMakeFile = self.__GetPackageCMakeFileName(androidProjectCMakeDir, package)
            IOUtil.WriteFileIfChanged(dstFileCMakeFile, buildCMakeFile)