diff --git a/HISTORY.rst b/HISTORY.rst index 4a50f1ee..b757ec66 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,9 @@ PlatformIO 2.0 2.3.4 (2015-10-??) ~~~~~~~~~~~~~~~~~~ +* Full support of `CLion IDE `_ + including code auto-completion + (`issue #132 `_) * Added support for ubIQio Ardhat board (`pull #302 `_) * Use Teensy CLI Loader for upload of .hex files on Mac OS X diff --git a/docs/ide/clion.rst b/docs/ide/clion.rst index 5353fd06..8e1093ae 100644 --- a/docs/ide/clion.rst +++ b/docs/ide/clion.rst @@ -47,11 +47,19 @@ There are 3 predefined targets for building: * ``PLATFORMIO_CLEAN`` - clean compiled objects and etc. .. warning:: - CLion is still in the development stage, so some of the features (like, - auto-complete) probably will not work with PlatformIO. See - `CLion issue #CPP-3977 `_. + PlatformIO generates empty project by default and **code auto-completion + will not work!** To enable auto-completion please choose one of: - Active discussion located in + * Add source files ``*.c, *.cpp, etc`` to ``src`` directory and re-initialize + project with command above + * Manually correct ``add_executable`` command in ``CMakeLists.txt`` file + (will be created in project directory after initialization). + + ``*.ino`` file isn't acceptable for ``add_executable`` command. You should + convert it manually to ``*.cpp``. See `project example `_. + + More info `CLion issue #CPP-3977 `_. + Active discussion is located in `PlatformIO issue #132 `_. Screenshot diff --git a/docs/quickstart.rst b/docs/quickstart.rst index a4d5864a..7ef08e6d 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -28,7 +28,7 @@ Quickstart The next files/directories will be created in *** platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-| - src - Put your source code here + src - Put your source files here lib - Put here project specific (private) libraries Do you want to continue? [y/N]: y Project has been successfully initialized! @@ -37,7 +37,7 @@ Quickstart `platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board `platformio run --target clean` - clean project (remove compiled files) -Put your source code ``*.h, *.c, *.cpp or *.ino`` files to ``src`` directory. +Put your source files ``*.h, *.c, *.cpp or *.ino`` to ``src`` directory. 4. Process the project's environments. diff --git a/docs/userguide/cmd_init.rst b/docs/userguide/cmd_init.rst index 29fedc47..88be4447 100644 --- a/docs/userguide/cmd_init.rst +++ b/docs/userguide/cmd_init.rst @@ -22,7 +22,7 @@ Initialize new PlatformIO based project. This command will create: * :ref:`projectconf` -* ``src`` - a source directory. Put your source code here +* ``src`` - a source directory. Put your source files here * ``lib`` - a directory for the project specific (private) libraries. PlatformIO will compile them to static libraries and link to executable file @@ -94,7 +94,7 @@ Examples The next files/directories will be created in *** platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-| - src - Put your source code here + src - Put your source files here lib - Put here project specific (private) libraries Do you want to continue? [y/N]: y Project has been successfully initialized! @@ -112,7 +112,7 @@ Examples The next files/directories will be created in *** platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-| - src - Put your source code here + src - Put your source files here lib - Put here project specific (private) libraries Do you want to continue? [y/N]: y Project has been successfully initialized! @@ -136,7 +136,7 @@ Examples The next files/directories will be created in *** platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-| - src - Put your source code here + src - Put your source files here lib - Put here project specific (private) libraries Do you want to continue? [y/N]: y Project has been successfully initialized! diff --git a/examples/ide/clion/.idea/clion.iml b/examples/ide/clion/.idea/clion.iml index 352882ec..bc2cd874 100644 --- a/examples/ide/clion/.idea/clion.iml +++ b/examples/ide/clion/.idea/clion.iml @@ -1,9 +1,7 @@ - - - + diff --git a/examples/ide/clion/.idea/workspace.xml b/examples/ide/clion/.idea/workspace.xml index 214a2cba..95694b4f 100644 --- a/examples/ide/clion/.idea/workspace.xml +++ b/examples/ide/clion/.idea/workspace.xml @@ -2,13 +2,13 @@ - - - - - - - + + + + + + + @@ -33,25 +33,25 @@ - + - - + + - - + + - + @@ -67,8 +67,8 @@ - @@ -116,13 +116,13 @@ - - + + @@ -173,15 +173,15 @@ - + - + - + @@ -206,27 +206,27 @@ - + - - - - - - - - + + + + + + + + - - - + + + @@ -240,35 +240,12 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/ide/clion/CMakeLists.txt b/examples/ide/clion/CMakeLists.txt index 06cc9517..19d9e858 100644 --- a/examples/ide/clion/CMakeLists.txt +++ b/examples/ide/clion/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required(VERSION 3.2) -project(PlatformIO) +project(clion) -set(PLATFORMIO_CMD platformio) +set(ENV{PATH} "/Volumes/SOFT/Projects/GitHub/platformio/origin/.tox/develop/bin:/usr/local/opt/pyenv/shims:/Users/ikravets/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin") +set(PLATFORMIO_CMD "/Volumes/SOFT/Projects/GitHub/platformio/origin/.tox/develop/bin/platformio") include_directories("$ENV{HOME}/.platformio/packages/framework-arduinoavr/variants/standard") include_directories("$ENV{HOME}/.platformio/packages/framework-arduinoavr/cores/arduino") @@ -14,7 +15,7 @@ add_definitions(-DF_CPU=16000000L) add_definitions(-DARDUINO_ARCH_AVR) add_definitions(-DARDUINO_AVR_UNO) add_definitions(-DARDUINO=10605) -add_definitions(-DPLATFORMIO=020300) +add_definitions(-DPLATFORMIO=020304) add_definitions(-D__AVR_ATmega328P__) add_custom_target( @@ -33,4 +34,6 @@ add_custom_target( PLATFORMIO_CLEAN ALL COMMAND ${PLATFORMIO_CMD} -f -c clion run --target clean WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) \ No newline at end of file +) + +add_executable(clion src/blink.cpp) diff --git a/platformio/__init__.py b/platformio/__init__.py index 51ef87aa..33ac68f2 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 3, "4.dev1") +VERSION = (2, 3, "4.dev2") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 319f79b3..c558fcd5 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -65,7 +65,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913 click.style(project_dir, fg="cyan")) click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" % click.style("platformio.ini", fg="cyan")) - click.echo("%s - Put your source code here" % + click.echo("%s - Put your source files here" % click.style("src", fg="cyan")) click.echo("%s - Put here project specific (private) libraries" % click.style("lib", fg="cyan")) diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 6597b41d..a66bda87 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -7,6 +7,7 @@ import re from os.path import abspath, basename, expanduser, isdir, join, relpath import bottle +import click from platformio import util @@ -72,7 +73,7 @@ class ProjectGenerator(object): def get_project_name(self): return basename(self.project_dir) - def get_srcfiles(self): + def get_src_files(self): result = [] with util.cd(self.project_dir): for root, _, files in os.walk(util.get_projectsrc_dir()): @@ -80,6 +81,14 @@ class ProjectGenerator(object): result.append(relpath(join(root, f))) return result + @staticmethod + def get_main_src_file(src_files): + for f in src_files: + for ext in ("c", "cpp"): + if f.endswith(".%s" % ext): + return f + return None + def get_tpls(self): tpls = [] tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide) @@ -112,11 +121,23 @@ class ProjectGenerator(object): return bottle.template(content, **self._tplvars) def _gather_tplvars(self): + src_files = self.get_src_files() + main_src_file = self.get_main_src_file(src_files) + + if not main_src_file and self.ide == "clion": + click.secho( + "Warning! Can not find main source file (*.c, *.cpp). So, " + "code auto-completion is disabled. Please add source files " + "to `src` directory and re-initialize project or edit " + "`CMakeLists.txt` file manually (`add_executable` command).", + fg="yellow") + self._tplvars.update(self.get_project_env()) self._tplvars.update(self.get_project_build_data()) self._tplvars.update({ "project_name": self.get_project_name(), - "srcfiles": self.get_srcfiles(), + "src_files": src_files, + "main_src_file": main_src_file, "user_home_dir": abspath(expanduser("~")), "project_dir": self.project_dir, "systype": util.get_systype(), diff --git a/platformio/ide/tpls/clion/.idea/workspace.xml.tpl b/platformio/ide/tpls/clion/.idea/workspace.xml.tpl index 04b41db6..d76300c8 100644 --- a/platformio/ide/tpls/clion/.idea/workspace.xml.tpl +++ b/platformio/ide/tpls/clion/.idea/workspace.xml.tpl @@ -47,7 +47,7 @@ - % for file in srcfiles: + % for file in src_files: diff --git a/platformio/ide/tpls/clion/CMakeLists.txt.tpl b/platformio/ide/tpls/clion/CMakeLists.txt.tpl index b8e7ed62..680805a1 100644 --- a/platformio/ide/tpls/clion/CMakeLists.txt.tpl +++ b/platformio/ide/tpls/clion/CMakeLists.txt.tpl @@ -8,7 +8,7 @@ set(PLATFORMIO_CMD "{{platformio_path}}") % if include.startswith(user_home_dir): include_directories("$ENV{HOME}{{include.replace(user_home_dir, '').replace("\\", "/")}}") % else: -include_directories("{{include}}") +include_directories("{{include.replace("\\", "/")}}") % end % end @@ -32,4 +32,14 @@ add_custom_target( PLATFORMIO_CLEAN ALL COMMAND ${PLATFORMIO_CMD} -f -c clion run --target clean WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) \ No newline at end of file +) + +% if main_src_file: +add_executable({{project_name}} {{main_src_file}}) +% else: +# +# To enable code auto-completion, please specify path +# to main source file (*.c, *.cpp) and uncomment line below +# +# add_executable({{project_name}} src/main_change_me.cpp) +% end diff --git a/platformio/ide/tpls/qtcreator/platformio.pro.tpl b/platformio/ide/tpls/qtcreator/platformio.pro.tpl index a173ed07..b33b91cf 100644 --- a/platformio/ide/tpls/qtcreator/platformio.pro.tpl +++ b/platformio/ide/tpls/qtcreator/platformio.pro.tpl @@ -21,6 +21,6 @@ OTHER_FILES += \ platformio.ini SOURCES += \ - % for file in srcfiles: + % for file in src_files: {{file}} % end diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl index 716218f9..d66bb4be 100644 --- a/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl @@ -13,7 +13,7 @@ - % for file in srcfiles: + % for file in src_files: % if any([file.endswith(".%s" % e) for e in ("h", "hh", "hpp", "inc")]): diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl index c0201b39..b27a7ab2 100644 --- a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl @@ -58,7 +58,7 @@ - % for file in srcfiles: + % for file in src_files: % if any([file.endswith(".%s" % e) for e in ("h", "hh", "hpp", "inc")]):