22

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.

1
  • Prepending to ENV{PATH} in a toolchain file Works For Me™ on Windows with CMake 3.25.2: set(ENV{PATH} "/path/to/mingw;$ENV{PATH}"), at least during the initial configuration/generation phase. Compilers fail to run with the subsequent Ninja invocation though :( Commented May 18, 2023 at 19:24

3 Answers 3

23

CMAKE_SYSTEM_PROGRAM_PATH is not meant to be modified, use

LIST(APPEND CMAKE_PROGRAM_PATH  "c:/MyProject/Tools/mingw/bin/" ...)
Sign up to request clarification or add additional context in comments.

2 Comments

Looks like this doesn't manipulate the PATH environement variable! If you call custom commands with programs that depend on DLL files located in the given path, the DLL files are not found.
@Benjamin Buch, in case you want it to find the dll, I used include_directories or target_include_directories for that
4

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'

1 Comment

This doesn't actually solve the question. The toolchain file will only work if the bin folder from mingw is already on the system path.
-7

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

1 Comment

you can use setlocal in a script to automatically undo the change to the path when the batch file exits (if desired). There are also environment variables ProgramFiles(x86) and ProgramFiles that should be used instead of hard coding C:\Program Files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.