From 423cdb561c129da439ebf2c61d6ddbcc5fb516e7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 17 Sep 2007 10:51:05 -0400 Subject: [PATCH] ENH: Adding test for ADD_CUSTOM_COMMAND's new IMPLICIT_DEPENDS feature. --- Tests/BuildDepends/CMakeLists.txt | 40 +++++++++++++++++++++++ Tests/BuildDepends/Project/CMakeLists.txt | 18 ++++++++++ Tests/BuildDepends/Project/dep.cxx | 1 + Tests/BuildDepends/Project/zot.cxx | 9 +++++ 4 files changed, 68 insertions(+) create mode 100644 Tests/BuildDepends/Project/dep.cxx create mode 100644 Tests/BuildDepends/Project/zot.cxx diff --git a/Tests/BuildDepends/CMakeLists.txt b/Tests/BuildDepends/CMakeLists.txt index b36d999df..428d5ed67 100644 --- a/Tests/BuildDepends/CMakeLists.txt +++ b/Tests/BuildDepends/CMakeLists.txt @@ -11,6 +11,9 @@ message("Creating Project/foo.cxx") write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx "const char* foo() { return \"foo\";}" ) +file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in + "static const char* zot = \"zot\";\n") + message("Building project first time") try_compile(RESULT ${BuildDepends_BINARY_DIR}/Project @@ -42,6 +45,14 @@ if(EXISTS "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}") endif(EXISTS "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}") +set(zot ${BuildDepends_BINARY_DIR}/Project/zot${CMAKE_EXECUTABLE_SUFFIX}) +if(EXISTS + "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" ) + message("found debug") + set(zot + "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}") +endif(EXISTS + "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}") message("Running ${bar} ") execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult) @@ -54,6 +65,17 @@ else("${out}" STREQUAL "foo ") message(SEND_ERROR "Project did not initially build properly: ${out}") endif("${out}" STREQUAL "foo ") +message("Running ${zot} ") +execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult) +string(REGEX REPLACE "[\r\n]" " " out "${out}") +message("Run result: ${runResult} Output: \"${out}\"") + +if("${out}" STREQUAL "zot ") + message("Worked!") +else("${out}" STREQUAL "zot ") + message(SEND_ERROR "Project did not initially build properly: ${out}") +endif("${out}" STREQUAL "zot ") + message("Waiting 3 seconds...") # any additional argument will cause ${bar} to wait forever execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out) @@ -61,6 +83,8 @@ execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out) message("Modifying Project/foo.cxx") write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx "const char* foo() { return \"foo changed\";}" ) +file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot.hxx.in + "static const char* zot = \"zot changed\";\n") message("Building project second time") try_compile(RESULT @@ -91,6 +115,11 @@ if(EXISTS message("found debug") endif(EXISTS "${BuildDepends_BINARY_DIR}/Project/Debug/bar${CMAKE_EXECUTABLE_SUFFIX}") +if(EXISTS + "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}" ) + message("found debug") +endif(EXISTS + "${BuildDepends_BINARY_DIR}/Project/Debug/zot${CMAKE_EXECUTABLE_SUFFIX}") message("Running ${bar} ") execute_process(COMMAND ${bar} OUTPUT_VARIABLE out RESULT_VARIABLE runResult) @@ -102,3 +131,14 @@ if("${out}" STREQUAL "foo changed ") else("${out}" STREQUAL "foo changed ") message(SEND_ERROR "Project did not rebuild properly!") endif("${out}" STREQUAL "foo changed ") + +message("Running ${zot} ") +execute_process(COMMAND ${zot} OUTPUT_VARIABLE out RESULT_VARIABLE runResult) +string(REGEX REPLACE "[\r\n]" " " out "${out}") +message("Run result: ${runResult} Output: \"${out}\"") + +if("${out}" STREQUAL "zot changed ") + message("Worked!") +else("${out}" STREQUAL "zot changed ") + message(SEND_ERROR "Project did not rebuild properly!") +endif("${out}" STREQUAL "zot changed ") diff --git a/Tests/BuildDepends/Project/CMakeLists.txt b/Tests/BuildDepends/Project/CMakeLists.txt index 4f188b67b..2651adf09 100644 --- a/Tests/BuildDepends/Project/CMakeLists.txt +++ b/Tests/BuildDepends/Project/CMakeLists.txt @@ -27,3 +27,21 @@ add_executable(bar bar.cxx ${CMAKE_CURRENT_BINARY_DIR}/regen.h ${CMAKE_CURRENT_BINARY_DIR}/noregen.h ) + +#----------------------------------------------------------------------------- +IF("${CMAKE_GENERATOR}" MATCHES "Make") + # Test the IMPLICIT_DEPENDS feature. + SET(ZOT_DEPENDS IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep.cxx) +ELSE("${CMAKE_GENERATOR}" MATCHES "Make") + # No IMPLICIT_DEPENDS...just depend directly. + SET(ZOT_DEPENDS DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in) +ENDIF("${CMAKE_GENERATOR}" MATCHES "Make") +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in + ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx + ${ZOT_DEPENDS} + ) + +add_executable(zot zot.cxx ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx) diff --git a/Tests/BuildDepends/Project/dep.cxx b/Tests/BuildDepends/Project/dep.cxx new file mode 100644 index 000000000..6cfebe37c --- /dev/null +++ b/Tests/BuildDepends/Project/dep.cxx @@ -0,0 +1 @@ +#include diff --git a/Tests/BuildDepends/Project/zot.cxx b/Tests/BuildDepends/Project/zot.cxx new file mode 100644 index 000000000..703ca384b --- /dev/null +++ b/Tests/BuildDepends/Project/zot.cxx @@ -0,0 +1,9 @@ +#include +#include + +int main() +{ + printf("%s\n", zot); + fflush(stdout); + return 0; +}