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
This commit is contained in:
Teo-CD
2019-08-29 21:01:50 +09:00
committed by Ivan Kravets
parent 0440b7a2f7
commit 1c8666e946
3 changed files with 40 additions and 18 deletions

View File

@@ -15,10 +15,18 @@
<config projectName="{{project_name}}" targetName="DEBUG" /> <config projectName="{{project_name}}" targetName="DEBUG" />
</generated> </generated>
</component> </component>
<component name="CMakeSettings" AUTO_RELOAD="true" GENERATION_PASS_SYSTEM_ENVIRONMENT="true"> <component name="CMakeSettings" AUTO_RELOAD="true">
<ADDITIONAL_GENERATION_ENVIRONMENT> <configurations>
<envs /> % envs = config.envs()
</ADDITIONAL_GENERATION_ENVIRONMENT> % if len(envs) > 1:
% for env in envs:
<configuration PROFILE_NAME="{{ env }}" CONFIG_NAME="{{ env }}" />
% end
<configuration PROFILE_NAME="All" CONFIG_NAME="All" />
% else:
<configuration PROFILE_NAME="{{ env_name }}" CONFIG_NAME="{{ env_name }}" />
% end
</configurations>
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="ec922180-b3d3-40f1-af0b-2568113a9075" name="Default" comment="" /> <list default="true" id="ec922180-b3d3-40f1-af0b-2568113a9075" name="Default" comment="" />

View File

@@ -16,49 +16,49 @@ endif()
add_custom_target( add_custom_target(
PLATFORMIO_BUILD ALL PLATFORMIO_BUILD ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion run COMMAND ${PLATFORMIO_CMD} -f -c clion run "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )
add_custom_target( add_custom_target(
PLATFORMIO_BUILD_VERBOSE ALL PLATFORMIO_BUILD_VERBOSE ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion run --verbose COMMAND ${PLATFORMIO_CMD} -f -c clion run --verbose "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )
add_custom_target( add_custom_target(
PLATFORMIO_UPLOAD ALL PLATFORMIO_UPLOAD ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion run --target upload COMMAND ${PLATFORMIO_CMD} -f -c clion run --target upload "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )
add_custom_target( add_custom_target(
PLATFORMIO_CLEAN ALL PLATFORMIO_CLEAN ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion run --target clean COMMAND ${PLATFORMIO_CMD} -f -c clion run --target clean "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )
add_custom_target( add_custom_target(
PLATFORMIO_MONITOR ALL PLATFORMIO_MONITOR ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion device monitor COMMAND ${PLATFORMIO_CMD} -f -c clion device monitor "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )
add_custom_target( add_custom_target(
PLATFORMIO_TEST ALL PLATFORMIO_TEST ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion test COMMAND ${PLATFORMIO_CMD} -f -c clion test "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )
add_custom_target( add_custom_target(
PLATFORMIO_PROGRAM ALL PLATFORMIO_PROGRAM ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion run --target program COMMAND ${PLATFORMIO_CMD} -f -c clion run --target program "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )
add_custom_target( add_custom_target(
PLATFORMIO_UPLOADFS ALL PLATFORMIO_UPLOADFS ALL
COMMAND ${PLATFORMIO_CMD} -f -c clion run --target uploadfs COMMAND ${PLATFORMIO_CMD} -f -c clion run --target uploadfs "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )

View File

@@ -5,6 +5,8 @@
# please create `CMakeListsUser.txt` in the root of project. # please create `CMakeListsUser.txt` in the root of project.
# The `CMakeListsUser.txt` will not be overwritten by PlatformIO. # The `CMakeListsUser.txt` will not be overwritten by PlatformIO.
%from platformio.project.helpers import (load_project_ide_data)
%
% import re % import re
% %
% def _normalize_path(path): % def _normalize_path(path):
@@ -19,6 +21,14 @@
% end % end
% return path % return path
% end % 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) }}") 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] }}) set(CMAKE_CXX_STANDARD {{ cxx_stds[-1] }})
% end % end
% for define in defines: % for env in envs:
add_definitions(-D'{{!re.sub(r"([\"\(\)#])", r"\\\1", define)}}') 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 % end
% for include in includes: % for include in items["includes"]:
include_directories("{{ _normalize_path(include) }}") include_directories("{{ _normalize_path(to_unix_path(include)) }}")
% end
endif()
% end % end
FILE(GLOB_RECURSE SRC_LIST "{{ _normalize_path(project_src_dir) }}/*.*" "{{ _normalize_path(project_lib_dir) }}/*.*" "{{ _normalize_path(project_libdeps_dir) }}/*.*") FILE(GLOB_RECURSE SRC_LIST "{{ _normalize_path(project_src_dir) }}/*.*" "{{ _normalize_path(project_lib_dir) }}/*.*" "{{ _normalize_path(project_libdeps_dir) }}/*.*")