How to set PATH environment variable in CMake script?

I want to create my sources using the Mingw compiler, which was not placed on my PATH system. I tried this at 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 option does not work at all. Suppose I cannot overwrite the value of an environment variable in a CMake script. The second script finds my mingw compiler, but it catches an error when gcc starts (cannot find libgmp-10.dll, which gcc needs). This is because the PATH variable is not configured on my Mingw.

+7
cmake
Sep 28 2018-11-11T00:
source share
3 answers

Write a script file to run 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 
+1
Sep 30 2018-11-21T00:
source share

CMAKE_SYSTEM_PROGRAM_PATH not intended to change, use

 LIST(APPEND CMAKE_PROGRAM_PATH "c:/MyProject/Tools/mingw/bin/" ...) 
+13
Aug 05 '14 at 3:00
source share

You can approach it as if it were a cross-compilation of a toolchain, even if you are not cross-compiling from Linux to Windows, as in this example:

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

After you follow this guide, you install the mingw toolchain on the command line when you invoke cmake:

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

then if you use this a lot, you can make an alias to restrict text input to this ugly -D every time you want to regenerate makefiles:

 alias mingw-cmake='cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake' 
+2
Sep 29 '11 at 20:27
source share



All Articles