如何在CMake脚本中设置PATH环境变量?

发布于 2024-12-07 03:56:47 字数 741 浏览 1 评论 0原文

我想通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暗藏城府 2024-12-14 03:56:47

CMAKE_SYSTEM_PROGRAM_PATH 不可修改,请使用

LIST(APPEND CMAKE_PROGRAM_PATH  "c:/MyProject/Tools/mingw/bin/" ...)

CMAKE_SYSTEM_PROGRAM_PATH is not meant to be modified, use

LIST(APPEND CMAKE_PROGRAM_PATH  "c:/MyProject/Tools/mingw/bin/" ...)
ぽ尐不点ル 2024-12-14 03:56:47

您可以将其视为交叉编译工具链,即使您没有像本示例中那样从 Linux 交叉编译到 Windows:

http://www.vtk.org/Wiki/CmakeMingw

遵循该指南后,您可以在调用 cmake 时在命令行中设置 mingw 工具链:

~/src/helloworld/ $ mkdir build
~/src/helloworld/ $ cd build
~/src/helloworld/build/ $ cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake

那么如果您经常使用它你可以创建一个别名来限制每次你想重新生成 makefile 时输入那个丑陋的 -D :

alias mingw-cmake='cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake'

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:

~/src/helloworld/ $ mkdir build
~/src/helloworld/ $ cd build
~/src/helloworld/build/ $ cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.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:

alias mingw-cmake='cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake'
长安忆 2024-12-14 03:56:47

编写脚本文件来启动 CMake。

在 Windows 上创建一个批处理文件:

@echo off
set path=c:\MyProject\Tools\mingw\bin;c:\MyProject\Tools\mingw\msys\1.0\bin
"C:\Program Files\CMake 2.8\bin\cmake-gui.exe"

在 Linux 上创建一个 bash 脚本:

export PATH=$PATH:/your/path

Write a script file to start CMake.

On Windows make a batch file:

@echo off
set path=c:\MyProject\Tools\mingw\bin;c:\MyProject\Tools\mingw\msys\1.0\bin
"C:\Program Files\CMake 2.8\bin\cmake-gui.exe"

On Linux make a bash script:

export PATH=$PATH:/your/path
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文