Example #1
0
// outDir ignored if writeToProject is true.
void CMaker::makeComponentFiles(bool writeToProject, OovStringRef const outDir,
        OovStringVec const &compNames)
    {
    FilePath incMapFn(getAnalysisPath(), FP_Dir);
    incMapFn.appendFile(Project::getAnalysisIncDepsFilename());
    mIncMap.read(incMapFn);
    if(mVerbose)
        printf("Read incmap\n");
    for(auto const &compName : compNames)
        {
        ComponentTypesFile::eCompTypes compType =
            mCompTypes.getComponentType(compName);
        if(compType != ComponentTypesFile::CT_Unknown)
            {
            OovStringVec sources = getCompSources(compName);
            FilePath outFp;
            std::string fixedCompName = makeComponentNameFromDir(compName);
            if(writeToProject)
                {
                outFp.setPath(mCompTypes.getComponentAbsolutePath(
                        compName), FP_Dir);
                outFp.appendFile("CMakeLists.txt");
                }
            else
                {
                outFp.setPath(outDir, FP_File);
                outFp.appendFile(std::string(fixedCompName + "-CMakeLists.txt"));
                }
            // Using the filepath here gives:
            // "Error evaluating generator expression", and "Target name not supported"
            makeComponentFile(fixedCompName, compType,
                    sources, outFp);
            }
        }
    }
Example #2
0
void setupCWD()
{
#ifdef __GLIBC__
    cwd.setPath(get_current_dir_name());
    return;
#else // untested
    const char *env = getenv("CWD");
    if (env)
    {
        cwd.setPath(env);
        return;
    }

    char buf[PATH_MAX + 1];
    if (getcwd(buf, PATH_MAX))
    {
        cwd.setPath(buf);
    }
#endif // __GLIBC__
}
Example #3
0
int main(int argc, char * argv[])
    {
    int ret = 1;
    bool verbose = false;
    bool writeToProject = false;
    const char *projDir = nullptr;
    const char *projName = "PROJNAME";

    for(int argi=1; argi<argc; argi++)
        {
        if(argv[argi][0] == '-')
            {
            switch(argv[argi][1])
                {
                case 'v':
                    verbose = true;
                    break;

                case 'w':
                    writeToProject = true;
                    break;

                case 'n':
                    projName = &argv[argi][2];
                    break;
                }
            }
        else
            projDir = argv[argi];
        }
    if(projDir)
        {
        Project::setProjectDirectory(projDir);
        CMaker maker(projName, verbose);

        FilePath outDir;
        if(writeToProject)
            {
            outDir.setPath(Project::getSrcRootDirectory(), FP_Dir);
            }
        else
            {
            outDir.setPath(Project::getBuildOutputDir("CMake"), FP_Dir);
            FileEnsurePathExists(outDir);
            if(maker.mVerbose)
                printf("Output directory %s\n", outDir.getStr());
            }

        if(maker.mCompTypes.read())
            {
            maker.makeToolchainFiles(outDir);
            maker.makeTopLevelFiles(outDir);

            maker.mBuildPkgs.read();

            FilePath topMlFp(outDir, FP_File);
            topMlFp.appendFile("CMakeLists.txt");
            maker.makeTopMakelistsFile(topMlFp);

            OovStringVec compNames = maker.mCompTypes.getComponentNames(true);
            if(compNames.size() > 0)
                {
                maker.makeComponentFiles(writeToProject, outDir, compNames);
                ret = 0;
                }
            else
                fprintf(stderr, "Components must be defined\n");
            }
        else
            fprintf(stderr, "Unable to read project files\n");
        }
    else
        {
        fprintf(stderr, "OovCMaker version %s\n", OOV_VERSION);
        fprintf(stderr, "  OovCMaker projectDirectory [switches]\n");
        fprintf(stderr, "    switches -v=verbose, -w=write to project, -nProjName\n");
        }
    return ret;
    }