Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fields from .cmake-kits.json get ignored? #195

Closed
i-ilak opened this issue Jan 17, 2024 · 6 comments
Closed

Some fields from .cmake-kits.json get ignored? #195

i-ilak opened this issue Jan 17, 2024 · 6 comments

Comments

@i-ilak
Copy link

i-ilak commented Jan 17, 2024

Describe the bug
I'm having trouble with the .cmake-kits.json configuration. I have a project and in its root I created the .cmake-kits.json file and I pasted the following configuration:

{
    "gcc Debug": {
        "cmake_src_dir": "~/test",
        "cmake_build_type": "Debug",
        "cmake_usr_args": {
            "CONAN": "ON",
            "CONAN_DISABLE_CHECK_COMPILER": "ON"
        },
        "cmake_build_dir": "~/build_folder_to_test_something",
        "cmake_build_args": {
            "parallel": "14"
        },
        "generator": "Ninja"
    }
}

The file gets correctly recognized by nvim, i.e. I can run :CMakeSelectKit gcc Debug and then I run :CMake. If I then run :CMakeInfo, half of the settings from above have been ignored (build type, build dir, build args).

To Reproduce
Steps to reproduce the behavior:

  1. Go to empty folder and create minimal CMakeLists.txt, main.cpp, and .cmake-kits.json with the above content
  2. Open CMakeLists.txt in nvim and run :CMakeSelectKit gcc Debug and :CMake
  3. Run :CMakeInfo. You should now see this
CMake:
    version:            3.22.1

Project:
    name:               example_project
    build type:         Release
    build directory:   ~/test/cmake-build-Release
    generator:          Ninja
    generation command: cmake -DCMAKE_BUILD_TYPE=Release -G "Ninja"  -DCONAN_DISABLE_CHECK_COMPILER=ON -DCONAN=ON -B ~/test/cmake-build-Release -S ~/test
    build command:      cmake --build ~/test/cmake-build-Release --target all  -- -C ~/test/cmake-build-Release 

As you can see, anything related to the build config is not working.

Expected behavior
A configuration that corresponds to the specified .cmake-kits.json.

If I'm misunderstanding how the .cmake-kits.json should work, I apologize for the bug report and would appreciate some guidance on how to get it working.^^

Desktop (please complete the following information):

  • OS: macOS, Ubuntu
  • Editor: nvim
  • Version: NVIM v0.10.0-dev, Build type: RelWithDebInfo, LuaJIT 2.1.0-beta3
Copy link

Hi!👋
Thank you for raising the issue.
I hope, the plugin makes your workflow easier!
We will take a look to your issue as soon as possible.💖

@mark2185
Copy link
Contributor

The cmake-kits support/parse only a handful of options, for e.g. cmake_build_type and cmake_build_args I'd recommend using the g:cmake_variants variable.

As for the cmake_build_dir it's done through g:cmake_build_dir, or better yet through g:cmake_build_path_pattern so you can have simultaneous builds of different build types/compilers/etc.

The way I use it is:

  • select a cmake kit
  • select a build variant
  • run :CMake

These are just some of my build variants:

let g:cmake_variants =
    \{
    \   'debug-with-warnings': {
    \       'cmake_build_type' : 'Debug',
    \       'cmake_usr_args'   : '-DENABLE_RUNTIME_CHECKS=ON -DMB_TREAT_WARNINGS_AS_ERRORS=OFF'
    \   },
    \   'debug': {
    \       'cmake_build_type' : 'Debug',
    \       'cmake_usr_args'   : '-DENABLE_RUNTIME_CHECKS=ON -DMB_TREAT_WARNINGS_AS_ERRORS=ON'
    \   },
    \   'release': {
    \       'cmake_build_type' : 'Release',
    \       'cmake_usr_args'   : '-DENABLE_RUNTIME_CHECKS=OFF -DMB_TREAT_WARNINGS_AS_ERRORS=OFF -DMB_INTEL_OPTIMIZATION=haswell'
    \   }}

And these are some of my cmake_kits.json:

...
    "clang": {
        "compilers": {
            "C"   : "/usr/bin/clang",
            "CXX" : "/usr/bin/clang++"
        },
        "query_driver" : "/usr/bin/clang++",
        "generator": "Ninja"
    },
    "gcc": {
        "compilers": {
            "C"   : "/usr/bin/gcc",
            "CXX" : "/usr/bin/g++"
        },
        "query_driver" : "/usr/bin/g++",
        "generator": "Ninja"
    },
...

As for the cmake_build_path_pattern, I have this:

let g:cmake_build_path_pattern = [ '%s/workspace/build/%s/%s/%s', "$HOME, fnamemodify( getcwd(), ':t' ), g:cmake_selected_kit, g:cmake_build_type" ]

That way I get builds like:

  • ~/workspace/build/ProjectName/clang/debug
  • ~/workspace/build/ProjectName/clang/release
  • ~/workspace/build/ProjectName/gcc/debug-with-warnings
  • ~/workspace/build/AnotherProject/clang/debug-with-warnings

@i-ilak
Copy link
Author

i-ilak commented Jan 17, 2024

Hi @mark2185

I see, I didn't know that the .cmake-kits.json where limited in that sense. From the README here I just assumed that everything that was listed in terms of vim variables could be moved to the json-file. Sorry and thanks for the other suggestions!

The cmake_variants works perfectly but with the cmake_build_path_pattern I'm struggling a bit. Since I use nvim my configuration is in Lua, i.e. I translated you suggestion to this

vim.g.cmake_build_path_pattern = {
    string.format('%s/iilak/prg/build_folders/%s/%s/%s',
    os.getenv('HOME'),
    vim.fn.fnamemodify(vim.fn.getcwd(), ':t'),
    vim.g.cmake_selected_kit,
    vim.g.cmake_build_type
  )
}

Unfortunately, this still doesn't work. When I open the a file in the test folder, it evaluates the above expression to e.g. ~/iilak/prg/build_folders/test// since cmake_selected_kit and cmake_build_type are not yet set. So once I run :CMakeSelectKit gcc and :CMakeSelectBuildType debug it runs cmake, but the build folder is then still ~/test/cmake-build-debug, which seems to be the default pattern.

I'm sorry, I assume this is my inexperience with nvim that is causing this...

@mark2185
Copy link
Contributor

mark2185 commented Jan 17, 2024

That's actually why both of the elements in g:cmake_build_path_pattern are strings, they're being eval'd at the time of use so it can "pick up" the g:cmake_selected_kit and g:cmake_build_type.

I'd suggest either writing that variable definition like this:

vim.cmd([[
let g:cmake_build_path_pattern = [ '%s/iilak/prg/build_folders/%s/%s/%s', "$HOME, fnamemodify( getcwd(), ':t' ), g:cmake_selected_kit, g:cmake_build_type" ]
]])

Or you could try writing it in lua, but as two strings, so just vim.g.cmake_build_path_pattern = { '%s/iilak/prg/build_folders/%s/%s/%s', "$HOME, fnamemodify( getcwd(), ':t' ), g:cmake_selected_kit, g:cmake_build_type" }, I think that could work too.

Since the plugin is written in vimscript I'm guessing the g:cmake_selected_kit and g:cmake_build_type in the second approach should work.

@i-ilak
Copy link
Author

i-ilak commented Jan 17, 2024

Hi @mark2185

Your Lua suggestion worked like a charm. Thanks a lot for the support! I'll close the issue, hope that works for you 🙌

@i-ilak i-ilak closed this as completed Jan 17, 2024
@mark2185
Copy link
Contributor

Great! Glad to have helped! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants