[CMake] configure_file as a build step?
Michael Wild
themiwi at gmail.com
Wed May 2 01:32:44 EDT 2012
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
>
>
>
> --
>
> 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
More information about the CMake
mailing list