[CMake] How to rerun cmake if a file changes
Vladislav Vaintroub
vvaintroub at googlemail.com
Tue Nov 23 13:23:53 EST 2010
Hello,
we use a text file as input for out build to store version info. The
content of this file is
./VERSION:
MYSQL_VERSION_MAJOR=5
MYSQL_VERSION_MINOR=5
MYSQL_VERSION_PATCH=8
MYSQL_VERSION_EXTRA=
During cmake run, the information is extracted, parsed,
CPACK_PACKAGE_FILE_NAME is generated, and some other things happen, e.g we
configure a header file mysql_version.h.
So far, it works nicely, the only problem with it is that cmake is not
rerun when this file changes. I made an attempt to fix it by introducing
custom command and custom target
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_BINARY_DIR}/VERSION.dep
COMMAND ${CMAKE_COMMAND} ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/VERSION.dep
DEPENDS ${CMAKE_SOURCE_DIR}/VERSION
)
ADD_CUSTOM_TARGET(check_version ALL DEPENDS ${CMAKE_BINARY_DIR}/VERSION.dep)
This seems to work but is not without problems. For example the very first
build with rerun cmake to generate VERSION.dep. It takes some seconds with
Makefiles, this is not a big problem, however in Visual Studio (I'm using
VS2010) the very first build would tell me "N solutions regenerated, you
want to rebuild?", and then I clicking "OK" a COM error would popup (the
build would actually still continue run successfully despite popups and COM
error).
So the question is if there is a nicer way to accomplish what I want to do.
I'm aware that if VERSION had CMake syntax with SET(MYSQL_MAJOR_VERSION 5)
etc, then I could just INCLUDE this file, and this would fix problems I
have. I'm however more interested in a solution that would not force that
file to be written in CMake syntax.
Thanks,
Vladislav
More information about the CMake
mailing list