atilaneves / cmake-ide

Use Emacs as a C/C++ IDE
BSD 3-Clause "New" or "Revised" License
716 stars 92 forks source link

Problem with cmake-ide-run-cmake and cmake-ide-cmake-args #190

Closed gatto73 closed 3 years ago

gatto73 commented 5 years ago

Hi. I'm starting to use cmake-ide with Spacemacs.

I put the following .dir-locals.el in my project directory:

((nil . ((cmake-ide-project-dir . "~/CppProjects/sse-cs106b/lecture12-recursive-struct")
         (cmake-ide-build-dir . "~/CppProjects/sse-cs106b/lecture12-recursive-struct/build")
         (cmake-ide-cmake-args . "-DCMAKE_BUILD_TYPE=Debug"))))

When I run cmake-ide-run-cmake I get the following Debugger backtrace:

Debugger entered--Lisp error: (wrong-type-argument stringp 45)
  make-process(:name "cmake" :buffer "*cmake*" :command ("cmake" 45 68 67 77 65 75 69 95 66 85 73 76 68 95 84 89 80 69 61 68 101 98 117 103 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" "-B" "." "-S" "/home/gatto/CppProjects/sse-cs106b/lecture12-dynamic-arrays"))
  apply(make-process (:name "cmake" :buffer "*cmake*" :command ("cmake" 45 68 67 77 65 75 69 95 66 85 73 76 68 95 84 89 80 69 61 68 101 98 117 103 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" "-B" "." "-S" "/home/gatto/CppProjects/sse-cs106b/lecture12-dynamic-arrays")))
  start-process("cmake" "*cmake*" "cmake" 45 68 67 77 65 75 69 95 66 85 73 76 68 95 84 89 80 69 61 68 101 98 117 103 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" "-B" "." "-S" "/home/gatto/CppProjects/sse-cs106b/lecture12-dynamic-arrays")
  apply(start-process ("cmake" "*cmake*" "cmake" 45 68 67 77 65 75 69 95 66 85 73 76 68 95 84 89 80 69 61 68 101 98 117 103 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" "-B" "." "-S" "/home/gatto/CppProjects/sse-cs106b/lecture12-dynamic-arrays"))
  cide--run-cmake-impl("/home/gatto/CppProjects/sse-cs106b/lecture12-dynamic-arrays" "/home/gatto/CppProjects/sse-cs106b/lecture12-dynamic-arrays/build/")
  cmake-ide-run-cmake()
  funcall-interactively(cmake-ide-run-cmake)
  call-interactively(cmake-ide-run-cmake nil nil)
  command-execute(cmake-ide-run-cmake)

The problem is that cide--cmake-args should return a list of arguments, as indicated in the docstring, that should be appended to other list of strings inside cide--run-cmake-impl:

(apply 'start-process (append (list "cmake" "*cmake*" cmake-ide-cmake-command)
                              (cide--cmake-args)
                              (list "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
                                    "-B" "." "-S" project-dir)))

But it returns the string "-DCMAKE_BUILD_TYPE=Debug".

System Info :computer:

atilaneves commented 5 years ago

Is this project open source? i.e. would I have access to the code to try an reproduce the issue?

gatto73 commented 5 years ago

I have the same problem with a simple hello-world project like the following:

gatto@xut:~/CppProjects/hello-world$ pwd
/home/gatto/CppProjects/hello-world
gatto@xut:~/CppProjects/hello-world$ tree -a
.
├── build
├── CMakeLists.txt
├── .dir-locals.el
├── main.cpp
└── .projectile

1 directory, 4 files
gatto@xut:~/CppProjects/hello-world$ cat .projectile 
gatto@xut:~/CppProjects/hello-world$ 

.dir-locals.el

((nil . ((cmake-ide-project-dir . "~/CppProjects/hello-world")
                 (cmake-ide-build-dir . "~/CppProjects/hello-world/build")
                 (cmake-ide-cmake-args . "-DCMAKE_BUILD_TYPE=Debug"))))

main.cpp

#include <iostream>
using namespace std;

int main() {
        cout << "Hello world" << endl;
        return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.10.2)
project(hello-world)

add_compile_options(-g -Wall -Wextra -pedantic -Werror)

add_executable(hello-world main.cpp)

To reproduce the problem I run cmake-ide-run-cmake from main.cpp buffer.

The content of .dir-locals.cpp is taken from Spacemacs documentation for cmake Layer, with the difference that I'm using cmake-ide-cmake-args instead of cmake-ide-cmake-opts, as suggested by the docstring of cmake-ide-cmake-opts:

cmake-ide-cmake-opts is a variable defined in ‘cmake-ide.el’.
Its value is "-DCMAKE_BUILD_TYPE=Release"

  This variable is safe as a file local variable if its value
  satisfies the predicate ‘stringp’.

Documentation:
The options passed to cmake when calling it.  DEPRECATED, use ‘cmake-ide-cmake-args’ instead.

You can customize this variable.

Actually if I use cmake-ide-cmake-opts I don't have any problem.

The issues seems in:

(defun cide--cmake-args ()
  "Return a list of arguments to pass to CMake when calling it."
(or cmake-ide-cmake-args cmake-ide-cmake-args (split-string cmake-ide-cmake-opts)))

that returns a list for cmake-ide-cmake-opts but a string for cmake-ide-cmake-args.

The code of cide--run-cmake-impl is expecting a list of string from cide--cmake-args and not a string:

(defun cide--run-cmake-impl (project-dir cmake-dir)
  "Run the CMake process for PROJECT-DIR in CMAKE-DIR."
  (when project-dir
    (let ((default-directory cmake-dir))
      (cide--message "Running cmake for src path %s in build path %s" project-dir cmake-dir)
      (apply 'start-process (append (list "cmake" "*cmake*" cmake-ide-cmake-command)
                                    (cide--cmake-args)
                                    (list "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
"-B" "." "-S" project-dir))))))
dlyr commented 5 years ago

As far as I understand, cmake-ide-cmake-args is a list, so you can set it with, for your case @gatto73,

((nil . ((cmake-ide-project-dir . "~/CppProjects/sse-cs106b/lecture12-recursive-struct")
         (cmake-ide-build-dir . "~/CppProjects/sse-cs106b/lecture12-recursive-struct/build")
         (cmake-ide-cmake-args . ("-DCMAKE_BUILD_TYPE=Debug")))))
gatto73 commented 5 years ago

Thanks for the reply @dlyr

Maybe the docstring for cmake-ide-cmake-args should be improved.

I also don't understand why cmake-ide-cmake-args is used two times inside the or special form of cide--cmake-args, I guess it was a typo.

Should I close this issue?

atilaneves commented 5 years ago

Should I close this issue?

Either that or change it to an issue about the docstring

thomaswillecomme commented 4 years ago

I had a related problem. It was always compiling in release mode even if cmake-ide-cmake-args was set properly. i figured out that cmake-ide-cmake-opts is set to "-DCMAKE_BUILD_TYPE=Release" and append to the command line even if cmake-ide-cmake-args is set. I quickfixed it by overriding cmake-ide-cmake-opts to "" but it should either be empty or we should not use this value if cmake-ide-cmake-args is set.

ilitzroth commented 3 years ago

Code says that if cmake-ide-cmake-args is nil (not set or cleared) it will use the value of the deprecated cmake-ide-cmake-opts which is set to "-D..." This is rather confusing behavior.