[CMake] Creating custom file before building/compiling with cmake
norulez
norulez at me.com
Thu Aug 19 15:48:23 EDT 2010
OK, thank you very much, I will try it
Best Regards
NoRulez
Am 19.08.2010 um 21:42 schrieb Michael Wild <themiwi at gmail.com>:
>
> In that case I recommend creating a CMake script (e.g. create_application_version.cmake) which creates the ApplicationVersion.xml file. It queries the current revision (have a look at FindSVN.cmake on how to do this), determines the date and time (this is a problem, refer to this thread for more info: http://www.mail-archive.com/cmake@cmake.org/msg30662.html) and then either does a configure_file() or a file(WRITE) to create ApplicationVersion.xml. Ideally the create_application_version.cmake is also a configured file (with the path to the build and source tree and the path to the svn executable etc.).
>
> This script is then invoked by a custom command:
>
> # dummy_file is never created...
> add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/ApplicationVersion.xml ${CMAKE_BINARY_DIR}/dummy_file
> COMMAND ${CMAKE_EXECUTABLE} -P ${CMAKE_BINARY_DIR}/create_application_version.cmake
> COMMENT "Creating ApplicationVersion.xml"
> VERBATIM
> )
>
> # this intentionally depends on dummy_file, which is never created
> add_custom_target(create_appplication_version ALL
> DEPENDS ${CMAKE_BINARY_DIR}/ApplicationVersion.xml ${CMAKE_BINARY_DIR}/dummy_file)
>
> add_executable(super_duper main.cpp ${CMAKE_BINARY_DIR}/ApplicationVersion.xml)
> add_dependencies(super_duper create_appplication_version)
>
>
> The trick I'm trying to pull off, is that super_duper depends on create_appplication_version, which is always out of date and depends on the non-existing file dummy_file, thus always updating ApplicationVersion.xml. Not that I haven't tested this.
>
> Michael
>
> On 19. Aug, 2010, at 18:54 , Roman Wüger @mac.com wrote:
>
>> The file should be updated every time a build is started.
>>
>> Best Regards
>> NoRulez
>>
>> Am 19. Aug 2010 um 16:48 schrieb Michael Wild <themiwi at gmail.com>:
>>
>>>
>>> On 19. Aug, 2010, at 16:38 , Roman Wüger @mac.com wrote:
>>>
>>>> Hello,
>>>>
>>>> i need to create a file called "ApplicationVersion.xml" before the main source file (main.cpp) would be compiled.
>>>> The file should contain some application details and the current Date/Time and SVN Revision.
>>>>
>>>> How can I create such file before the source file are compiled?
>>>> How can I get the current Date/Time and the SVN Revision?
>>>>
>>>> Thanks in advance
>>>>
>>>> Best Regards
>>>> NoRulez
>>>
>>>
>>> When should the file be updated? At configure time or every time a build is started?
>>>
>>> Michael
>
More information about the CMake
mailing list