@@ -60,49 +60,25 @@ local function get_cmake_opts(path)
60
60
local options = {}
61
61
62
62
local file = io.open (path , " r" )
63
-
64
63
if file then
65
- local in_command = false
66
-
67
- for line in file :lines () do
68
- -- Parse 'add_executable' commands
69
- local target = line :match (" ^%s*add_executable%s*%(" )
70
- if target then
71
- in_command = true
72
- target = line :match (" (%b())" )
73
- target = target :gsub (" [%(%)]" , " " )
74
-
75
- -- Split the target string by spaces and take the first part
76
- target = target :match (" (%S+)" )
77
-
78
- table.insert (
79
- options ,
80
- { text = " CMake " .. target , value = target , bau = " cmake" }
81
- )
82
- elseif in_command then
83
- in_command = false
84
- end
85
-
86
- -- Parse 'add_custom_target' commands
87
- local custom_target = line :match (" ^%s*add_custom_target%s*%(" )
88
- if custom_target then
89
- in_command = true
90
- custom_target = line :match (" (%b())" )
91
- custom_target = custom_target :gsub (" [%(%)]" , " " )
92
-
93
- -- Split the custom target string by spaces and take the first part
94
- custom_target = custom_target :match (" (%S+)" )
64
+ local content = file :read (" *all" )
65
+ file :close ()
95
66
96
- table.insert (
97
- options ,
98
- { text = " CMake " .. custom_target , value = custom_target , bau = " cmake" }
99
- )
100
- elseif in_command then
101
- in_command = false
102
- end
67
+ -- Parse add_executable entries
68
+ for target in content :gmatch (" add_executable%s*%(%s*([%w_]+)" ) do
69
+ table.insert (
70
+ options ,
71
+ { text = " CMake " .. target , value = target , bau = " cmake" }
72
+ )
103
73
end
104
74
105
- file :close ()
75
+ -- Parse add_custom_target entries
76
+ for target in content :gmatch (" add_custom_target%s*%(%s*([%w_]+)" ) do
77
+ table.insert (
78
+ options ,
79
+ { text = " CMake " .. target , value = target , bau = " cmake" }
80
+ )
81
+ end
106
82
end
107
83
108
84
return options
0 commit comments