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)
        targetIncludeDirectories = CMakeGeneratorUtil.BuildTargetIncludeDirectories(
            config, package, template.PackageTargetIncludeDirectories,
            template.PackageTargetIncludeDirEntry, pathType)
        targetIncludeDirectories = targetIncludeDirectories.replace(
            Variable.RecipeVariant, "${ANDROID_ABI}")

        includeFiles = self.__ExpandPathAndJoin(
            config, package, package.ResolvedBuildAllIncludeFiles)
        sourceFiles = self.__ExpandPathAndJoin(
            config, package, package.ResolvedBuildSourceFiles)
        linkLibrariesDirectDependencies = CMakeGeneratorUtil.BuildTargetLinkLibrariesForDirectDependencies(
            config, package, template.PackageDependencyTargetLinkLibraries,
            ignoreLibs)
        directDefinitions = CMakeGeneratorUtil.BuildDirectDefinitions(
            config, package,
            template.PackageDependencyTargetCompileDefinitions)
        findDirectExternalDependencies = CMakeGeneratorUtil.BuildFindDirectExternalDependencies(
            config, package, template.PackageDependencyFindPackage)

        buildCMakeFile = template.Master

        if package.Type == PackageType.Executable:
            if package.AbsoluteContentPath is None:
                raise Exception("Invalid package")
            packageContentPath = CMakeGeneratorUtil.GetSDKBasedPathUsingCMakeVariable(
                config, package.AbsoluteContentPath)
            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_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##",
            template.SnippetDefaultTargetCompileOptions)
        buildCMakeFile = buildCMakeFile.replace(
            "##SNIPPET_DEFAULT_TARGET_COMPILE_FEATURES##",
            template.SnippetDefaultTargetCompileFeatures)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_NAME!##",
                                                packageName.upper())
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_NAME##",
                                                packageName)
        buildCMakeFile = buildCMakeFile.replace("##ALIAS_PACKAGE_NAME##",
                                                aliasPackageName)

        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)
    def __GenerateCMakeFile(self, config: Config, package: Package,
                            platformName: str,
                            template: CMakeGeneratorUtil.CodeTemplateCMake,
                            toolProjectContextsDict: Dict[
                                ProjectId, ToolConfigProjectContext],
                            useExtendedProjectHack: bool) -> None:
        if package.Type == PackageType.TopLevel:
            raise Exception("Usage error")
        #if package.IsVirtual:
        #    return
        if package.AbsolutePath is None or package.ResolvedBuildPath is None:
            raise Exception("Invalid package")

        packageName = CMakeGeneratorUtil.GetPackageName(package)

        aliasPackageName = CMakeGeneratorUtil.GetAliasName(
            packageName, package.ProjectContext.ProjectName)

        targetIncludeDirectories = CMakeGeneratorUtil.BuildTargetIncludeDirectories(
            config, package, template.PackageTargetIncludeDirectories,
            template.PackageTargetIncludeDirEntry,
            template.PackageTargetIncludeDirVirtualEntry,
            CMakeGeneratorUtil.CMakePathType.LocalRelative)

        publicIncludeFiles = self.__Join(
            package.ResolvedBuildPublicIncludeFiles)
        privateIncludeFiles = self.__Join(
            package.ResolvedBuildPrivateIncludeFiles)
        includeFiles = self.__Join(package.ResolvedBuildAllIncludeFiles)
        sourceFiles = self.__Join(package.ResolvedBuildSourceFiles)

        linkLibrariesDirectDependencies = CMakeGeneratorUtil.BuildTargetLinkLibrariesForDirectDependencies(
            config, package, template.PackageDependencyTargetLinkLibraries,
            template.PackageDependencyFindPackage)
        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)
        targetFileCopy = CMakeGeneratorUtil.BuildFileCopy(
            config, package, template.PackageTargetCopyFile,
            template.PackageTargetCopyFilePath)

        cacheVariants = CMakeGeneratorUtil.GetCacheVariants(
            package, template.SnippetCacheVariant)

        contentInBinaryDirectory = True

        packageContentBuilder = CMakeGeneratorUtil.GetContentBuilder(
            config, package, platformName, template.PackageContentBuilder,
            contentInBinaryDirectory)
        #packageContentBuilderOutputFiles = CMakeGeneratorUtil.GetContentBuilderOutputFiles(config, package, contentInBinaryDirectory)

        packageContentSection = CMakeGeneratorUtil.GetContentSection(
            config, package, platformName, template.PackageContent,
            template.PackageContentFile, contentInBinaryDirectory)
        #packageContentSectionOutputFiles = CMakeGeneratorUtil.GetContentSectionOutputFiles(config, package, contentInBinaryDirectory)

        packageContentDep = CMakeGeneratorUtil.GetContentDepSection(
            config, package, platformName, template.PackageContentDep,
            contentInBinaryDirectory)
        packageContentDepOutputFiles = CMakeGeneratorUtil.GetContentDepOutputFile(
            config, package, contentInBinaryDirectory)

        packageCompilerSpecificFileDependencies = CMakeGeneratorUtil.CompilerSpecificFileDependencies(
            config, package, template.PackageCompilerConditional,
            template.PackageTargetSourceFiles,
            template.PackageCompilerFileDict)

        packageVariantSettings = CMakeGeneratorUtil.GetVariantSettings(
            config, package, template.PackageVariantSettings,
            template.PackageDependencyTargetCompileDefinitions,
            template.PackageDependencyTargetLinkLibraries)

        buildCMakeFile = template.Master
        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##",
            targetCompileFeatures)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_COPY_FILES##",
                                                targetFileCopy)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_GENERATE_INSTALL_INSTRUCTIONS##", installInstructions)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_CONTENTBUILDER##",
                                                packageContentBuilder)
        #buildCMakeFile = buildCMakeFile.replace("##PACKAGE_CONTENTBUILDER_OUTPUT_FILES##", packageContentBuilderOutputFiles)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_CONTENTSECTION_OUTPUT##", packageContentSection)
        #buildCMakeFile = buildCMakeFile.replace("##PACKAGE_CONTENTSECTION_OUTPUT_FILES##", packageContentSectionOutputFiles)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_CONTENTDEP##",
                                                packageContentDep)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_CONTENTDEP_OUTPUT_FILES##",
            packageContentDepOutputFiles)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_COMPILER_SPECIFIC_FILE_DEPENDENCIES##",
            packageCompilerSpecificFileDependencies)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_VARIANT_SETTINGS##",
                                                packageVariantSettings)

        toolProjectContext = toolProjectContextsDict[
            package.ProjectContext.ProjectId]
        sectionDefinePathEnvAsVariables = CMakeGeneratorUtil.CreateDefineRootDirectoryEnvironmentAsVariables(
            config.ToolConfig, toolProjectContext, useExtendedProjectHack,
            template.PathEnvToVariable)
        buildCMakeFile = self.__CommonReplace(
            buildCMakeFile, package.ProjectContext, packageName,
            aliasPackageName, cacheVariants, sectionDefinePathEnvAsVariables,
            config.ToolConfig.CMakeConfiguration.MinimumVersion, template)

        self.__SaveFile(GeneratorCMake._GetPackageBuildFileName(package),
                        buildCMakeFile)
        GitIgnoreHelper.SafeAddEntry(self.GitIgnoreDict, package,
                                     "CMakeLists.txt")
Beispiel #3
0
    def __GenerateCMakeFile(
            self, config: Config, package: Package, platformName: str,
            template: CMakeGeneratorUtil.CodeTemplateCMake) -> None:
        if package.IsVirtual:
            return
        if package.AbsolutePath is None or package.ResolvedBuildPath is None:
            raise Exception("Invalid package")

        packageName = CMakeGeneratorUtil.GetPackageName(package)

        addSubDirectoriesDirectDependencies = ""
        #findExternalDependencies = ""
        if package.Type == PackageType.TopLevel:
            package.AbsolutePath = config.SDKPath
            packageName = "DemoFrameworkTopLevel"
            addSubDirectoriesDirectDependencies = self.__BuildAddSubDirectoriesForDirectDependencies(
                config, package, template)
            #findExternalDependencies = self.__BuildFindExternalDependencies(config, package, template)

        aliasPackageName = CMakeGeneratorUtil.GetAliasName(packageName)

        targetIncludeDirectories = CMakeGeneratorUtil.BuildTargetIncludeDirectories(
            config, package, template.PackageTargetIncludeDirectories,
            template.PackageTargetIncludeDirEntry)

        includeFiles = self.__Join(package.ResolvedBuildAllIncludeFiles)
        sourceFiles = self.__Join(package.ResolvedBuildSourceFiles)

        linkLibrariesDirectDependencies = CMakeGeneratorUtil.BuildTargetLinkLibrariesForDirectDependencies(
            config, package, template.PackageDependencyTargetLinkLibraries)
        directDefinitions = CMakeGeneratorUtil.BuildDirectDefinitions(
            config, package,
            template.PackageDependencyTargetCompileDefinitions)
        findDirectExternalDependencies = CMakeGeneratorUtil.BuildFindDirectExternalDependencies(
            config, package, template.PackageDependencyFindPackage)

        buildCMakeFile = template.Master
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_INCLUDE_FILES##",
                                                includeFiles)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_SOURCE_FILES##",
                                                sourceFiles)
        buildCMakeFile = buildCMakeFile.replace(
            "##TARGET_INCLUDE_DIRECTORIES##", targetIncludeDirectories)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_DIRECT_DEPENDENCIES_ADD_SUBDIRECTORIES##",
            addSubDirectoriesDirectDependencies)
        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##",
            template.SnippetDefaultTargetCompileOptions)
        buildCMakeFile = buildCMakeFile.replace(
            "##SNIPPET_DEFAULT_TARGET_COMPILE_FEATURES##",
            template.SnippetDefaultTargetCompileFeatures)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_NAME!##",
                                                packageName.upper())
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_NAME##",
                                                packageName)
        buildCMakeFile = buildCMakeFile.replace("##ALIAS_PACKAGE_NAME##",
                                                aliasPackageName)

        buildBasePath = IOUtil.Join(package.AbsolutePath,
                                    package.ResolvedBuildPath)
        if not config.DisableWrite:
            IOUtil.SafeMakeDirs(buildBasePath)
            dstFileCMakeFile = IOUtil.Join(package.AbsolutePath,
                                           "CMakeLists.txt")
            IOUtil.WriteFileIfChanged(dstFileCMakeFile, buildCMakeFile)