[CMake] Depending on a Config File (CMake and VC++)
Brad King
brad.king at kitware.com
Thu May 25 15:23:10 EDT 2006
Steve Johns wrote:
> My app will depend on the presence of a config file at runtime.
> It looks for this config file in the current directory where the app
> started from.
> I am using VC++ 7 and the Visual Studio IDE.
> My config file checks out of svn into the same directory as my C++ source.
>
> My goal is to copy the config file into the \debug and \release directories
> when I build (so the app will find it), and if I edit the config file,
> I want a Build operation to realize that I have done so, and copy the
> edited
> config file into \debug or \release.
>
> Can someone suggest a good way to arrange this via CMake and the VS IDE?
> Also, if the solution works with CMake over in the Cygwin environment as
> well, that would be ideal.
There are two categories of generators in CMake: multi-configuration
(VS, Xcode) and single-configuration (all Makefiles). In order to
support both VS and cygwin you need to account for both categories of
generators. You can tell them apart in CMake code using the variable
CMAKE_CONFIGURATION_TYPES which is set only for multi-configuration
generators.
You can use CONFIGURE_FILE to copy the file:
IF(CMAKE_CONFIGURATION_TYPES)
# Handle multi-configuration generators.
FOREACH(config ${CMAKE_CONFIGURATION_TYPES})
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/my.config.in,
${CMAKE_CURRENT_BINARY_DIR}/${config}/my.config)
ENDFOREACH(config)
ELSE(CMAKE_CONFIGURATION_TYPES)
# Handle single-configuration generators.
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/my.config.in,
${CMAKE_CURRENT_BINARY_DIR}/my.config)
ENDIF(CMAKE_CONFIGURATION_TYPES)
See "cmake --help-command CONFIGURE_FILE" for details.
-Brad
More information about the CMake
mailing list