Issue
When using CMAKE_PREFIX_PATH
as an environnment variable, I have a weird behaviour, which I can't find in documentation.
I want to search the prefix path in two location, let's call them /path/to/prefix1
and /path/to/prefix2
.
- This doesn't work :
export CMAKE_PREFIX_PATH="/path/to/prefix1;/path/to/prefix2"
- This does work :
export CMAKE_PREFIX_PATH="/path/to/prefix1:/path/to/prefix2"
Obviously in Unix PATH
variable use :
as a separator, but in CMake list separator is ;
, like documented here. In the same link, its not written that environnment variables are an exception.
It also is explicitly written that CMAKE_PREFIX_PATH
is a semicolon-separated list, which is confusing.
So what's going on here?
EDIT: It seems that when giving the argument from the command line, it does work only with ;
and not :
, which is the opposite as using an environnment variable : e.g. cmake .. -D CMAKE_PREFIX_PATH="/path/to/prefix1;/path/to/prefix2"
works.
Solution
The normal variable and the environment variable are treated differently and are documented separately. CMake tends to treat environment variables the same way as the system treats the PATH
variable. CMake normal variables are typically semicolon-separated (the most notable exceptions are the _FLAGS
variables, which are space-separated for historical and backwards compatibility reasons).
For the environment variable CMAKE_PREFIX_PATH
, the documentation says:
This variable may hold a single prefix or a list of prefixes separated by
:
on UNIX or;
on Windows (the same as the PATH environment variable convention on those platforms).
https://cmake.org/cmake/help/latest/envvar/CMAKE_PREFIX_PATH.html
Meanwhile, for the normal CMAKE_PREFIX_PATH
variable, the documentation says:
Semicolon-separated list of directories specifying installation prefixes to be searched by the
find_package()
,find_program()
,find_library()
,find_file()
, andfind_path()
commands.
https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html
which I can't find in documentation.
I found this simply by searching "CMAKE_PREFIX_PATH" in the documentation side-bar.
Answered By - Alex Reinking Answer Checked By - David Goodson (WPSolving Volunteer)