cmake4eclipse icon indicating copy to clipboard operation
cmake4eclipse copied to clipboard

cmake-presets support

Open ksrp1984 opened this issue 1 year ago • 4 comments

I created a CMakePresets.json file containing project configurations. I can see the list of available configurations by adding --list-presets to Other CMake arguments I can run a configuration by adding --preset MY_CONFIG_NAME But I can't run --build --presets and --workflow --presets.

Cmake4Eclipse adds first: -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_RULE_MESSAGES:BOOL=OFF -G "Unix Makefiles". Cmake throws an error. Cmake expects --workflow --presets to be the first argument.

The first step would be to add the ability to run cmake with its own parameters, without adding additional arguments. I think it's not difficult to implement.

The second step would be to load configurations from CMakePresets.json. This is more complicated. I'm not sure it's possible. But the first step would be enough. Configurations with --preset can be created manually.

CMakePresets.json is very useful when the project is distributed, and a user who does not use Eclipse can build it from the command line, or in another IDE supporting Cmake (VS, QTCreator...)

ksrp1984 avatar Aug 07 '24 14:08 ksrp1984

Which version of cmake are you running? My version is 3.20.4 which does not support the --workflow option.

Anyway: Adding an option like --build or any other option that makes cmake to behave like a native build tool (e.g. make) is a bad idea since it will build the project twice: Once by cmake and once by CDT's builder. cmake4eclipse uses cmake to generate the build scripts, building is done by CDT's builder.

15knots avatar Aug 20 '24 19:08 15knots

Which version of cmake are you running? My version is 3.20.4 which does not support the --workflow option.

I am using cmake 3.28. I use cmake 3.28. I was able to set up a configuration by сmake --preset and build by CDT. But on Linux for some reason there is no access to the Eclipse environment variables (${ConfigName}). On Windows it works, and you can pass the CDT configuration name in cmake --preset. On Linux you need to specify the configuration name twice - in Configurations Manager and in Other Cmake Arguments image Maybe this is a CDT problem and not a plugin problem

ksrp1984 avatar Aug 21 '24 03:08 ksrp1984

Another problem: the plugin does not add include directories if there are no source files inside the project (Even if link directories are created). We use the project only for building, all source files in separate directories. A workaround is to add fake.c to the root of the project, but this is a bad way

ksrp1984 avatar Aug 21 '24 03:08 ksrp1984

It loooks like VSCode is parsing the preset file to gather settings from the presets and call CMake directly with those settings. Maybe it's the sanest way of using presets.

Some Ideas:

  • Build presets could be used as build configurations within Eclipse
  • Targets which can be used to auto fill build targets
  • Cache variables for CMake cache entries dialog
  • Per build preset/configuration CMake to, e.g., cross compile with a native CMake and run UnitTests with Cygwin
  • etc.

IMHO supporting presets may lead to a refactoring of the whole plugin, as everything can change depending on choosen preset, which also changes how GUI dialogs expose settings (readonly?).

kuch3n avatar Sep 10 '24 07:09 kuch3n