How can I define CMAKE_INSTALL_PREFIX if Windows is in English to go to C:\program file\ and if Windows is in Spanish to go to C:\Archivos de Programas\
I think you can use $ENV{ProgramFiles}
to get that path in any language. If you need the 32-bit version:
set(envvar "ProgramFiles(x86)")
set(program_files "$ENV{${envvar}}")
is needed because variable names cannot have ()
in them literally.
set(program_files "$ENV{ProgramFiles\(x86\)}")
should also work.
1 Like
I don’t think so (at least with CMP0053 set to NEW) because \(
is not a recognized escape sequence. We discussed this when I implemented the policy and decided it was rare enough that the workaround was fine.
message("$ENV{ProgramFiles\(x86\)}")
gives a warning and doesn’t output what we want:
CMake Warning (dev) at D:/dev/CMExt/env_var.cmake:1 (message):
Syntax error in cmake code at
D:/dev/CMExt/env_var.cmake:1
when parsing string
$ENV{ProgramFiles\(x86\)}
syntax error, unexpected cal_SYMBOL, expecting } (19)
Policy CMP0010 is not set: Bad variable reference syntax is an error. Run
"cmake --help-policy CMP0010" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
This warning is for project developers. Use -Wno-dev to suppress it.
$ENV{ProgramFiles\(x86\)}
cmake_policy(SET CMP0010 NEW)
message("$ENV{ProgramFiles\(x86\)}")
gives an error and stops processing:
CMake Error at D:/dev/CMExt/env_var.cmake:2 (message):
Syntax error in cmake code at
D:/dev/CMExt/env_var.cmake:2
when parsing string
$ENV{ProgramFiles\(x86\)}
syntax error, unexpected cal_SYMBOL, expecting } (19)
cmake_policy(SET CMP0053 NEW)
message("$ENV{ProgramFiles\(x86\)}")
gives what we want:
C:\Program Files (x86)
Oh, maybe we decided differently. In that case, carry on . It’s too late to change such a minor behavior that has a small upside IMO .
Thank you very much, it really helps.