[CMake] configure_file as a build step?
Jensen, Erik A
Erik.Jensen at pnnl.gov
Wed May 9 14:44:45 EDT 2012
That worked, although a little roundabout. Thank you.
Would there be any interest in having an easier way to do this? It seems like it could be usefully in a fair number of situations.
Maybe an additional -E command:
cmake -E configure_file -D var1=value1 -D var2=value2 --at-only infile outfile
Or even a way to run arbitrary CMake commands without a script file:
cmake -D var1=value1 -D var2=value2 -R "configure_file(infile outfile @ONLY)"
This would make it possible to avoid having a whole other file just to execute one CMake command at build time.
Thoughts?
-----Original Message-----
From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf Of Michael Wild
Sent: Tuesday, May 01, 2012 10:33 PM
To: cmake at cmake.org
Subject: Re: [CMake] configure_file as a build step?
You can configure_file() a CMake-script which itself then performs the
configure_file() in a custom command. E.g.:
# CMakeLists.txt:
#...
set(FOO "Some text to show up in json_file.json")
set(BAR "More text")
configure_file(configure_json_file.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/configure_json_file.cmake @ONLY)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/json_file.json
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/configure_json_file.cmake
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/configure_json_file.cmake
${CMAKE_CURRENT_SOURCE_DIR}/json_file.json.in
COMMENT "Configuring json_file.json"
VERBATIM)
add_custom_target(configure_json ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/json_file.json)
#...
# EOF
# configure_json_file.cmake.in:
set(SRC_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
set(BIN_DIR "@CMAKE_CURRENT_BINARY_DIR@")
set(FOO "@FOO@")
set(BAR "@BAR@")
configure_file(${SRC_DIR}/json_file.json.in
${BIN_DIR}/json_file.json @ONLY)
# EOF
HTH
Michael
On 05/02/2012 01:16 AM, Jensen, Erik A wrote:
> I have a JSON file that needs to have some values set based on the
> project's configuration. During development, this file can change rather
> frequently.
>
>
>
> Currently, I am using configure_file to fill in the required values.
> Unfortunately, every time the file is modified, it triggers CMake to do
> a complete configuration and generation step. This slows down rebuilds,
> and is especially problematic when using Visual Studio, where the
> solution has to be reloaded after it is regenerated.
>
>
>
> Is there any way to have the file generated as part of the build instead
> of part of the configuration/generation step?
>
>
>
> Thanks,
>
> -- Erik
More information about the CMake
mailing list