安装后将bin文件夹追加到PATH环境变量

Append bin folder to PATH environement variable after installation

我已经完成了 Windows 的 C++ 程序和使用 CPack 的 NSIS 安装程序。 我希望安装后,用户可以从终端调用我的程序,而无需提供 exe 的完整路径。
有时,一些安装程序甚至会在安装结束时添加一个 Add useful environment variables 复选框,以供用户选择。

是否可以在安装结束时使用 CPack 和 NSIS 生成器将我们的 bin 文件夹的路径添加到 PATH 环境变量?

如果不行,其他程序在安装时如何添加环境变量?

一如既往,检查文档... https://cmake.org/cmake/help/latest/cpack_gen/nsis.html

CPACK_NSIS_MODIFY_PATH

   Modify PATH toggle. If this is set to ON, then an extra page will appear in the installer that will allow the user to choose whether the program directory should be added to the system PATH variable.

请注意,这被硬编码为 $INSTDIR\bin 路径并且不可配置。特别是,将 CMAKE_INSTALL_BINDIR 设置为 other 而不是 bin 的任何值都会中断。