Exemplo n.º 1
0
void CMaker::makeDefineName(OovStringRef const pkgName, OovString &defName)
    {
    OovString shortName;
    for(const char *p = pkgName; *p!='\0'; p++)
        {
        if(isalpha(*p))
            shortName += *p;
        }
    defName.setUpperCase(shortName);
    }
Exemplo n.º 2
0
void CMaker::makeTopInFile(OovStringRef const destName)
    {
    OovString projNameUpper;
    projNameUpper.setUpperCase(mProjectName);
    OovStringVec const compNames = mCompTypes.getComponentNames(true);

    std::string str = std::string("# - Config file for the ") + mProjectName + " package\n";

    str += "# Compute paths\n";
    str += std::string("get_filename_component(") + projNameUpper +
            "_CMAKE_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n";
    str += std::string("set(") + projNameUpper + "_INCLUDE_DIRS \"@CONF_INCLUDE_DIRS@\")\n\n";

    str += "# Our library dependencies (contains definitions for IMPORTED targets)\n";
    str += std::string("if(NOT TARGET ") + mProjectName + "AND NOT " +
            projNameUpper + "_BINARY_DIR)\n";
    str += "   include(\"${FOOBAR_CMAKE_DIR}/" + mProjectName + "Targets.cmake\")\n";
    str += "endif()\n\n";

    str += std::string("# These are IMPORTED targets created by ") + mProjectName +
            "Targets.cmake\n";
    str += std::string("set(") + projNameUpper + "_LIBRARIES";
    for(auto const &name : compNames)
        {
        ComponentTypesFile::eCompTypes compType = mCompTypes.getComponentType(name);
        if(compType == ComponentTypesFile::CT_StaticLib)
            {
            str += ' ';
            str += name;
            }
        }
    str += ")\n";
    str += std::string("set(") + projNameUpper + "_EXECUTABLE";
    for(auto const &name : compNames)
        {
        ComponentTypesFile::eCompTypes compType = mCompTypes.getComponentType(name);
        if(compType == ComponentTypesFile::CT_Program)
            {
            str += ' ';
            str += name;
            }
        }
    str += ")\n";
    writeFile(destName, str);
    }
Exemplo n.º 3
0
void CMaker::makeTopVerInFile(OovStringRef const destName)
    {
    OovString projNameUpper;
    projNameUpper.setUpperCase(mProjectName);

    std::string str;
    str += "set(PACKAGE_VERSION \"@" + projNameUpper + "_VERSION@\")\n\n";

    str += "# Check whether the requested PACKAGE_FIND_VERSION is compatible\n";
    str += "if(\"${PACKAGE_VERSION}\" VERSION_LESS \"${PACKAGE_FIND_VERSION}\")\n";
    str += "   set(PACKAGE_VERSION_COMPATIBLE FALSE)\n";
    str += "else()\n";
    str += "   set(PACKAGE_VERSION_COMPATIBLE TRUE)\n";
    str += "   if (\"${PACKAGE_VERSION}\" VERSION_EQUAL \"${PACKAGE_FIND_VERSION}\")\n";
    str += "      set(PACKAGE_VERSION_EXACT TRUE)\n";
    str += "   endif()\n";
    str += "endif()\n";
    writeFile(destName, str);
    }
Exemplo n.º 4
0
void CMaker::makeTopMakelistsFile(OovStringRef const destName)
    {
    std::string str;

    str += "cmake_minimum_required(VERSION 2.8)\n";
    str += std::string("project(") + mProjectName + ")\n";
    str += "INCLUDE(FindPkgConfig)\n\n";

    OovString projNameUpper;
    projNameUpper.setUpperCase(mProjectName);
    str += std::string("set(") + projNameUpper + "_MAJOR_VERION 0)\n";
    str += std::string("set(") + projNameUpper + "_MINOR_VERION 1)\n";
    str += std::string("set(") + projNameUpper + "_PATCH_VERION 0)\n";
    str += std::string("set(") + projNameUpper + "_VERION\n";
    str += std::string("${") + projNameUpper + "_MAJOR_VERSION}.${";
    str += projNameUpper + "_MINOR_VERSION}.${";
    str += projNameUpper + "_PATCH_VERSION})\n\n";

    str += "# Offer the user the choice of overriding the installation directories\n";
    str += "set(INSTALL_LIB_DIR lib CACHE PATH \"Installation directory for libraries\")\n";
    str += "set(INSTALL_BIN_DIR bin CACHE PATH \"Installation directory for executables\")\n";
    str += "set(INSTALL_INCLUDE_DIR include CACHE PATH\n";
    str += "   \"Installation directory for header files\")\n";
    str += "if(WIN32 AND NOT CYGWIN)\n";
    str += "   set(DEF_INSTALL_CMAKE_DIR CMake)\n";
    str += "else()\n";
    str += std::string("   set(DEF_INSTALL_CMAKE_DIR lib/CMake/") + mProjectName + ")\n";
    str += "endif()\n";
    str += "set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH\n";
    str += "   \"Installation directory for CMake files\")\n\n";

    str += "# Make relative paths absolute (needed later on)\n";
    str += "foreach(p LIB BIN INCLUDE CMAKE)\n";
    str += "   set(var INSTALL_${p}_DIR)\n";
    str += "   if(NOT IS_ABSOLUTE \"${${var}}\")\n";
    str += "      set(${var} \"${CMAKE_INSTALL_PREFIX}/${${var}}\")\n";
    str += "   endif()\n";
    str += "endforeach()\n\n";

    str += "# Add debug and release flags\n";
    str += "# Use from the command line with -DCMAKE_BUILD_TYPE=Release or Debug\n";
    str += "set(CMAKE_CXX_FLAGS_DEBUG \"${CMAKE_CXX_FLAGS_DEBUG} -Wall\")\n";
    str += "set(CMAKE_CXX_FLAGS_RELEASE \"${CMAKE_CXX_FLAGS_RELEASE} -Wall\")\n";

    str += "# External Packages\n";
    str += "if(NOT WIN32)\n";
    for(auto const &pkg : mBuildPkgs.getPackages())
        {
        addPackageDefines(pkg.getPkgName(), str);
        }
    str += "endif()\n\n";

    str += "# set up include directories\n";
    str += "include_directories(\n";

    OovStringVec const compNames = mCompTypes.getComponentNames(true);
    for(auto const &name : compNames)
        {
        ComponentTypesFile::eCompTypes compType = mCompTypes.getComponentType(name);
        if(compType == ComponentTypesFile::CT_StaticLib)
            str += std::string("   \"${PROJECT_SOURCE_DIR}/") + name + "\"\n";
        }
    str += "   )\n";
    str += "add_definitions(-std=c++11)\n\n";

    str += "# Add sub directories\n";
    for(auto const &name : compNames)
        {
        ComponentTypesFile::eCompTypes compType = mCompTypes.getComponentType(name);
        if(compType != ComponentTypesFile::CT_Unknown)
            {
            std::string compRelDir = name;
            str += std::string("add_subdirectory(") + compRelDir + ")\n";
            }
        }

    str += "# Add all targets to the build-tree export set\n";
    str += "export(TARGETS ";
    for(auto const &name : compNames)
        {
        ComponentTypesFile::eCompTypes compType = mCompTypes.getComponentType(name);
        if(compType != ComponentTypesFile::CT_Unknown)
            {
            str += ' ';
            str += makeComponentNameFromDir(name);
            }
        }
    str += "\n";
    str += "   FILE \"${PROJECT_BINARY_DIR}/" + mProjectName + "Targets.cmake\")\n\n";

    str += "# Export the package for use from the build-tree\n";
    str += "# (this registers the build-tree with a global CMake-registry)\n";
    str += std::string("export(PACKAGE ") + mProjectName + ")\n\n";

    str += std::string("# Create the ") +  mProjectName + "Config.cmake and " +
            mProjectName + "ConfigVersion files\n";
    str += "file(RELATIVE_PATH REL_INCLUDE_DIR \"${INSTALL_CMAKE_DIR}\"\n";
    str += "   \"${INSTALL_INCLUDE_DIR}\")\n";
    str += "# for the build tree\n";
    str += "set(CONF_INCLUDE_DIRS \"${PROJECT_SOURCE_DIR}\" \"${PROJECT_BINARY_DIR}\")\n";
    str += std::string("configure_file(") + mProjectName + "Config.cmake.in\n";
    str += std::string("   \"${PROJECT_BINARY_DIR}/") + mProjectName + "Config.cmake\" @ONLY)\n";
    str += "# for the install tree\n";
    str += "set(CONF_INCLUDE_DIRS \"\\${" + projNameUpper + "_CMAKE_DIR}/${REL_INCLUDE_DIR}\")\n";
    str += std::string("configure_file(") + mProjectName + "Config.cmake.in\n";
    str += std::string("   \"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/") +
            mProjectName + "Config.cmake\" @ONLY)\n";
    str += "# for both\n";
    str += std::string("configure_file(") + mProjectName + "ConfigVersion.cmake.in\n";
    str += std::string("   \"${PROJECT_BINARY_DIR}/") + mProjectName +
            "ConfigVersion.cmake\" @ONLY)\n\n";

    str += std::string("# Install the ") + mProjectName + "Config.cmake and " +
            mProjectName + "ConfigVersion.cmake\n";
    str += "install(FILES\n";
    str += std::string("   \"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/") +
            mProjectName + "Config.cmake\"\n";
    str += std::string("   \"${PROJECT_BINARY_DIR}/") + mProjectName +
            "ConfigVersion.cmake\"\n";
    str += "DESTINATION \"${INSTALL_CMAKE_DIR}\" COMPONENT dev)\n\n";

    str += "# Install the export set for use with the install-tree\n";
    str += std::string("install(EXPORT ") + mProjectName + "Targets DESTINATION\n";
    str += "   \"${INSTALL_CMAKE_DIR}\" COMPONENT dev)\n";
    writeFile(destName, str);
    }