summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2003-06-03 14:34:15 (GMT)
committerKen Martin <ken.martin@kitware.com>2003-06-03 14:34:15 (GMT)
commit7b3f2d4420a0df7faf374b1b5c306df1d9d0e312 (patch)
tree3f7a75e450d3de18970cd53ce4c90d23497d953d
parentba68f771b369e65476e7ce12aa8dd1cf18d7f529 (diff)
downloadCMake-7b3f2d4420a0df7faf374b1b5c306df1d9d0e312.zip
CMake-7b3f2d4420a0df7faf374b1b5c306df1d9d0e312.tar.gz
CMake-7b3f2d4420a0df7faf374b1b5c306df1d9d0e312.tar.bz2
new test
-rw-r--r--Tests/CustomCommand/CMakeLists.txt105
-rw-r--r--Tests/CustomCommand/doc1.tex1
-rw-r--r--Tests/CustomCommand/foo.in15
-rw-r--r--Tests/CustomCommand/generator.c9
-rw-r--r--Tests/CustomCommand/wrapped.h1
-rw-r--r--Tests/CustomCommand/wrapper.c9
6 files changed, 140 insertions, 0 deletions
diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt
new file mode 100644
index 0000000..19a8399
--- /dev/null
+++ b/Tests/CustomCommand/CMakeLists.txt
@@ -0,0 +1,105 @@
+#
+# Wrapping
+#
+PROJECT (CustomCommand)
+
+#
+# Lib and exe path
+#
+SET (LIBRARY_OUTPUT_PATH
+ ${PROJECT_BINARY_DIR}/bin/ CACHE PATH
+ "Single output directory for building all libraries.")
+
+SET (EXECUTABLE_OUTPUT_PATH
+ ${PROJECT_BINARY_DIR}/bin/ CACHE PATH
+ "Single output directory for building all executables.")
+
+################################################################
+#
+# First test using a compiled generator to create a .c file
+#
+################################################################
+# add the executable that will generate the file
+ADD_EXECUTABLE(generator generator.c)
+
+# the folowing assumes that a cmSourceFile
+# is instantiated for the output, with GENERATED 1
+# at the end of the day this becomes a what in VS ?
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/generated.c
+ DEPENDS generator
+ COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/generator
+ ARGS ${PROJECT_BINARY_DIR}/generated.c
+ )
+
+################################################################
+#
+# Test using a wrapper to wrap a header file
+#
+################################################################
+# add the executable that will generate the file
+ADD_EXECUTABLE(wrapper wrapper.c)
+
+# the following assumes that a cmSourceFile
+# is instantiated for the output, with GENERATED 1
+# at the end of the day this becomes a what in VS ?
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${PROJECT_BINARY_DIR}/wrapped.c
+ DEPENDS wrapper
+ MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/wrapped.h
+ COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/wrapper
+ ARGS ${PROJECT_BINARY_DIR}/wrapped.c ${PROJECT_SOURCE_DIR}/wrapped.h
+ )
+
+################################################################
+#
+# Test creating files from a custom target
+#
+################################################################
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/doc1.dvi
+ DEPENDS ${PROJECT_SOURCE_DIR}/doc1.tex
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${PROJECT_SOURCE_DIR}/doc1.tex
+ ${PROJECT_BINARY_DIR}/doc1.dvi
+ )
+
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/doc1.h
+ DEPENDS ${PROJECT_BINARY_DIR}/doc1.dvi
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${PROJECT_BINARY_DIR}/doc1.dvi
+ ${PROJECT_BINARY_DIR}/doc1.h
+ )
+
+ADD_CUSTOM_TARGET(TDocument ALL
+ ${CMAKE_COMMAND} -E echo "building doc1.h"
+ DEPENDS ${PROJECT_BINARY_DIR}/doc1.h
+ )
+
+################################################################
+#
+# Test using a multistep generated file
+#
+################################################################
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/foo.pre
+ DEPENDS ${PROJECT_SOURCE_DIR}/foo.in
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${PROJECT_SOURCE_DIR}/foo.in
+ ${PROJECT_BINARY_DIR}/foo.pre
+ )
+
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/foo.c
+ DEPENDS TDocument ${PROJECT_BINARY_DIR}/foo.pre
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${PROJECT_BINARY_DIR}/foo.pre
+ ${PROJECT_BINARY_DIR}/foo.c
+ )
+
+# add the library
+ADD_EXECUTABLE(CustomCommand
+ ${PROJECT_BINARY_DIR}/foo.c
+ ${PROJECT_BINARY_DIR}/wrapped.c
+ ${PROJECT_BINARY_DIR}/generated.c
+ )
+
+# must add a dependency on TDocument otherwise it might never build and
+# the CustomCommand executable really needs doc1.h
+ADD_DEPENDENCIES(CustomCommand TDocument) \ No newline at end of file
diff --git a/Tests/CustomCommand/doc1.tex b/Tests/CustomCommand/doc1.tex
new file mode 100644
index 0000000..e6b6ccb
--- /dev/null
+++ b/Tests/CustomCommand/doc1.tex
@@ -0,0 +1 @@
+int doc() { return 7;}
diff --git a/Tests/CustomCommand/foo.in b/Tests/CustomCommand/foo.in
new file mode 100644
index 0000000..a887264
--- /dev/null
+++ b/Tests/CustomCommand/foo.in
@@ -0,0 +1,15 @@
+#include "doc1.h"
+
+int generated();
+int wrapped();
+
+int main ()
+{
+ if (generated()*wrapped()*doc() == 3*5*7)
+ {
+ return 0;
+ }
+
+ return -1;
+}
+
diff --git a/Tests/CustomCommand/generator.c b/Tests/CustomCommand/generator.c
new file mode 100644
index 0000000..cda3e0f
--- /dev/null
+++ b/Tests/CustomCommand/generator.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+main(int argc, char *argv[])
+{
+ FILE *fp = fopen(argv[1],"w");
+
+ fprintf(fp,"int generated() { return 3; }\n");
+ fclose(fp);
+}
diff --git a/Tests/CustomCommand/wrapped.h b/Tests/CustomCommand/wrapped.h
new file mode 100644
index 0000000..fa882cb
--- /dev/null
+++ b/Tests/CustomCommand/wrapped.h
@@ -0,0 +1 @@
+/* empty file */
diff --git a/Tests/CustomCommand/wrapper.c b/Tests/CustomCommand/wrapper.c
new file mode 100644
index 0000000..0ed4b76
--- /dev/null
+++ b/Tests/CustomCommand/wrapper.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+main(int argc, char *argv[])
+{
+ FILE *fp = fopen(argv[1],"w");
+
+ fprintf(fp,"int wrapped() { return 5; }\n");
+ fclose(fp);
+}