How to set PATH environment variable in CMake scri

2019-02-16 17:46发布

I want to build my sources by Mingw compiler wich 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 setted to my Mingw.

标签: cmake
3条回答
可以哭但决不认输i
2楼-- · 2019-02-16 17:51

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'
查看更多
淡お忘
3楼-- · 2019-02-16 17:52

CMAKE_SYSTEM_PROGRAM_PATH is not meant to be modified, use

LIST(APPEND CMAKE_PROGRAM_PATH  "c:/MyProject/Tools/mingw/bin/" ...)
查看更多
霸刀☆藐视天下
4楼-- · 2019-02-16 18:11

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
查看更多
登录 后发表回答