rpav / cmake-build.el

CMake building with multiple targets, run configurations, and interactive menu
GNU General Public License v3.0
14 stars 4 forks source link

Feature request: out of source build dir and git branch tag #3

Closed dlyr closed 4 years ago

dlyr commented 4 years ago

I usually set my build directory on another hard drive (ssd) I do not figure out how to do that with cmake-build.el any idea ? Also I want to add the current git branch name to the build dir (like the release type), maybe this feature is not used by alot of people, but I work on project where I had to switch and build different git branches frequently. I'm not sure on how to add theses features, but I can take some time to try it if PR are welcome and if I had some hints on how to go in the right direction.

rpav commented 4 years ago

Nothing like people using something with varied usage patterns for finding rough spots. :)

I was going to say this should be easy to add, and give a few steps you could use for a PR, but it would have taken about as long to explain as just do it, so I did.

But fear not, you still have work to do. :wink: I only wrote the facility for custom build dir naming, you will still have to write a function to do so and incorporate your tags etc. See this README section for how the function should look. You should be able to set your function with customize or setq.

I did a fairly cursory test of alternate build roots, but I didn't test in Windows with drive letters or anything particularly unusual. If there are any issues, let me know of course (a PR fixing them would be great too...).

dlyr commented 4 years ago

Thanks for your quick update. The custom build dir name function works well. But the out of source build dir doesn't. It's not working for me, so I hope I do things well. I think the bug comes from the fact that cmake-build-clear-cache-and-configure set (default-directory (cmake-build--get-build-dir)) and if this directory is not a subdir of project-root, subsequent calls to projectile-project-root falls to identify the current project root I have a workaround, but I don't think it works with multiple opened project. It's to set the cmake-build-project-root to (cmake-build--project-root) before changing directory, i.e. around line 380

(defun cmake-build-clear-cache-and-configure ()
  (interactive)
  (unless (file-exists-p (cmake-build--get-build-dir))
    (make-directory (cmake-build--get-build-dir)))
  (let* ((cmake-build-project-root (cmake-build--project-root))
     (default-directory (cmake-build--get-build-dir))
         (buffer-name (cmake-build--build-buffer-name))

Another way is to have a map of project-key / project-dir as found in cmake-ide but it can creates huge modifications.

Another option might be to call cmake with -S and -B options, so no need to change directory. I'm trying currently but still not working.

dlyr commented 4 years ago

Check this branch https://github.com/dlyr/cmake-build.el/tree/cmake-explicit-build-dir I'm clearly not sure it's the right way todo ...

rpav commented 4 years ago

Whoops, I added a macro for this but forgot to apply it to this (and some others). Apparently it worked while testing because I had forced the project root, since it's annoying to switch windows while editing the elisp. ;)

rpav commented 4 years ago

(Let me know if the above commit doesn't fix it, or if I missed anything else.)

dlyr commented 4 years ago

Works perfectly ! FYI I use

(defun my-dir-name-function (project-root profile)
  "Return the directory name to run CMake in."
  (replace-regexp-in-string "[-/= ]" "_"  (concat (expand-file-name project-root)
                          (if (fboundp 'magit-get-current-branch) (magit-get-current-branch) "")
                          "."
                                                  profile))
  )

(setq cmake-build-dir-name-function 'my-dir-name-function)

With an external build pool. I do not see in the README where cmake-build-dir-name-functionbut I figured it out pretty well. Next things (I hope I can do it) is to work on the split window function (sometimes emacs hasn't sufficient space to split) and also on the mode of the compilation buffer so that search error works (it may be a pb on my side)/