Merge topic 'cmake-rerun-depends'

82d43175 Allow projects to specify extra inputs to CMake
1ef444d6 Add test case to verify CMake does not re-run on first build
This commit is contained in:
Brad King 2014-01-22 08:47:59 -05:00 committed by CMake Topic Stage
commit 0bd4157886
10 changed files with 87 additions and 0 deletions

View File

@ -48,6 +48,7 @@ Properties on Directories
/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES
/prop_dir/CACHE_VARIABLES
/prop_dir/CLEAN_NO_CUSTOM
/prop_dir/CMAKE_CONFIGURE_DEPENDS
/prop_dir/COMPILE_DEFINITIONS_CONFIG
/prop_dir/COMPILE_DEFINITIONS
/prop_dir/COMPILE_OPTIONS

View File

@ -0,0 +1,9 @@
CMAKE_CONFIGURE_DEPENDS
-----------------------
Tell CMake about additional input files to the configuration process.
If any named file is modified the build system will re-run CMake to
re-configure the file and generate the build system again.
Specify files as a semicolon-separated list of paths. Relative paths
are interpreted as relative to the current source directory.

View File

@ -114,6 +114,8 @@ void cmLocalGenerator::Configure()
}
}
this->Makefile->AddCMakeDependFilesFromUser();
// Check whether relative paths should be used for optionally
// relative paths.
this->UseRelativePaths = this->Makefile->IsOn("CMAKE_USE_RELATIVE_PATHS");

View File

@ -3913,6 +3913,30 @@ cmTest* cmMakefile::GetTest(const char* testName) const
return 0;
}
void cmMakefile::AddCMakeDependFilesFromUser()
{
std::vector<std::string> deps;
if(const char* deps_str = this->GetProperty("CMAKE_CONFIGURE_DEPENDS"))
{
cmSystemTools::ExpandListArgument(deps_str, deps);
}
for(std::vector<std::string>::iterator i = deps.begin();
i != deps.end(); ++i)
{
if(cmSystemTools::FileIsFullPath(i->c_str()))
{
this->AddCMakeDependFile(*i);
}
else
{
std::string f = this->GetCurrentDirectory();
f += "/";
f += *i;
this->AddCMakeDependFile(f);
}
}
}
std::string cmMakefile::GetListFileStack()
{
cmOStringStream tmp;

View File

@ -650,6 +650,7 @@ public:
///! When the file changes cmake will be re-run from the build system.
void AddCMakeDependFile(const std::string& file)
{ this->ListFiles.push_back(file);}
void AddCMakeDependFilesFromUser();
/**
* Get the list file stack as a string

View File

@ -0,0 +1,9 @@
file(READ ${stamp} content)
if(NOT content STREQUAL 1)
set(RunCMake_TEST_FAILED "Expected stamp '1' but got: '${content}'")
endif()
file(READ ${output} content)
if(NOT content STREQUAL 1)
set(RunCMake_TEST_FAILED "Expected output '1' but got: '${content}'")
endif()

View File

@ -0,0 +1,9 @@
file(READ ${stamp} content)
if(NOT content STREQUAL 2)
set(RunCMake_TEST_FAILED "Expected stamp '2' but got: '${content}'")
endif()
file(READ ${output} content)
if(NOT content STREQUAL 2)
set(RunCMake_TEST_FAILED "Expected output '2' but got: '${content}'")
endif()

View File

@ -0,0 +1,11 @@
set(input ${CMAKE_CURRENT_BINARY_DIR}/CustomCMakeInput.txt)
set(stamp ${CMAKE_CURRENT_BINARY_DIR}/CustomCMakeStamp.txt)
file(READ ${input} content)
file(WRITE ${stamp} "${content}")
set(depend ${CMAKE_CURRENT_BINARY_DIR}/CustomCMakeDepend.txt)
set(output ${CMAKE_CURRENT_BINARY_DIR}/CustomCMakeOutput.txt)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${depend})
file(READ ${depend} content)
file(WRITE ${output} "${content}")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS RerunCMake.txt)

View File

@ -0,0 +1 @@
Source-tree dependency for "RerunCMake.cmake".

View File

@ -2,3 +2,23 @@ include(RunCMake)
run_cmake(ErrorLogs)
run_cmake(FailCopyFileABI)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/RerunCMake-build)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
set(input "${RunCMake_TEST_BINARY_DIR}/CustomCMakeInput.txt")
set(stamp "${RunCMake_TEST_BINARY_DIR}/CustomCMakeStamp.txt")
set(depend "${RunCMake_TEST_BINARY_DIR}/CustomCMakeDepend.txt")
set(output "${RunCMake_TEST_BINARY_DIR}/CustomCMakeOutput.txt")
file(WRITE "${input}" "1")
file(WRITE "${depend}" "1")
run_cmake(RerunCMake)
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1) # handle 1s resolution
file(WRITE "${input}" "2")
run_cmake_command(RerunCMake-build1 ${CMAKE_COMMAND} --build .)
file(WRITE "${depend}" "2")
run_cmake_command(RerunCMake-build2 ${CMAKE_COMMAND} --build .)
unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN)