lukka / run-cmake

GitHub Action to build C++ applications with CMake (CMakePresets.json), Ninja and vcpkg on GitHub.
MIT License
173 stars 19 forks source link

[question] run build without presets #94

Closed esaulenka closed 1 year ago

esaulenka commented 1 year ago

I cannot find a way to run cmake --build without any buildPresets.

To be clear: I am using CMake with make generator and with a list of configurePresets. But I didn't find any useful settings in buildPreset, so I don't want to duplicate all items from config section to build in a CMakePresets.json.

I have two options: specify buildPreset key in action (it will cause build error) or skip it (then action just skip building). I don't like both alternatives ;)

Yes, as a workaround, I can specify something like run: cmake .. --preset ${{preset}} && cmake --build ., but it's not so elegant as dedicated solution.

lukka commented 1 year ago

@esaulenka if I get you right, you want to run cmake --preset <name> and then cmake --build <something>, without --preset.

You should be able to do it by customizing the build command by defining what you want in the buildPresetCmdString input defined here: https://github.com/lukka/run-cmake/blob/main/action.yml#L41

buildPresetCmdString:
    default: "[`--build`, `--preset`, `$[env.BUILD_PRESET_NAME]`]"
    required: false
    description: "The CMake command format string to run the build." 

You may use:

uses: run-cmake
with:
  buildPresetCmdString: ['--build', 'something']

Assuming this is helpful, let me know how to improve the documentation so that this feature is more approachable by the users!

esaulenka commented 1 year ago

Thanks, Luca.

Finally, I got working configuration: https://github.com/esaulenka/SCan_fw/actions/runs/3391874169/workflow

But for my point of view, it can be more clear, if you provide something like forceBuild: true which will work even if buildPreset not specified.

And second thing, not linked with previous. All CMake tutorials use separate folder to store generated files (usually build). I think, it is not matter in most cases when we using CI, but as I understood, with your script I got build artefacts in the repo root folder. If you are not lucky and store a lot of files in this folder (for example, scripts for other build system) you can get conflicts. Please let me know, if I am wrong.

lukka commented 1 year ago

@esaulenka I am glad to hear you found a way to make it working! I would still strongly suggest to try to use build presets, and use its powerful inheritance system between configure and build presets, which should avoid duplication of code. Let me know if your scenario makes the usage of build preset not feasible, I am interested into understanding it more.

Regarding the build output directory, you can should specify the binary directory in the configure preset, and either use preset for building as well, or fix your build command line to point to the right build directory.

esaulenka commented 1 year ago

I would still strongly suggest to try to use build presets

Thanks, I did it. But now I am not fully satisfied due to duplication of preset names ( here ). Unfortunately, ${presetName} macro not working in this place.

Anyway, thanks for your work. I think you can close this issue without any changes on your side. Thanks.