[CMake] "Deep" variable expansion (or, replacing literal "${FOO}")

Petr Kmoch petr.kmoch at gmail.com
Tue Apr 2 02:49:50 EDT 2013


Hi Braden,

the purpose of CMAKE_CFG_INTDIR is to expand to something that is
meaningful to the build system you're using. It's a way to transport
information from CMake-time (when your CMakeLists are processed) to
build-time (when you run a build).

The exact value of CMAKE_CFG_INTDIR depends on the generator you're using.
For Visual Studio, for example, it's $(OutDir) or $(Configuration),
depending on VS version. Note that these aren't CMake variable, they're
Visual Studio macros, which are expanded by VS itself when it sees them in
a command-line it's processing. CMAKE_CFG_INTDIR will have a value with
similar properties for other multi-configuration generators (e.g.
$(CONFIGURATION) for XCode).

On single-config generators, the value is just ".", because these do not
have different paths for different configurations (since they just have
one). With such generators, the name of the configuration is available at
CMake-time in the variable CMAKE_BUILD_TYPE.

On multi-config generators, there is no "current configuration" at
CMake-time. When a reference to a configuration-specific path (or something
else configuration-specific) is necessary, its dereferencing must be done
at build time, and for this purpose, the "meta" variable CMAKE_CFG_INTDIR
is used.

I hope this helps you. Regarding your particular question about replacing
in the value, are you sure CMAKE_CFG_INTDIR expands to a text with braces,
not parentheses?

Petr


On Fri, Mar 29, 2013 at 9:58 PM, Braden McDaniel <braden at endoframe.com>wrote:

> The value of the variable CMAKE_CFG_INTDIR is the literal string
> "${config}"
> (that is, CMake does not expand this variable itself). I'd like to expand
> this
> literal variable within CMake using a value I supply; that is, I'd like to
> replace the literal string "${config}" with something else; say, "foo".
> Alas, I
> have not been able to get this to work:
>
>   string(REPLACE "\${config}" foo MY_OUTPUT_VAR ${CMAKE_CFG_INTDIR})
>
> Why isn't this working? Is there some other way to accomplish what I want?
>
> Braden
>
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130402/ff4e5532/attachment.htm>


More information about the CMake mailing list