Skip to content

Commit b556f1d

Browse files
committed
Add new files directly to CMakeLists.txt (#2132)
Adds two new commands that scan the Code Model and CMakeLists.txt for command invocations that add source files to targets or certain variables. * cmake.addFileToCMakeLists: Present the user with options for which command invocation to modify, and then edit that command invocation to add a new source file to its arguments. * cmake.removeFileFromCMakeLists: Edit any command invocations that include a source file, removing it from their argument lists. These commands can optionally be triggered when a source file is created or deleted. Quick Pick items for targets and invocations are carefully sorted to make the first option very likely to be the desired one, and settings exist to automatically choose the best option rather than asking.
1 parent c87888b commit b556f1d

File tree

3 files changed

+1578
-0
lines changed

3 files changed

+1578
-0
lines changed

package.json

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,16 @@
708708
"title": "%cmake-tools.command.cmake.quickStart.title%",
709709
"category": "CMake"
710710
},
711+
{
712+
"command": "cmake.addFileToCMakeLists",
713+
"title": "Add File to CMake Lists",
714+
"category": "CMake"
715+
},
716+
{
717+
"command": "cmake.removeFileFromCMakeLists",
718+
"title": "Remove File from CMake Lists",
719+
"category": "CMake"
720+
},
711721
{
712722
"command": "cmake.debugTarget",
713723
"title": "%cmake-tools.command.cmake.debugTarget.title%",
@@ -3672,6 +3682,150 @@
36723682
"default": false,
36733683
"description": "%cmake-tools.configuration.cmake.useFolderPropertyInBuildTargetDropdown.description%",
36743684
"scope": "resource"
3685+
},
3686+
"cmake.modifyLists.addNewSourceFiles": {
3687+
"type": "string",
3688+
"default": "yes",
3689+
"enum": [
3690+
"no",
3691+
"yes",
3692+
"ask"
3693+
],
3694+
"description": "Add source files to CMake lists when they are created.",
3695+
"enumDescriptions": [
3696+
"Do not automatically add source files to CMake lists",
3697+
"Automatically add source files to CMake lists",
3698+
"Show a preview panel of proposed changes to apply"
3699+
],
3700+
"order": 100,
3701+
"scope": "resource"
3702+
},
3703+
"cmake.modifyLists.removeDeletedSourceFiles": {
3704+
"type": "string",
3705+
"default": "yes",
3706+
"enum": [
3707+
"no",
3708+
"yes",
3709+
"ask"
3710+
],
3711+
"description": "Remove source files from CMake lists when they are deleted.",
3712+
"enumDescriptions": [
3713+
"Do not automatically remove source files from CMake lists",
3714+
"Automatically remove source files from CMake lists",
3715+
"Show a preview panel of proposed changes to apply"
3716+
],
3717+
"order": 101,
3718+
"scope": "resource"
3719+
},
3720+
"cmake.modifyLists.variableSelection": {
3721+
"type": "string",
3722+
"enum": [
3723+
"never",
3724+
"auto",
3725+
"askFirstParentDir",
3726+
"askParentDirs"
3727+
],
3728+
"default": "never",
3729+
"markdownDescription": "How to choose which `set()` or `list(APPEND/PREPEND/INSERT)` command invocation to edit when adding source files to CMake lists.",
3730+
"markdownEnumDescriptions": [
3731+
"Do not look for variable modification command invocations, only look for source command invocations.",
3732+
"Choose the best candidate automatically.",
3733+
"Present a Quick Pick with options from the first `CMakeLists.txt` found when searching up from the location of the new source file.",
3734+
"Present a Quick Pick with options from all `CMakeLists.txt` files found when searching up from the location of the new source file."
3735+
],
3736+
"order": 102,
3737+
"scope": "resource"
3738+
},
3739+
"cmake.modifyLists.sourceVariables": {
3740+
"type": "array",
3741+
"items": {
3742+
"type": "string"
3743+
},
3744+
"default": [
3745+
"SRC",
3746+
"SRCS",
3747+
"SOURCES",
3748+
"SOURCE_FILES",
3749+
"*_SRC",
3750+
"*_SRCS",
3751+
"*_SOURCES",
3752+
"*_SOURCE_FILES"
3753+
],
3754+
"markdownDescription": "Variables to add source files to. Variables appearing earlier in this list will be given higher priority. Only used if `#cmake.modifyLists.variableSelection#` is not `never`. Supports glob patterns.",
3755+
"order": 103,
3756+
"scope": "resource"
3757+
},
3758+
"cmake.modifyLists.targetSelection": {
3759+
"type": "string",
3760+
"enum": [
3761+
"auto",
3762+
"askNearestSourceDir",
3763+
"askParentSourceDirs"
3764+
],
3765+
"default": "askParentSourceDirs",
3766+
"description": "How to choose which target to add new source files to when adding source files to CMake lists.",
3767+
"enumDescriptions": [
3768+
"Choose the best candidate automatically.",
3769+
"Present a Quick Pick with targets whose source directories are closest to location of the new source file.",
3770+
"Present a Quick Pick with targets whose source directories contain the location of the new source file."
3771+
],
3772+
"order": 104,
3773+
"scope": "resource"
3774+
},
3775+
"cmake.modifyLists.targetCommandInvocationSelection": {
3776+
"type": "string",
3777+
"enum": [
3778+
"auto",
3779+
"askFirstParentDir",
3780+
"askParentDirs"
3781+
],
3782+
"default": "askParentDirs",
3783+
"description": "How to choose which of a target's source command invocations to edit when adding source files to CMake lists.",
3784+
"enumDescriptions": [
3785+
"Choose the best candidate automatically.",
3786+
"Present a Quick Pick with options from the CMake list file in the parent directory closest to the location of the new source file.",
3787+
"Present a Quick Pick with options from all CMake list files in the parent directories of the new source file."
3788+
],
3789+
"order": 105,
3790+
"scope": "resource"
3791+
},
3792+
"cmake.modifyLists.targetSourceCommands": {
3793+
"type": "array",
3794+
"items": {
3795+
"type": "string"
3796+
},
3797+
"default": [
3798+
"target_sources",
3799+
"add_executable",
3800+
"add_library"
3801+
],
3802+
"markdownDescription": "Commands to treat as target source commands when adding source files CMake lists. Commands appearing earlier in this list will be given higher priority. Supports glob patterns.\n\nIf you are using the File API (see `#cmake.cmakeCommunicationMode#`), user-defined functions and macros which call the commands in this list are detected automatically and added to it.",
3803+
"order": 106,
3804+
"scope": "resource"
3805+
},
3806+
"cmake.modifyLists.scopeSelection": {
3807+
"type": "string",
3808+
"enum": [
3809+
"auto",
3810+
"ask"
3811+
],
3812+
"default": "ask",
3813+
"description": "How to choose which of a target's visibility scopes, file sets, or source keyword parameters to edit when adding source files to CMake lists.",
3814+
"enumDescriptions": [
3815+
"Choose the best candidate automatically.",
3816+
"Present a Quick Pick with options from the selected target source command invocation."
3817+
],
3818+
"order": 107,
3819+
"scope": "resource"
3820+
},
3821+
"cmake.modifyLists.sourceListKeywords": {
3822+
"type": "array",
3823+
"items": {
3824+
"type": "string"
3825+
},
3826+
"markdownDescription": "Keyword arguments to user-defined functions and macros which introduce lists of source files. If left empty, all arguments consisting of only upper-case letters and underscores will be considered. Supports glob patterns",
3827+
"order": 108,
3828+
"scope": "resource"
36753829
}
36763830
}
36773831
},

0 commit comments

Comments
 (0)