From 0751a2cef96516b85ec4dff6762479b592216a91 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 4 Jan 2016 18:11:20 +0200 Subject: [PATCH] Fix CMakeLists.txt add_executable has only one source file // Resolve #421 --- HISTORY.rst | 2 ++ platformio/ide/projectgenerator.py | 13 ++----------- platformio/ide/tpls/clion/CMakeLists.txt.tpl | 10 ++++++++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 49d9b12f..1ba82a85 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -16,6 +16,8 @@ PlatformIO 2.0 (`issue #422 `_) * Fixed package ``shasum`` validation on Mac OS X 10.11.2 (`issue #429 `_) +* Fixed CMakeLists.txt ``add_executable`` has only one source file + (`issue #421 `_) 2.7.0 (2015-12-30) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 2c91ebc2..05ccafa2 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -91,14 +91,6 @@ 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) @@ -132,9 +124,9 @@ class ProjectGenerator(object): 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": + if (not any([f.endswith((".c", ".cpp")) for f in src_files]) 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 " @@ -147,7 +139,6 @@ class ProjectGenerator(object): self._tplvars.update({ "project_name": self.get_project_name(), "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/CMakeLists.txt.tpl b/platformio/ide/tpls/clion/CMakeLists.txt.tpl index ddcb7eb8..8704357a 100644 --- a/platformio/ide/tpls/clion/CMakeLists.txt.tpl +++ b/platformio/ide/tpls/clion/CMakeLists.txt.tpl @@ -38,8 +38,14 @@ add_custom_target( WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) -% if main_src_file: -add_executable({{project_name}} {{main_src_file.replace("\\", "/")}}) +% if src_files and any([f.endswith((".c", ".cpp")) for f in src_files]): +add_executable({{project_name}} +% for f in src_files: +% if f.endswith((".c", ".cpp")): + {{f.replace("\\", "/")}} +% end +% end +) % else: # # To enable code auto-completion, please specify path