Skip to content

Commit

Permalink
Added option to generate VSCode debug conf
Browse files Browse the repository at this point in the history
  • Loading branch information
awillecke committed Aug 7, 2023
1 parent cc0062d commit 36b19fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ add_subdirectory(src/traci)

add_subdirectory(src/artery)

option(VSCODE_LAUNCH_INTEGRATION "Generate VS Code configuration for debugging Artery (requires debug build)" OFF)

# scenarios directory is part of repository but omitted for Docker build context
if(EXISTS ${PROJECT_SOURCE_DIR}/scenarios)
add_subdirectory(scenarios)
Expand Down
8 changes: 4 additions & 4 deletions cmake/AddVSCode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function(generate_vscode)
file(READ ${args_FILE} current_launch_json)

string(JSON num_configs LENGTH ${current_launch_json} "configurations")
message("-- Found ${num_configs} VS Code Config(s) in .vscode/launch.json")
message(STATUS "Found ${num_configs} VS Code Config(s) in .vscode/launch.json")
math(EXPR last_config "${num_configs} - 1")

# read recent build configuration from temporary launch configuraiton
Expand All @@ -62,7 +62,7 @@ function(generate_vscode)

# found Arterys default debug configuration
if (${config_name} STREQUAL ${default_launch_configuration_name})
message("-- Updating Artery default config in .vscode/launch.json")
message(STATUS "Updating Artery default config in .vscode/launch.json")
set(default_config_found true)

# replace old config with newly generated one and save
Expand All @@ -73,7 +73,7 @@ function(generate_vscode)

# launch.json is present but no default configuration was found
if (NOT ${default_config_found})
message("-- Append Artery default config to .vscode/launch.json")
message(STATUS "Append Artery default config to .vscode/launch.json")

# append default configuration
string(JSON current_launch_configuration SET ${current_launch_json} "configurations" ${num_configs} ${default_launch_configuration})
Expand All @@ -92,7 +92,7 @@ function(generate_vscode)
file(WRITE ${args_FILE} ${current_launch_configuration})
endif()
else()
message("-- Generating default debug config for VS Code")
message(STATUS "Generating default debug config for VS Code")
# substitute variables first, then generator expressions
file(GENERATE OUTPUT ${args_FILE} INPUT ${PROJECT_BINARY_DIR}/launch.json.default)
endif()
Expand Down
6 changes: 5 additions & 1 deletion src/artery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ if(NOT is_multi_config)
install(
PROGRAMS ${PROJECT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/run_artery.sh.install
DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME run_artery.sh)
endif()

if(NOT CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
if(VSCODE_LAUNCH_INTEGRATION)
if (NOT CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
generate_vscode(TARGET artery FILE ${PROJECT_SOURCE_DIR}/.vscode/launch.json)
else()
message(STATUS "VS Code integration is enabled, but built type is Release")
endif()
endif()

0 comments on commit 36b19fa

Please sign in to comment.