2121
2222namespace vix ::commands::modules_cmd::commands
2323{
24-
2524 namespace fs = std::filesystem;
2625 namespace cnt = vix::commands::modules_cmd::content;
2726 namespace utils = vix::commands::modules_cmd::utils;
@@ -90,10 +89,31 @@ namespace vix::commands::modules_cmd::commands
9089 return false ;
9190 }
9291
93- if (patchRoot && !cnt::patch_root_cmakelists_include (root))
92+ const bool hasRootCMake =
93+ utils::exists_file (root / " CMakeLists.txt" );
94+
95+ const bool hasVixApp =
96+ utils::exists_file (root / " vix.app" );
97+
98+ if (patchRoot && hasRootCMake)
9499 {
95- ui::err_line (std::cout, " Failed to patch root CMakeLists.txt." );
96- return false ;
100+ if (!cnt::patch_root_cmakelists_include (root))
101+ {
102+ ui::err_line (std::cout, " Failed to patch root CMakeLists.txt." );
103+ return false ;
104+ }
105+ }
106+ else if (patchRoot && hasVixApp)
107+ {
108+ ui::warn_line (
109+ std::cout,
110+ " vix.app project detected. CMake patch skipped." );
111+ }
112+ else if (patchRoot)
113+ {
114+ ui::warn_line (
115+ std::cout,
116+ " CMakeLists.txt not found. Skipping root patch." );
97117 }
98118
99119 print_modules_banner (" modules" , " initialized" );
@@ -103,8 +123,10 @@ namespace vix::commands::modules_cmd::commands
103123 print_command_step (1 , " modules/" , " module directory" );
104124 print_command_step (2 , " cmake/vix_modules.cmake" , " module loader" );
105125
106- if (patchRoot)
126+ if (patchRoot && hasRootCMake)
127+ {
107128 print_command_step (3 , " CMakeLists.txt" , " patched" );
129+ }
108130
109131 sep ();
110132 section (" next" );
@@ -187,54 +209,80 @@ namespace vix::commands::modules_cmd::commands
187209 return false ;
188210 }
189211
190- if (patchRootLink && !cnt::patch_root_cmakelists_link_module (root, project, module ))
212+ const bool hasRootCMake =
213+ utils::exists_file (root / " CMakeLists.txt" );
214+
215+ const bool hasVixApp =
216+ utils::exists_file (root / " vix.app" );
217+
218+ if (patchRootLink && hasRootCMake)
191219 {
192- ui::err_line (std::cout, " Failed to patch root CMakeLists.txt with module link." );
193- return false ;
220+ if (!cnt::patch_root_cmakelists_link_module (root, project, module ))
221+ {
222+ ui::err_line (std::cout, " Failed to patch root CMakeLists.txt with module link." );
223+ return false ;
224+ }
225+ }
226+ else if (patchRootLink && hasVixApp)
227+ {
228+ ui::warn_line (
229+ std::cout,
230+ " vix.app project detected. Add the module in vix.app." );
231+ }
232+ else if (patchRootLink)
233+ {
234+ ui::warn_line (
235+ std::cout,
236+ " CMakeLists.txt not found. Skipping auto-link." );
194237 }
195238
196- print_modules_banner (normalized, " module" );
239+ print_modules_banner (normalized, " module created " );
197240 sep ();
198241
199242 section (" files" );
200243 print_command_step (
201244 1 ,
202- " modules/" + normalized + " /include/" + normalized + " /api.hpp" ,
203- " public header" );
245+ " modules/" + normalized + " /" );
204246
205247 print_command_step (
206248 2 ,
207- " modules/" + normalized + " /src/" + normalized + " .cpp" ,
208- " implementation" );
249+ " modules/" + normalized + " /include/" + normalized + " /api.hpp" );
209250
210251 print_command_step (
211252 3 ,
212- " modules/" + normalized + " /CMakeLists.txt" ,
213- " target" );
214-
215- sep ();
216- section (" target" );
217- print_command_step (1 , cnt::module_alias_name (project, module ), " CMake alias" );
253+ " modules/" + normalized + " /src/" + normalized + " .cpp" );
218254
219255 sep ();
220256 section (" next" );
221- print_command_step (
222- 1 ,
223- " #include <" + normalized + " /api.hpp>" ,
224- " include" );
225257
226- if (patchRootLink )
258+ if (hasVixApp )
227259 {
228- print_command_step (2 , " vix build" , " compile" );
260+ print_command_step (
261+ 1 ,
262+ " add \" " + normalized + " \" to modules in vix.app" );
263+
264+ print_command_step (2 , " vix build" );
265+ }
266+ else if (patchRootLink && hasRootCMake)
267+ {
268+ print_command_step (
269+ 1 ,
270+ " #include <" + normalized + " /api.hpp>" );
271+
272+ print_command_step (2 , " vix build" );
229273 }
230274 else
231275 {
276+ print_command_step (
277+ 1 ,
278+ " #include <" + normalized + " /api.hpp>" );
279+
232280 print_command_step (
233281 2 ,
234- " target_link_libraries(" + project + " PRIVATE " + cnt::module_alias_name (project, module ) + " )" ,
235- " link manually" );
236- }
282+ " target_link_libraries(" + project + " PRIVATE " + cnt::module_alias_name (project, module ) + " )" );
237283
284+ print_command_step (3 , " vix build" );
285+ }
238286 return true ;
239287 }
240288
0 commit comments