Skip to content

Support for Qt Creator Generic project export and associated Makefile #4115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from tools.export import embitz, coide, kds, simplicity, atmelstudio
from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt
from tools.export import gnuarmeclipse
from tools.export import qtcreator
from tools.targets import TARGET_NAMES

EXPORTERS = {
Expand All @@ -55,6 +56,7 @@
'eclipse_iar' : cdt.EclipseIAR,
'eclipse_armc5' : cdt.EclipseArmc5,
'gnuarmeclipse': gnuarmeclipse.GNUARMEclipse,
'qtcreator': qtcreator.QtCreator,
'zip' : zip.ZIP,
'cmsis' : cmsis.CMSIS
}
Expand Down
68 changes: 68 additions & 0 deletions tools/export/qtcreator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
mbed SDK
Copyright (c) 2014-2017 ARM Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from os.path import splitext, basename
from tools.targets import TARGET_MAP
from tools.export.exporters import Exporter, filter_supported
from tools.export.makefile import GccArm

class QtCreator(GccArm):
NAME = 'QtCreator'
TOOLCHAIN = 'GCC_ARM'

TARGETS = filter_supported("GCC_ARM", set())

MBED_CONFIG_HEADER_SUPPORTED = True

def generate(self):
self.resources.win_to_unix()

defines = [] # list of tuples ('D'/'U', [key, value]) (value is optional)
forced_includes = [] # list of strings
sources = [] # list of strings
include_paths = [] # list of strings

next_is_include = False
for f in self.flags['c_flags'] + self.flags['cxx_flags']:
f=f.strip()
if next_is_include:
forced_includes.append(f)
next_is_include = False
continue
if f.startswith('-D'):
defines.append(('D', f[2:].split('=', 1)))
elif f.startswith('-U'):
defines.append(('U', [f[2:]]))
elif f == "-include":
next_is_include = True

for r_type in ['headers', 'c_sources', 's_sources', 'cpp_sources']:
sources.extend(getattr(self.resources, r_type))

include_paths = self.resources.inc_dirs

ctx = {
'defines': defines,
'forced_includes': forced_includes,
'sources': sources,
'include_paths': self.resources.inc_dirs
}

for ext in ['creator', 'files', 'includes', 'config']:
self.gen_file('qtcreator/%s.tmpl' % ext, ctx, "%s.%s" % (self.project_name, ext))

# finally, generate the Makefile
super(QtCreator, self).generate()
6 changes: 6 additions & 0 deletions tools/export/qtcreator/config.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% for d in defines -%}
{% if d[0] == 'D' %}#define {% else %}#undef{% endif %} {{ d[1]|join(' ')}}
{% endfor %}
{% for i in forced_includes -%}
#include "{{i}}"
{% endfor %}
1 change: 1 addition & 0 deletions tools/export/qtcreator/creator.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[General]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10/10 best template

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha I told you that I was a bit ashamed to inconvenience Jinja just for this kind of output. 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it's there if we need to add something to that configuration file.

3 changes: 3 additions & 0 deletions tools/export/qtcreator/files.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for s in sources -%}
{{s}}
{% endfor %}
3 changes: 3 additions & 0 deletions tools/export/qtcreator/includes.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for i in include_paths -%}
{{i}}
{% endfor %}