如何在CMake脚本中设置PATH环境变量?
我想通过 Mingw 编译器构建我的源代码,该编译器未放置在我的系统路径中。 我在脚本的开头尝试了
set(Env{PATH} "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
这个:
set(CMAKE_PROGRAM_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
set(CMAKE_LIBRARY_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
set(CMAKE_SYSTEM_PROGRAM_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
set(CMAKE_SYSTEM_PREFIX_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
第一个变体根本不起作用。建议我无法覆盖 CMake 脚本中环境变量的值。 第二个脚本找到我的 mingw 编译器,但在运行 gcc 时捕获错误(找不到 gcc 所需的 libgmp-10.dll)。这是因为 PATH 变量没有设置为我的 Mingw。
I want to build my sources by Mingw compiler which in not placed on my system PATH.
I tried this in the beginning of my script:
set(Env{PATH} "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
And this:
set(CMAKE_PROGRAM_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
set(CMAKE_LIBRARY_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
set(CMAKE_SYSTEM_PROGRAM_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
set(CMAKE_SYSTEM_PREFIX_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
The first variant doesn't work at all. A suggest that I can't overwrite the value of the environment variable in CMake script.
The second script finds my mingw compiler, but catches the error while running gcc (can't find libgmp-10.dll which needs by gcc). This is because the PATH variable is not set to my Mingw.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CMAKE_SYSTEM_PROGRAM_PATH 不可修改,请使用
CMAKE_SYSTEM_PROGRAM_PATH is not meant to be modified, use
您可以将其视为交叉编译工具链,即使您没有像本示例中那样从 Linux 交叉编译到 Windows:
http://www.vtk.org/Wiki/CmakeMingw
遵循该指南后,您可以在调用 cmake 时在命令行中设置 mingw 工具链:
那么如果您经常使用它你可以创建一个别名来限制每次你想重新生成 makefile 时输入那个丑陋的 -D :
You might approach it as if it were a cross compiling toolchain, even if you're not cross compiling from Linux to Windows as in this example:
http://www.vtk.org/Wiki/CmakeMingw
After you follow that guide you set the mingw toolchain at the command line when calling cmake:
then if you're using this a whole lot you can make an alias to limit typing in that ugly -D every time you want to regenerate makefiles:
编写脚本文件来启动 CMake。
在 Windows 上创建一个批处理文件:
在 Linux 上创建一个 bash 脚本:
Write a script file to start CMake.
On Windows make a batch file:
On Linux make a bash script: