Beispiel #1
0
    def __CreateCMakeSection_Sources(self, cmakeUIHInputVar,
                                     cmakeUICppInputVar, cmakeMocInputVar):
        """ Add sources to the target in the CMakeLists.txt """
        sources = self.project.GetSources()
        if not self.__HasCompilableFiles():
            sources.append(csnUtility.GetDummyCppFilename())
        if self.project.type == "executable":
            self.file.write(
                "ADD_EXECUTABLE(%s %s %s %s %s)\n" %
                (self.project.name, cmakeUIHInputVar, cmakeUICppInputVar,
                 cmakeMocInputVar, csnUtility.Join(sources, _addQuotes=1)))

        elif self.project.type == "library":
            self.file.write(
                "ADD_LIBRARY(%s STATIC %s %s %s %s)\n" %
                (self.project.name, cmakeUIHInputVar, cmakeUICppInputVar,
                 cmakeMocInputVar, csnUtility.Join(sources, _addQuotes=1)))

        elif self.project.type == "dll":
            self.file.write(
                "ADD_LIBRARY(%s SHARED %s %s %s %s)\n" %
                (self.project.name, cmakeUIHInputVar, cmakeUICppInputVar,
                 cmakeMocInputVar, csnUtility.Join(sources, _addQuotes=1)))

        elif self.project.type == "container":
            self.file.write("# Container project\n")

        else:
            raise NameError, "Unknown project type %s" % self.project.type
Beispiel #2
0
    def GenerateConfigFile(self, _public):
        """
        Generates the XXXConfig.cmake file for this project.
        _public - If true, generates a config file that can be used in any cmake file. If false,
        it generates the private config file that is used in the csnake-generated cmake files.
        """
        fileConfig = self.project.pathsManager.GetPathToConfigFile(_public)
        f = open(fileConfig, 'w')

        # create list with folder where libraries should be found. Add the folder where all the targets are placed to this list.
        publicLibraryFolders = self.project.GetCompileManager(
        ).public.libraryFolders
        if _public:
            publicLibraryFolders.append(self.project.GetBuildResultsFolder())

        # write header and some cmake fields
        f.write("# File generated automatically by the CSnake generator.\n")
        f.write("# DO NOT EDIT (changes will be lost)\n\n")
        f.write("SET( %s_FOUND TRUE )\n" % (self.project.name))
        f.write(
            "SET( %s_USE_FILE \"%s\" )\n" %
            (self.project.name, self.project.pathsManager.GetPathToUseFile()))
        f.write("SET( %s_INCLUDE_DIRS %s )\n" %
                (self.project.name,
                 csnUtility.Join(
                     self.project.GetCompileManager().public.includeFolders,
                     _addQuotes=1)))
        f.write("SET( %s_LIBRARY_DIRS %s )\n" %
                (self.project.name,
                 csnUtility.Join(publicLibraryFolders, _addQuotes=1)))
        if len(self.project.GetCompileManager().public.libraries):
            libraries = ""
            for buildType in self.project.GetCompileManager(
            ).public.libraries.keys():
                typeString = ""
                if buildType != "":
                    typeString = "\"%s\" " % buildType  # something like "debug "
                for library in self.project.GetCompileManager(
                ).public.libraries[buildType]:
                    libraries += "%s\"%s\"" % (typeString, library)
            f.write("SET( %s_LIBRARIES ${%s_LIBRARIES} %s )\n" %
                    (self.project.name, self.project.name, libraries))

        # add the target of this project to the list of libraries that should be linked
        if _public and len(self.project.GetSources()) > 0 and (
                self.project.type == "library" or self.project.type == "dll"):
            targetName = self.project.name
            f.write("SET( %s_LIBRARIES ${%s_LIBRARIES} %s )\n" %
                    (self.project.name, self.project.name,
                     csnUtility.Join([targetName], _addQuotes=1)))
Beispiel #3
0
 def testGlob(self):
     """ csnProjectTests: test that globbing source files works. """
     # dummyExe project
     dummyExe = csnProject.Project("DummyExe", "executable")
     dummyExe.AddSources(["data/my src/DummyExe/src/*.cpp"])
     # should have 1 source files
     assert len(dummyExe.GetSources()) == 1, csnUtility.Join(
         dummyExe.GetSources(), _addQuotes=1)
Beispiel #4
0
 def __CreateCMakeSection_SourceGroups(self):
     """ Create source groups in the CMakeLists.txt """
     for groupName in self.project.GetCompileManager().sourceGroups:
         self.file.write("\n # Create %s group \n" % groupName)
         self.file.write("IF (WIN32)\n")
         self.file.write(
             "  SOURCE_GROUP(\"%s\" FILES %s)\n" %
             (groupName,
              csnUtility.Join(
                  self.project.GetCompileManager().sourceGroups[groupName],
                  _addQuotes=1)))
         self.file.write("ENDIF(WIN32)\n\n")
Beispiel #5
0
    def GenerateUseFile(self):
        """
        Generates the UseXXX.cmake file for this project.
        """
        fileUse = self.project.pathsManager.GetPathToUseFile()
        f = open(fileUse, 'w')

        # write header and some cmake fields
        f.write("# File generated automatically by the CSnake generator.\n")
        f.write("# DO NOT EDIT (changes will be lost)\n\n")
        #f.write( "MESSAGE(\"Already using %s = ${AlreadyUsing%s}\")\n" % (self.project.name, self.project.name) )
        f.write("INCLUDE_DIRECTORIES(${%s_INCLUDE_DIRS})\n" %
                (self.project.name))
        f.write("LINK_DIRECTORIES(${%s_LIBRARY_DIRS})\n" % (self.project.name))

        # write definitions
        if len(self.project.GetCompileManager().public.definitions):
            f.write("ADD_DEFINITIONS(%s)\n" % csnUtility.Join(
                self.project.GetCompileManager().public.definitions))
Beispiel #6
0
 def __CreateCMakeSection_MocRules(self):
     """ Create moc rules in the CMakeLists.txt """
     cmakeMocInputVar = ""
     if len(self.project.GetCompileManager().sourcesToBeMoced):
         cmakeMocInputVarName = "MOC_%s" % (self.project.name)
         cmakeMocInputVar = "${%s}" % (cmakeMocInputVarName)
         self.file.write(
             "\nQT_WRAP_CPP( %s %s %s )\n" %
             (self.project.name, cmakeMocInputVarName,
              csnUtility.Join(
                  self.project.GetCompileManager().sourcesToBeMoced,
                  _addQuotes=1)))
         # write section for sorting moc files in a separate folder in Visual Studio
         self.file.write("\n # Create MOC group \n")
         self.file.write("IF (WIN32)\n")
         self.file.write(
             "  SOURCE_GROUP(\"Generated MOC Files\" REGULAR_EXPRESSION moc_[a-zA-Z0-9_]*[.]cxx$)\n"
         )
         self.file.write("ENDIF(WIN32)\n\n")
     return cmakeMocInputVar
Beispiel #7
0
 def __CreateCMakeSection_UicRules(self):
     """ Create uic rules in the CMakeLists.txt """
     cmakeUIHInputVar = ""
     cmakeUICppInputVar = ""
     if len(self.project.GetCompileManager().sourcesToBeUIed):
         cmakeUIHInputVarName = "UI_H_%s" % (self.project.name)
         cmakeUIHInputVar = "${%s}" % (cmakeUIHInputVarName)
         cmakeUICppInputVarName = "UI_CPP_%s" % (self.project.name)
         cmakeUICppInputVar = "${%s}" % (cmakeUICppInputVarName)
         self.file.write(
             "\nQT_WRAP_UI( %s %s %s %s )\n" %
             (self.project.name, cmakeUIHInputVarName,
              cmakeUICppInputVarName,
              csnUtility.Join(
                  self.project.GetCompileManager().sourcesToBeUIed,
                  _addQuotes=1)))
         # write section for sorting ui files in a separate folder in Visual Studio
         self.file.write("\n # Create UI group \n")
         self.file.write("IF (WIN32)\n")
         self.file.write(
             "  SOURCE_GROUP(\"Forms\" REGULAR_EXPRESSION [.]ui$)\n")
         self.file.write("ENDIF(WIN32)\n\n")
     return (cmakeUIHInputVar, cmakeUICppInputVar)
Beispiel #8
0
 def __CreateCMakeSection_Definitions(self):
     """ Create definitions in the CMakeLists.txt """
     if len(self.project.GetCompileManager().private.definitions):
         self.file.write("ADD_DEFINITIONS(%s)\n" % csnUtility.Join(
             self.project.GetCompileManager().private.definitions))