diff --git a/docs/_static/ide-platformio-clion.png b/docs/_static/ide-platformio-clion.png
new file mode 100644
index 00000000..11f0754f
Binary files /dev/null and b/docs/_static/ide-platformio-clion.png differ
diff --git a/docs/ide.rst b/docs/ide.rst
index 48053b78..6e5623fe 100644
--- a/docs/ide.rst
+++ b/docs/ide.rst
@@ -7,6 +7,7 @@ IDE Integration
:maxdepth: 2
ide/arduino
+ ide/clion
ide/eclipse
ide/energia
ide/qtcreator
diff --git a/docs/ide/clion.rst b/docs/ide/clion.rst
new file mode 100644
index 00000000..2beb1c31
--- /dev/null
+++ b/docs/ide/clion.rst
@@ -0,0 +1,47 @@
+.. _ide_clion:
+
+CLion
+=====
+
+The `CLion `_ is a cross-platform C/C++ IDE
+for Linux, OS X, and Windows integrated with the CMake build system. The
+initial version will support the GCC and Clang compilers and GDB debugger.
+Clion includes such features as a smart editor, code quality assurance,
+automated refactorings, project manager, integrated version control systems.
+
+This software can be used with:
+
+* all available :ref:`platforms`
+* all available :ref:`frameworks`
+
+Refer to the `CDT Documentation `_
+page for more detailed information.
+
+.. contents::
+
+Integration
+-----------
+
+Project Generator
+^^^^^^^^^^^^^^^^^
+
+Since PlatformIO 2.0 you can generate CLion compatible project using
+:option:`platformio init --ide` command. Please choose board type using
+:ref:`cmd_boards` command and run:
+
+.. code-block:: shell
+
+ platformio init --ide clion --board %TYPE%
+
+Then import this project from start menu or via ``File > Import Project>`` and specify root directory where is located.
+
+:ref:`projectconf`
+
+.. warning::
+ CLion is still in the development stage, so some of the features probably will not work with PlatformIO
+
+Screenshot
+----------
+
+.. image:: ../_static/ide-platformio-clion.png
+ :target: http://docs.platformio.org/en/latest/_static/ide-platformio-clion.png
diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py
index 2d6dbcc6..1720e467 100644
--- a/platformio/ide/projectgenerator.py
+++ b/platformio/ide/projectgenerator.py
@@ -2,8 +2,7 @@
# See LICENSE for details.
import json
-from glob import glob
-from os import listdir, walk
+from os import listdir, makedirs, walk
from os.path import abspath, basename, expanduser, isdir, join, relpath
import bottle
@@ -76,14 +75,26 @@ class ProjectGenerator(object):
return result
def get_tpls(self):
+ tpls = []
tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide)
- return glob(join(tpls_dir, ".*.tpl")) + glob(join(tpls_dir, "*.tpl"))
+ for root, _, files in walk(tpls_dir):
+ for f in files:
+ if f.endswith(".tpl"):
+ tpls.append((
+ root.replace(tpls_dir, ""), join(root, f)))
+ return tpls
def generate(self):
- for tpl_path in self.get_tpls():
- file_name = basename(tpl_path)[:-4]
- with open(join(self.project_dir, file_name), "w") as f:
- f.write(self._render_tpl(tpl_path).encode("utf8"))
+ for _relpath, _path in self.get_tpls():
+ tpl_dir = self.project_dir
+ if _relpath:
+ tpl_dir = join(self.project_dir, _relpath)[1:]
+ if not isdir(tpl_dir):
+ makedirs(tpl_dir)
+
+ file_name = basename(_path)[:-4]
+ with open(join(tpl_dir, file_name), "w") as f:
+ f.write(self._render_tpl(_path).encode("utf8"))
def _render_tpl(self, tpl_path):
content = ""
diff --git a/platformio/ide/tpls/clion/.idea/clion.iml.tpl b/platformio/ide/tpls/clion/.idea/clion.iml.tpl
new file mode 100644
index 00000000..bc2cd874
--- /dev/null
+++ b/platformio/ide/tpls/clion/.idea/clion.iml.tpl
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/platformio/ide/tpls/clion/.idea/modules.xml.tpl b/platformio/ide/tpls/clion/.idea/modules.xml.tpl
new file mode 100644
index 00000000..9ce81f04
--- /dev/null
+++ b/platformio/ide/tpls/clion/.idea/modules.xml.tpl
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/platformio/ide/tpls/clion/.idea/platformio.iml.tpl b/platformio/ide/tpls/clion/.idea/platformio.iml.tpl
new file mode 100644
index 00000000..bc2cd874
--- /dev/null
+++ b/platformio/ide/tpls/clion/.idea/platformio.iml.tpl
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/platformio/ide/tpls/clion/.idea/workspace.xml.tpl b/platformio/ide/tpls/clion/.idea/workspace.xml.tpl
new file mode 100644
index 00000000..04b41db6
--- /dev/null
+++ b/platformio/ide/tpls/clion/.idea/workspace.xml.tpl
@@ -0,0 +1,266 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ % for file in srcfiles:
+
+
+
+
+
+
+
+
+
+
+ % end
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ C/C++
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1435919971910
+
+ 1435919971910
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/platformio/ide/tpls/clion/CMakeLists.txt.tpl b/platformio/ide/tpls/clion/CMakeLists.txt.tpl
new file mode 100644
index 00000000..9707347f
--- /dev/null
+++ b/platformio/ide/tpls/clion/CMakeLists.txt.tpl
@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 3.2)
+project({{project_name}})
+% for include in includes:
+% if include.startswith(user_home_dir):
+include_directories("$ENV{HOME}{{include.replace(user_home_dir, '').replace("\\", "/")}}")
+% else:
+include_directories("{{include}}")
+% end
+% end
+
+% for define in defines:
+add_definitions(-D{{define}})
+% end
+
+add_custom_target(
+ PLATFORMIO_BUILD ALL
+ COMMAND platformio -f run
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(
+ PLATFORMIO_UPLOAD ALL
+ COMMAND platformio -f run --target upload
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+add_custom_target(
+ PLATFORMIO_CLEAN ALL
+ COMMAND platformio -f run --target clean
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+)
\ No newline at end of file