qtcreator project generator now includes defines and correct include paths.
authorCampbell Barton <ideasman42@gmail.com>
Sat, 26 Feb 2011 11:18:36 +0000 (11:18 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 26 Feb 2011 11:18:36 +0000 (11:18 +0000)
build_files/cmake/cmake_qtcreator_project.py

index 925aee564b8b1ae126d6c610e874e966a4cfc1f9..da0a7b4fc3b18482aadccbb7222a582c322c9fff 100644 (file)
@@ -30,6 +30,7 @@ base = join(os.path.dirname(__file__), "..", "..")
 base = normpath(base)
 base = abspath(base)
 
+SIMPLE_PROJECTFILE = False
 
 def source_list(path, filename_check=None):
     for dirpath, dirnames, filenames in os.walk(path):
@@ -73,29 +74,120 @@ def is_svn_file(filename):
 def is_project_file(filename):
     return (is_c_any(filename) or is_cmake(filename)) and is_svn_file(filename)
 
-files = list(source_list(base, filename_check=is_project_file))
-files_rel = [relpath(f, start=base) for f in files]
-files_rel.sort()
 
-
-# --- qtcreator spesific, simple format
-PROJECT_NAME = "Blender"
-f = open(join(base, "%s.files" % PROJECT_NAME), 'w')
-f.write("\n".join(files_rel))
-
-f = open(join(base, "%s.includes" % PROJECT_NAME), 'w')
-f.write("\n".join(sorted(list(set(dirname(f) for f in files_rel if is_c_header(f))))))
-
-qtc_prj = join(base, "%s.creator" % PROJECT_NAME)
-f = open(qtc_prj, 'w')
-f.write("[General]\n")
-
-qtc_cfg = join(base, "%s.config" % PROJECT_NAME)
-if not exists(qtc_cfg):
-    f = open(qtc_cfg, 'w')
-    f.write("// ADD PREDEFINED MACROS HERE!\n")
-    # todo, include real defines.
-    f.write("#define WITH_PYTHON\n")
-
-print("Project file written to: %s" % qtc_prj)
-# --- end
+def cmake_advanced_info():
+    """ Extracr includes and defines from cmake.
+    """
+
+    def create_eclipse_project(cmake_dir):
+        cmd = 'cmake %r -G"Eclipse CDT4 - Unix Makefiles"' % cmake_dir
+        os.system(cmd)
+
+    includes = []
+    defines = []
+    
+    import os
+    import sys
+
+    cmake_dir = sys.argv[-1]
+
+    if not os.path.join(cmake_dir, "CMakeCache.txt"):
+        cmake_dir = os.getcwd()
+    if not os.path.join(cmake_dir, "CMakeCache.txt"):
+        print("CMakeCache.txt not found in %r or %r\n    Pass CMake build dir as an argument, or run from that dir, abording" % (cmake_dir, os.getcwd()))
+        sys.exit(1)
+
+    # create_eclipse_project(cmake_dir)
+    
+    from xml.dom.minidom import parse
+    tree = parse(os.path.join(cmake_dir, ".cproject"))
+    '''
+    f = open(".cproject_pretty", 'w')
+    f.write(tree.toprettyxml(indent="    ", newl=""))
+    '''
+    ELEMENT_NODE = tree.ELEMENT_NODE
+    
+    cproject, = tree.getElementsByTagName("cproject")
+    for storage in cproject.childNodes:
+        if storage.nodeType != ELEMENT_NODE:
+            continue
+        
+        if storage.attributes["moduleId"].value == "org.eclipse.cdt.core.settings":
+            cconfig = storage.getElementsByTagName("cconfiguration")[0]
+            for substorage in cconfig.childNodes:
+                if substorage.nodeType != ELEMENT_NODE:
+                    continue
+
+                moduleId = substorage.attributes["moduleId"].value
+
+                # org.eclipse.cdt.core.settings
+                # org.eclipse.cdt.core.language.mapping
+                # org.eclipse.cdt.core.externalSettings
+                # org.eclipse.cdt.core.pathentry
+                # org.eclipse.cdt.make.core.buildtargets
+
+                if moduleId == "org.eclipse.cdt.core.pathentry":
+                    for path in substorage.childNodes:
+                        if path.nodeType != ELEMENT_NODE:
+                            continue
+                        kind = path.attributes["kind"].value
+
+                        if kind == "mac":
+                            # <pathentry kind="mac" name="PREFIX" path="" value="&quot;/opt/blender25&quot;"/>
+                            defines.append((path.attributes["name"].value, path.attributes["value"].value))
+                        elif kind == "inc":
+                            # <pathentry include="/data/src/blender/blender/source/blender/editors/include" kind="inc" path="" system="true"/>
+                            includes.append(path.attributes["include"].value)
+                        else:
+                            print(kind)
+
+    return includes, defines
+
+
+def main():
+    files = list(source_list(base, filename_check=is_project_file))
+    files_rel = [relpath(f, start=base) for f in files]
+    files_rel.sort()
+
+    # --- qtcreator spesific, simple format
+    if SIMPLE_PROJECTFILE:
+        # --- qtcreator spesific, simple format
+        PROJECT_NAME = "Blender"
+        f = open(join(base, "%s.files" % PROJECT_NAME), 'w')
+        f.write("\n".join(files_rel))
+
+        f = open(join(base, "%s.includes" % PROJECT_NAME), 'w')
+        f.write("\n".join(sorted(list(set(dirname(f) for f in files_rel if is_c_header(f))))))
+
+        qtc_prj = join(base, "%s.creator" % PROJECT_NAME)
+        f = open(qtc_prj, 'w')
+        f.write("[General]\n")
+
+        qtc_cfg = join(base, "%s.config" % PROJECT_NAME)
+        if not exists(qtc_cfg):
+            f = open(qtc_cfg, 'w')
+            f.write("// ADD PREDEFINED MACROS HERE!\n")
+    else:
+        includes, defines = cmake_advanced_info()
+        
+        PROJECT_NAME = "Blender"
+        f = open(join(base, "%s.files" % PROJECT_NAME), 'w')
+        f.write("\n".join(files_rel))
+
+        f = open(join(base, "%s.includes" % PROJECT_NAME), 'w')
+        f.write("\n".join(sorted(includes)))
+
+        qtc_prj = join(base, "%s.creator" % PROJECT_NAME)
+        f = open(qtc_prj, 'w')
+        f.write("[General]\n")
+
+        qtc_cfg = join(base, "%s.config" % PROJECT_NAME)
+        f = open(qtc_cfg, 'w')
+        f.write("// ADD PREDEFINED MACROS HERE!\n")
+        f.write("\n".join([("#define %s %s" % item) for item in defines]))
+
+    print("Project file written to: %s" % qtc_prj)
+    # --- end
+
+if __name__ == "__main__":
+    main()