Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake modules to generate VSCode Launch and Settings files #11

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ output/
build_log.txt

# VScode settings
.vscode/*cortex-debug*
.vscode/settings.json
.vscode/*_properties.json
.vscode/launch.json
.vscode/

*.jlink
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ set(DEBUG_TOOLSET "PYOCD")
# THIS OPTION IS ONLY SUPPORTED WITH THE JLINK TOOLSET
set(ENABLE_SEGGER_RTT false)

set(DEBUG_INTERFACE "swd")
# set(DEBUG_INTERFACE "jtag")

# MCU Target name as seen in debug toolset
set(MCU_TARGET LPC5526)

Expand Down Expand Up @@ -74,7 +77,7 @@ project(${PROJECT_NAME} VERSION 1.0 LANGUAGES C)

# Set the C standard and executable suffix
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD 99)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why C 99 instead of C 2011 or C 2018?

Copy link
Contributor Author

@stephendpmurphy stephendpmurphy Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukewelchGB Current flags (flags.cmake) are using -std=gnu99 so setting CMake to be in parity.

set(CMAKE_C_STANDARD_REQUIRED ON)

# Set our executable output path to the 'output/' folder
Expand Down Expand Up @@ -162,4 +165,7 @@ add_custom_target(erase ${DEBUG_ERASE_CMD})
add_custom_target(flash ${DEBUG_FLASH_CMD})

# Add a makefile "target" for running unit tests
add_custom_target(test cd ../ && ceedling gcov:all utils:gcov)
add_custom_target(test cd ../ && ceedling gcov:all utils:gcov)

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/vscode_debug.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/vscode_intellisense.cmake)
46 changes: 1 addition & 45 deletions cmake/debug_jlink.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,4 @@ loadfile ${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE_NAME}.hex
r
g
exit"
)

write_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json
{\n
\t\"version\": \"0.2.0\",\n
\t\"configurations\": [\n
\t{\n
\t\t\"name\": \"${MCU_TARGET}\",\n
\t\t\"type\": \"cortex-debug\",\n
\t\t\"request\": \"launch\",\n
\t\t\"servertype\":\"jlink\",\n
\t\t\"cwd\": \"${workspaceRoot}\",\n
\t\t\"executable\": \"${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE_NAME}.elf\",\n
\t\t\"device\": \"${MCU_TARGET}\",\n
\t\t\"runToMain\": true,\n
\t\t\"v1\": false,\n
\t\t\"serverArgs\": [\n
\t\t\t\"--target\",\n
\t\t\t\"${MCU_TARGET}\"\n
\t\t],
)

if(${ENABLE_SEGGER_RTT})

write_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json
\t\t"rttConfig":{\n
\t\t\t"enabled":true,\n
\t\t\t"address":"auto",\n
\t\t\t"decoders":[{\n
\t\t\t\t"port":0,\n
\t\t\t\t"type":"console"\n
\t\t\t}]\n
\t\t}\n
\t}]\n
}
APPEND)

else()

write_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json
\t}]\n
}
APPEND)

endif()
)
23 changes: 1 addition & 22 deletions cmake/debug_pyocd.cmake
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
set(DEBUG_ERASE_CMD "pyocd" "erase" "-t${MCU_TARGET}" "--chip")
set(DEBUG_FLASH_CMD "pyocd" "flash" "-t${MCU_TARGET}" "-f20000khz" "${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE_NAME}.elf")

write_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json
{\n
\t\"version\": \"0.2.0\",\n
\t\"configurations\": [\n
\t{\n
\t\t\"name\": \"${MCU_TARGET}\",\n
\t\t\"type\": \"cortex-debug\",\n
\t\t\"request\": \"launch\",\n
\t\t\"servertype\":\"pyocd\",\n
\t\t\"cwd\": \"${workspaceRoot}\",\n
\t\t\"executable\": \"${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE_NAME}.elf\",\n
\t\t\"device\": \"${MCU_TARGET}\",\n
\t\t\"runToMain\": true,\n
\t\t\"v1\": false,\n
\t\t\"serverArgs\": [\n
\t\t\t\"--target\",\n
\t\t\t\"${MCU_TARGET}\"\n
\t\t]\n
\t}]\n
})
set(DEBUG_FLASH_CMD "pyocd" "flash" "-t${MCU_TARGET}" "-f20000khz" "${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE_NAME}.elf")
46 changes: 46 additions & 0 deletions cmake/vscode_debug.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Make sure to create the .vscode directory if it doesn't exist
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.vscode)

string(TOLOWER ${DEBUG_TOOLSET} DEBUG_SERVER_TYPE)

# Specify the template for the c_cpp_properties.json file
write_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json
"{
\"version\":\"0.2.0\",
\"configurations\":[
{
\"name\":\"${DEBUG_TOOLSET}\",
\"type\":\"cortex-debug\",
\"request\":\"launch\",
\"servertype\":\"${DEBUG_SERVER_TYPE}\",
\"cwd\":\"\",
\"executable\":\"${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE_NAME}.elf\",
\"device\":\"${MCU_TARGET}\",
\"interface\": \"${DEBUG_INTERFACE}\",
\"v1\":false,
\"serverArgs\":[
\"--nogui\"
],"
)

if(${ENABLE_SEGGER_RTT} AND (${DEBUG_SERVER_TYPE} STREQUAL "jlink"))

write_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json
" \"rttConfig\":{
\"enabled\":true,
\"address\":\"auto\",
\"decoders\":[{
\"port\":0,
\"type\":\"console\"
}]
}
}]
}" APPEND)

else()

write_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/launch.json
" }]
}" APPEND)

endif()
32 changes: 32 additions & 0 deletions cmake/vscode_intellisense.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Make sure to create the .vscode directory if it doesn't exist
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.vscode)

# Note, if a seperate include variable is used for SDK includes you would append it here
set(INTELLISENSE_INCLDUES ${INCLUDE_DIRS})

# Generate the list of include directories as a JSON array
set(INCLUDE_DIRS_JSON "")
foreach(INCLUDE_DIR ${INTELLISENSE_INCLDUES})
list(APPEND INCLUDE_DIRS_JSON "\"${INCLUDE_DIR}\"")
endforeach()
string(JOIN ",\n" INCLUDE_DIRS_JSON ${INCLUDE_DIRS_JSON})

# Specify the template for the c_cpp_properties.json file
write_file(${CMAKE_CURRENT_SOURCE_DIR}/.vscode/c_cpp_properties.json
"{
\"configurations\": [
{
\"name\": \"${CMAKE_BUILD_TYPE}\",
\"includePath\": [
${INCLUDE_DIRS_JSON}
],
\"compileCommands\": \"\$\{workspaceFolder\}/build/compile_command.json\",
\"defines\": [\"\"],
\"compilerPath\": \"${CMAKE_C_COMPILER}\",
\"cStandard\": \"c99\",
\"cppStandard\": \"c++17\",
\"intelliSenseMode\": \"gcc-arm\"
stephendpmurphy marked this conversation as resolved.
Show resolved Hide resolved
}
],
\"version\": 1
}")