I was able to implement the logic of building, running and debugging a C++ project by passing the appropriate target functions configured in Cmake, but is there any way I can make the available targets display from Cmake? So I don't have to navigate through CmakeLists looking for the right target, but select it from the hint in the minibuffer, like with C-f?
(use-package projectile
:config
(projectile-mode +1))
(defun compile-project (target)
(interactive "MEnter target name: ")
(let ((build-dir (concat (projectile-project-root) "build/"))
(compile-command (concat "cd " (projectile-project-root) " && cmake --build build --target " target)))
(compile compile-command)))
(defun build-and-run-project (target)
(interactive "MEnter target name: ")
(compile-project target)
(let ((build-dir (concat (projectile-project-root) "build/"))
(compile-command (concat "cd " (projectile-project-root) " && cmake --build build --target " target " && " (projectile-project-root) "build/" target)))
(compile compile-command)
(async-shell-command (concat (projectile-project-root) "build/" target))))
(defun build-and-debug-project (target)
(interactive "MEnter target name: ")
(compile-project target)
(let ((build-dir (concat (projectile-project-root) "build/"))
(compile-command (concat "cd " (projectile-project-root) " && cmake --build build --target " target)))
(compile compile-command)
(gdb (concat "gdb -i=mi " (concat (projectile-project-root) "build/" target)))))
(global-set-key (kbd "<f5>") 'build-and-run-project)
(global-set-key (kbd "<f6>") 'build-and-debug-project)
(global-set-key (kbd "<f7>") 'compile-project)