From 1c8666e946e60896f6e809847a24b69934b67cff Mon Sep 17 00:00:00 2001 From: Teo-CD <32749416+Teo-CD@users.noreply.github.com> Date: Thu, 29 Aug 2019 21:01:50 +0900 Subject: [PATCH] Clion integration, resolves #2824 (#2944) * Better environement integration : - Environement can be selected in the build target menu of CLion - Platformio target runs on the selected environment - Changing environment changes defined preprocessor variables and includes accordingly - Added 'All' build profile that runs targets on all environment if there are multiple of them (Original behaviour) * Calling get_project_dir() only once. * Fixed include path not being converted to unix style. Removed duplicate and not normalized definition --- .../ide/tpls/clion/.idea/workspace.xml.tpl | 16 +++++++++--- platformio/ide/tpls/clion/CMakeLists.txt.tpl | 16 ++++++------ .../ide/tpls/clion/CMakeListsPrivate.txt.tpl | 26 ++++++++++++++----- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/platformio/ide/tpls/clion/.idea/workspace.xml.tpl b/platformio/ide/tpls/clion/.idea/workspace.xml.tpl index 8cf4214f..d50b1de3 100644 --- a/platformio/ide/tpls/clion/.idea/workspace.xml.tpl +++ b/platformio/ide/tpls/clion/.idea/workspace.xml.tpl @@ -15,10 +15,18 @@ - - - - + + +% envs = config.envs() +% if len(envs) > 1: +% for env in envs: + +% end + +% else: + +% end + diff --git a/platformio/ide/tpls/clion/CMakeLists.txt.tpl b/platformio/ide/tpls/clion/CMakeLists.txt.tpl index 4680f6b4..08e69681 100644 --- a/platformio/ide/tpls/clion/CMakeLists.txt.tpl +++ b/platformio/ide/tpls/clion/CMakeLists.txt.tpl @@ -16,49 +16,49 @@ endif() add_custom_target( PLATFORMIO_BUILD ALL - COMMAND ${PLATFORMIO_CMD} -f -c clion run + COMMAND ${PLATFORMIO_CMD} -f -c clion run "$<$>:-e${CMAKE_BUILD_TYPE}>" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target( PLATFORMIO_BUILD_VERBOSE ALL - COMMAND ${PLATFORMIO_CMD} -f -c clion run --verbose + COMMAND ${PLATFORMIO_CMD} -f -c clion run --verbose "$<$>:-e${CMAKE_BUILD_TYPE}>" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target( PLATFORMIO_UPLOAD ALL - COMMAND ${PLATFORMIO_CMD} -f -c clion run --target upload + COMMAND ${PLATFORMIO_CMD} -f -c clion run --target upload "$<$>:-e${CMAKE_BUILD_TYPE}>" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target( PLATFORMIO_CLEAN ALL - COMMAND ${PLATFORMIO_CMD} -f -c clion run --target clean + COMMAND ${PLATFORMIO_CMD} -f -c clion run --target clean "$<$>:-e${CMAKE_BUILD_TYPE}>" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target( PLATFORMIO_MONITOR ALL - COMMAND ${PLATFORMIO_CMD} -f -c clion device monitor + COMMAND ${PLATFORMIO_CMD} -f -c clion device monitor "$<$>:-e${CMAKE_BUILD_TYPE}>" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target( PLATFORMIO_TEST ALL - COMMAND ${PLATFORMIO_CMD} -f -c clion test + COMMAND ${PLATFORMIO_CMD} -f -c clion test "$<$>:-e${CMAKE_BUILD_TYPE}>" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target( PLATFORMIO_PROGRAM ALL - COMMAND ${PLATFORMIO_CMD} -f -c clion run --target program + COMMAND ${PLATFORMIO_CMD} -f -c clion run --target program "$<$>:-e${CMAKE_BUILD_TYPE}>" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) add_custom_target( PLATFORMIO_UPLOADFS ALL - COMMAND ${PLATFORMIO_CMD} -f -c clion run --target uploadfs + COMMAND ${PLATFORMIO_CMD} -f -c clion run --target uploadfs "$<$>:-e${CMAKE_BUILD_TYPE}>" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl b/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl index 5d69c4d8..81d32c13 100644 --- a/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl +++ b/platformio/ide/tpls/clion/CMakeListsPrivate.txt.tpl @@ -5,6 +5,8 @@ # please create `CMakeListsUser.txt` in the root of project. # The `CMakeListsUser.txt` will not be overwritten by PlatformIO. +%from platformio.project.helpers import (load_project_ide_data) +% % import re % % def _normalize_path(path): @@ -19,6 +21,14 @@ % end % return path % end +% +% envs = config.envs() + +% if len(envs) > 1: +set(CMAKE_CONFIGURATION_TYPES "{{ ";".join(envs) }}" CACHE STRING "" FORCE) +% else: +set(CMAKE_CONFIGURATION_TYPES "{{ env_name }}" CACHE STRING "" FORCE) +% end set(PLATFORMIO_CMD "{{ _normalize_path(platformio_path) }}") @@ -37,12 +47,16 @@ SET(CMAKE_C_STANDARD {{ cc_stds[-1] }}) set(CMAKE_CXX_STANDARD {{ cxx_stds[-1] }}) % end -% for define in defines: -add_definitions(-D'{{!re.sub(r"([\"\(\)#])", r"\\\1", define)}}') -% end +% for env in envs: +if (CMAKE_BUILD_TYPE MATCHES {{ env }}) +% items = load_project_ide_data(project_dir,env) +% for define in items["defines"]: + add_definitions(-D'{{!re.sub(r"([\"\(\)#])", r"\\\1", define)}}') +% end -% for include in includes: -include_directories("{{ _normalize_path(include) }}") +% for include in items["includes"]: + include_directories("{{ _normalize_path(to_unix_path(include)) }}") +% end +endif() % end - FILE(GLOB_RECURSE SRC_LIST "{{ _normalize_path(project_src_dir) }}/*.*" "{{ _normalize_path(project_lib_dir) }}/*.*" "{{ _normalize_path(project_libdeps_dir) }}/*.*")