[CMake] How to specify that CMake build time configuration depends on a certain file?
Michael Wild
themiwi at gmail.com
Tue Oct 25 00:51:45 EDT 2011
On 10/25/2011 12:09 AM, Daniel Dunbar wrote:
> Hi all,
>
> I've been searching for an answer to the following problem, with no luck:
>
> I have a CMake build that reads in some data from an external
> (non-CMake) file during configuration.
>
> I want to tell CMake that the configuration depends on this file, so
> that the --check-build-system / check_cache steps will know to
> automatically rebuild the project files / Makefiles / etc., whenever I
> edit the external file.
>
> Is this possible?
>
> Here is an example test case to demonstrate the problem, I want the
> project to know to rebuild when I change the version.txt file:
> --
> # Here is the test CMakeLists file that uses an external file:
> $ cat CMakeLists.txt
> cmake_minimum_required(VERSION 2.6)
>
> file(STRINGS "version.txt" VERSION)
> add_library(test t.cpp)
> add_definitions("-DVERSION=@VERSION@")
>
> # And here is the external file:
> $ cat version.txt
> 1
>
> # Do our first build.
> $ make
> [100%] Building CXX object CMakeFiles/test.dir/t.cpp.o
> Linking CXX static library libtest.a
> [100%] Built target test
>
> # Modify the external file.
> $ echo 2 > version.txt
>
> # Now we rerun make, but nothing is rebuilt because CMake
> # doesn't know the configuration depends on version.txt
> $ make
> [100%] Built target test
> --
>
> Thanks in advance,
> - Daniel
More information about the CMake
mailing list