From 4a6d5e8395a308158d0fe3b90cbf5b22c652ffc8 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 29 Aug 2019 16:26:51 +0300 Subject: [PATCH] Added support for multi-environment PlatformIO project for CLion IDE // Resolve #2824 Resolve #2944 --- HISTORY.rst | 3 ++- .../ide/tpls/clion/CMakeListsPrivate.txt.tpl | 24 +++++++++++++++---- platformio/project/helpers.py | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index c67378b0..8b8b8c95 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -9,8 +9,9 @@ PlatformIO 4.0 4.0.3 (2019-??-??) ~~~~~~~~~~~~~~~~~~ -* Support `PLATFORMIO_DISABLE_COLOR `__ system environment variable which disables color ANSI-codes in a terminal output (`issue #2956 `_) +* Added support for multi-environment PlatformIO project for `CLion IDE `__ (`issue #2824 `_) * Generate ``.ccls`` LSP file for `Vim `__ cross references, hierarchies, completion and semantic highlighting (`issue #2952 `_) +* Added support for `PLATFORMIO_DISABLE_COLOR `__ system environment variable which disables color ANSI-codes in a terminal output (`issue #2956 `_) * Updated SCons tool to 3.1.1 * Remove ProjectConfig cache when "platformio.ini" was modified outside * Fixed an issue with PIO Unified Debugger on Windows OS when debug server is piped diff --git a/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl b/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl index 81d32c13..680a79a9 100644 --- a/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl +++ b/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl @@ -47,14 +47,30 @@ SET(CMAKE_C_STANDARD {{ cc_stds[-1] }}) set(CMAKE_CXX_STANDARD {{ cxx_stds[-1] }}) % end -% for env in envs: +if (CMAKE_BUILD_TYPE MATCHES {{ env_name }}) +%for define in defines: + add_definitions(-D'{{!re.sub(r"([\"\(\)#])", r"\\\1", define)}}') +%end + +%for include in includes: + include_directories("{{ _normalize_path(to_unix_path(include)) }}") +%end +endif() + +% leftover_envs = set(envs) ^ set([env_name]) +% +% if leftover_envs: +% ide_data = load_project_ide_data(project_dir, leftover_envs) +% end +% +% for env in leftover_envs: if (CMAKE_BUILD_TYPE MATCHES {{ env }}) -% items = load_project_ide_data(project_dir,env) -% for define in items["defines"]: +% data = ide_data[env] +% for define in data["defines"]: add_definitions(-D'{{!re.sub(r"([\"\(\)#])", r"\\\1", define)}}') % end -% for include in items["includes"]: +% for include in data["includes"]: include_directories("{{ _normalize_path(to_unix_path(include)) }}") % end endif() diff --git a/platformio/project/helpers.py b/platformio/project/helpers.py index 166ef420..7ead95eb 100644 --- a/platformio/project/helpers.py +++ b/platformio/project/helpers.py @@ -197,7 +197,7 @@ def compute_project_checksum(config): def load_project_ide_data(project_dir, envs): from platformio.commands.run import cli as cmd_run assert envs - if not isinstance(envs, (list, tuple)): + if not isinstance(envs, (list, tuple, set)): envs = [envs] args = ["--project-dir", project_dir, "--target", "idedata"] for env in envs: