summaryrefslogtreecommitdiff
path: root/Tests/CustomCommand
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/CustomCommand')
-rw-r--r--Tests/CustomCommand/CMakeLists.txt438
-rw-r--r--Tests/CustomCommand/GeneratedHeader/CMakeLists.txt13
-rw-r--r--Tests/CustomCommand/GeneratedHeader/generated.h.in1
-rw-r--r--Tests/CustomCommand/GeneratedHeader/main.cpp5
-rw-r--r--Tests/CustomCommand/GeneratorInExtraDir/CMakeLists.txt8
-rw-r--r--Tests/CustomCommand/check_command_line.c.in36
-rw-r--r--Tests/CustomCommand/check_mark.cmake5
-rw-r--r--Tests/CustomCommand/config.h.in1
-rw-r--r--Tests/CustomCommand/doc1.tex1
-rw-r--r--Tests/CustomCommand/foo.h.in1
-rw-r--r--Tests/CustomCommand/foo.in28
-rw-r--r--Tests/CustomCommand/gen_redirect_in.c5
-rw-r--r--Tests/CustomCommand/generator.cxx19
-rw-r--r--Tests/CustomCommand/main.cxx6
-rw-r--r--Tests/CustomCommand/tcat.cxx11
-rw-r--r--Tests/CustomCommand/wrapped.h1
-rw-r--r--Tests/CustomCommand/wrapper.cxx36
17 files changed, 615 insertions, 0 deletions
diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt
new file mode 100644
index 000000000..b7c9ea268
--- /dev/null
+++ b/Tests/CustomCommand/CMakeLists.txt
@@ -0,0 +1,438 @@
+#
+# Wrapping
+#
+cmake_minimum_required (VERSION 2.6)
+PROJECT (CustomCommand)
+
+ADD_SUBDIRECTORY(GeneratedHeader)
+
+#
+# Lib and exe path
+#
+IF(NOT DEFINED bin_dir)
+ SET(bin_dir "bin")
+ENDIF()
+
+SET (LIBRARY_OUTPUT_PATH
+ ${PROJECT_BINARY_DIR}/${bin_dir} CACHE INTERNAL
+ "Single output directory for building all libraries.")
+
+SET (EXECUTABLE_OUTPUT_PATH
+ ${PROJECT_BINARY_DIR}/${bin_dir} CACHE INTERNAL
+ "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.cxx)
+
+GET_TARGET_PROPERTY(generator_PATH generator LOCATION)
+MESSAGE("Location ${generator_PATH}")
+
+################################################################
+#
+# Test using a wrapper to wrap a header file
+#
+################################################################
+# add the executable that will generate the file
+ADD_EXECUTABLE(wrapper wrapper.cxx)
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${PROJECT_BINARY_DIR}/wrapped.c ${PROJECT_BINARY_DIR}/wrapped_help.c
+ DEPENDS wrapper
+ MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/wrapped.h
+ COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/wrapper
+ ${PROJECT_BINARY_DIR}/wrapped.c ${PROJECT_BINARY_DIR}/wrapped_help.c
+ ${CMAKE_CFG_INTDIR} # this argument tests passing of the configuration
+ VERBATIM # passing of configuration should work in this mode
+ )
+
+################################################################
+#
+# Test creating files from a custom target
+#
+################################################################
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}//doc1.dvi # test 2 slashes
+ 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
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1.dvi to doc1temp.h."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1.dvi
+ ${PROJECT_BINARY_DIR}/doc1temp.h
+ )
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/doc1.h APPEND
+ DEPENDS ${PROJECT_BINARY_DIR}/doc1.dvi
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1temp.h to doc1.h."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1temp.h
+ ${PROJECT_BINARY_DIR}/doc1.h
+ COMMAND ${CMAKE_COMMAND} -E echo " Removing doc1temp.h."
+ COMMAND ${CMAKE_COMMAND} -E remove -f ${PROJECT_BINARY_DIR}/doc1temp.h
+ )
+
+# Add custom command to generate foo.h.
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/foo.h
+ DEPENDS ${PROJECT_SOURCE_DIR}/foo.h.in
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying foo.h.in to foo.h."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/foo.h.in
+ ${PROJECT_BINARY_DIR}/foo.h
+ )
+
+# Add the location of foo.h to the include path.
+INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
+
+# Test generation of a file to the build tree without full path. As
+# of CMake 2.6 custom command outputs specified by relative path go in
+# the build tree.
+ADD_CUSTOM_COMMAND(
+ OUTPUT doc1.txt
+ COMMAND ${CMAKE_COMMAND} -E echo "Example Document Target" > doc1.txt
+ DEPENDS doc1.tex
+ VERBATIM
+ )
+
+# Add a custom target to drive generation of doc1.h.
+ADD_CUSTOM_TARGET(TDocument ALL
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1.h to doc2.h."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1.h
+ ${PROJECT_BINARY_DIR}/doc2.h
+ DEPENDS doc1.txt ${PROJECT_BINARY_DIR}//doc1.h # test 2 slashes
+ COMMENT "Running top-level TDocument commands"
+ SOURCES doc1.tex
+ )
+
+# Setup a pre- and post-build pair that will fail if not run in the
+# proper order.
+ADD_CUSTOM_COMMAND(
+ TARGET TDocument PRE_BUILD
+ COMMAND ${CMAKE_COMMAND} -E echo " Writing doc1pre.txt."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/doc1.tex ${PROJECT_BINARY_DIR}/doc1pre.txt
+ COMMENT "Running TDocument pre-build commands"
+ )
+ADD_CUSTOM_COMMAND(
+ TARGET TDocument POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E echo " Copying doc1pre.txt to doc2post.txt."
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/doc1pre.txt
+ ${PROJECT_BINARY_DIR}/doc2post.txt
+ COMMENT "Running TDocument post-build commands"
+ )
+
+################################################################
+#
+# Test using a multistep generated file
+#
+################################################################
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/foo.pre
+ DEPENDS ${PROJECT_SOURCE_DIR}/foo.in
+ TDocument # Ensure doc1.h generates before this target
+ 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 ${PROJECT_BINARY_DIR}/foo.pre
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${PROJECT_BINARY_DIR}/foo.pre
+ ${PROJECT_BINARY_DIR}/foo.c
+ )
+
+# Add custom command to generate not_included.h, which is a header
+# file that is not included by any source in this project. This will
+# test whether all custom command outputs explicitly listed as sources
+# get generated even if they are not needed by an object file.
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/not_included.h
+ DEPENDS ${PROJECT_SOURCE_DIR}/foo.h.in
+ COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/foo.h.in
+ ${PROJECT_BINARY_DIR}/not_included.h
+ )
+
+# Tell the executable where to find not_included.h.
+CONFIGURE_FILE(
+ ${PROJECT_SOURCE_DIR}/config.h.in
+ ${PROJECT_BINARY_DIR}/config.h
+ @ONLY IMMEDIATE
+ )
+
+# add the executable
+ADD_EXECUTABLE(CustomCommand
+ ${PROJECT_BINARY_DIR}/foo.h
+ ${PROJECT_BINARY_DIR}/foo.c
+ ${PROJECT_BINARY_DIR}/wrapped.c
+ ${PROJECT_BINARY_DIR}/wrapped_help.c
+ ${PROJECT_BINARY_DIR}/generated.c
+ ${PROJECT_BINARY_DIR}/not_included.h
+ gen_redirect.c # default location for custom commands is in build tree
+ )
+
+# Add the rule to create generated.c at build time. This is placed
+# here to test adding the generation rule after referencing the
+# generated source in a target.
+ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_BINARY_DIR}/generated.c
+ DEPENDS generator
+ COMMAND ${generator_PATH}
+ ARGS ${PROJECT_BINARY_DIR}/generated.c
+ )
+
+TARGET_LINK_LIBRARIES(CustomCommand GeneratedHeader)
+
+##############################################################################
+# Test for using just the target name as executable in the COMMAND
+# section. Has to be recognized and replaced by CMake with the output
+# actual location of the executable.
+# Additionally the generator is created in an extra subdir after the
+# ADD_CUSTOM_COMMAND() is used.
+#
+# Test the same for ADD_CUSTOM_TARGET()
+
+ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx
+ COMMAND generator_extern ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx
+ )
+
+ADD_EXECUTABLE(CustomCommandUsingTargetTest main.cxx ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx )
+
+ADD_CUSTOM_TARGET(RunTarget
+ COMMAND generator_extern ${CMAKE_CURRENT_BINARY_DIR}/run_target.cxx
+ )
+
+ADD_CUSTOM_COMMAND(TARGET CustomCommandUsingTargetTest POST_BUILD
+ COMMAND dummy_generator ${CMAKE_CURRENT_BINARY_DIR}/generated_dummy.cxx)
+
+ADD_SUBDIRECTORY(GeneratorInExtraDir)
+
+##############################################################################
+# Test shell operators in custom commands.
+
+ADD_EXECUTABLE(tcat tcat.cxx)
+
+ADD_CUSTOM_COMMAND(OUTPUT gen_redirect.c
+ DEPENDS tcat gen_redirect_in.c
+ COMMAND tcat < ${CMAKE_CURRENT_SOURCE_DIR}/gen_redirect_in.c > gen_redirect.c
+ COMMAND ${CMAKE_COMMAND} -E echo "#endif" >> gen_redirect.c
+ VERBATIM
+ )
+
+##############################################################################
+# Test non-trivial command line arguments in custom commands.
+SET(EXPECTED_ARGUMENTS)
+SET(CHECK_ARGS)
+IF(NOT MSVC71)
+ SET(CHECK_ARGS -DPATH=c:/posix/path)
+ENDIF()
+SET(CHECK_ARGS
+ ${CHECK_ARGS}
+ c:/posix/path
+ c:\\windows\\path
+ 'single-quotes'
+ single'quote
+ \"double-quotes\"
+ "\\;semi-colons\\;"
+ "semi\\;colon"
+ `back-ticks`
+ back`tick
+ "(parens)"
+ "(lparen"
+ "rparen)"
+ {curly}
+ {lcurly}
+ rcurly}
+ <angle>
+ <langle
+ rangle>
+ [square]
+ [lsquare # these have funny behavior due to special cases for
+ rsquare] # windows registry value names in list expansion
+ $dollar-signs$
+ dollar$sign
+ &ampersands&x # Borland make does not like trailing ampersand
+ one&ampersand
+ @two-ats@
+ one@at
+ ~two-tilda~
+ one~tilda
+ ^two-carrots^
+ one^carrot
+ %two-percents%
+ one%percent
+ !two-exclamations!
+ one!exclamation
+ ?two-questions?
+ one?question
+ *two-stars*
+ one*star
+ =two+equals=
+ one=equals
+ _two-underscores_
+ one_underscore
+ ,two-commas,
+ one,comma
+ .two-periods.
+ one.period
+ |two-pipes|
+ one|pipe
+ |nopipe
+ "#two-pounds#"
+ "one#pound"
+ "#nocomment"
+ "c:/posix/path/with space"
+ "c:\\windows\\path\\with space"
+ "'single quotes with space'"
+ "single'quote with space"
+ "\"double-quotes with space\""
+ "\\;semi-colons w s\\;"
+ "semi\\;colon w s"
+ "`back-ticks` w s"
+ "back`tick w s"
+ "(parens) w s"
+ "(lparen w s"
+ "rparen) w s"
+ "{curly} w s"
+ "{lcurly w s"
+ "rcurly} w s"
+ "<angle> w s"
+ "<langle w s"
+ "rangle> w s"
+ "[square] w s"
+ "[lsquare w s" # these have funny behavior due to special cases for
+ "rsquare] w s" # windows registry value names in list expansion
+ "$dollar-signs$ w s"
+ "dollar$sign w s"
+ "&ampersands& w s"
+ "one&ampersand w s"
+ "@two-ats@ w s"
+ "one@at w s"
+ "~two-tilda~ w s"
+ "one~tilda w s"
+ "^two-carrots^ w s"
+ "one^carrot w s"
+ "%two-percents% w s"
+ "one%percent w s"
+ "!two-exclamations! w s"
+ "one!exclamation w s"
+ "*two-stars* w s"
+ "one*star w s"
+ "=two+equals= w s"
+ "one=equals w s"
+ "_two-underscores_ w s"
+ "one_underscore w s"
+ "?two-questions? w s"
+ "one?question w s"
+ ",two-commas, w s"
+ "one,comma w s"
+ ".two-periods. w s"
+ "one.period w s"
+ "|two-pipes| w s"
+ "one|pipe w s"
+ "#two-pounds# w s"
+ "one#pound w s"
+ ~ ` ! @ \# $ % ^ & _ - + = : "\;" \" ' , . ? "(" ")" { } []
+ )
+IF(NOT MINGW)
+ # * # MinGW programs on windows always expands the wildcard!
+ # / # MSys make converts a leading slash to the mingw home directory
+ LIST(APPEND CHECK_ARGS * /)
+ENDIF(NOT MINGW)
+
+# The windows command shell does not support a double quote by itself:
+# double\"quote
+# without messing up quoting of arguments following it.
+
+# Make tools need help with escaping a single backslash
+# \
+# at the end of a command because they think it is a continuation
+# character.
+
+# We now have special cases for shell operators:
+# | < > << >> &> 2>&1 1>&2
+# to allow custom commands to perform redirection.
+
+FOREACH(arg ${CHECK_ARGS} "")
+ SET(ARG "${arg}")
+ STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ARG "${ARG}")
+ STRING(REGEX REPLACE "\"" "\\\\\"" ARG "${ARG}")
+ SET(EXPECTED_ARGUMENTS
+ "${EXPECTED_ARGUMENTS} \"${ARG}\",
+")
+ENDFOREACH(arg)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/check_command_line.c.in
+ ${CMAKE_CURRENT_BINARY_DIR}/check_command_line.c
+ @ONLY IMMEDIATE)
+ADD_EXECUTABLE(check_command_line
+ ${CMAKE_CURRENT_BINARY_DIR}/check_command_line.c)
+SET(output_name "check_command_line")
+SET_PROPERTY(TARGET check_command_line
+ PROPERTY OUTPUT_NAME ${output_name})
+# SET_TARGET_PROPERTIES(check_command_line PROPERTIES
+# COMPILE_FLAGS -DCHECK_COMMAND_LINE_VERBOSE)
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/command_line_check
+ COMMAND ${CMAKE_COMMAND} -DMARK_FILE=${CMAKE_CURRENT_BINARY_DIR}/check_mark.txt
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check_mark.cmake
+ COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${output_name}
+ ${CHECK_ARGS} ""
+ VERBATIM
+ COMMENT "Checking custom command line escapes (single'quote)"
+ )
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/command_line_check
+ PROPERTIES SYMBOLIC 1)
+ADD_CUSTOM_TARGET(do_check_command_line ALL
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/command_line_check
+ COMMAND ${CMAKE_COMMAND} -E echo "Checking custom target command escapes"
+ COMMAND ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${output_name}
+ ${CHECK_ARGS} ""
+ VERBATIM
+ COMMENT "Checking custom target command line escapes ($dollar-signs$)"
+ )
+ADD_DEPENDENCIES(do_check_command_line check_command_line)
+
+ADD_CUSTOM_TARGET(pre_check_command_line
+ COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/check_mark.txt
+ )
+ADD_DEPENDENCIES(do_check_command_line pre_check_command_line)
+
+# <SameNameTest>
+#
+# Add a custom target called "SameName" -- then add a custom command in a
+# different target whose output is a full-path file called "SameName" -- then
+# add a second custom target that depends on the full-path file ".../SameName"
+#
+# At first, this reproduces a bug reported by a customer. After fixing it,
+# having this test here makes sure it stays fixed moving forward.
+#
+ADD_CUSTOM_COMMAND(
+ OUTPUT SameName1.txt
+ COMMAND ${CMAKE_COMMAND} -E touch SameName1.txt
+ )
+ADD_CUSTOM_TARGET(SameName ALL
+ DEPENDS SameName1.txt
+ )
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/subdir/SameName
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/subdir
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/subdir/SameName
+ )
+ADD_CUSTOM_TARGET(DifferentName ALL
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/subdir/SameName
+ )
+#
+# </SameNameTest>
+
+# Per-config target name and generator expressions.
+ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../PerConfig PerConfig)
+ADD_CUSTOM_COMMAND(
+ OUTPUT perconfig.out
+ COMMAND ${PerConfig_COMMAND}
+ DEPENDS ${PerConfig_DEPENDS}
+ VERBATIM
+ )
+SET_PROPERTY(SOURCE perconfig.out PROPERTY SYMBOLIC 1)
+ADD_CUSTOM_TARGET(perconfig_target ALL
+ COMMAND ${CMAKE_COMMAND} -E echo "perconfig=$<TARGET_FILE:perconfig>" "config=$<CONFIGURATION>"
+ DEPENDS perconfig.out)
diff --git a/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt b/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt
new file mode 100644
index 000000000..2d47d8749
--- /dev/null
+++ b/Tests/CustomCommand/GeneratedHeader/CMakeLists.txt
@@ -0,0 +1,13 @@
+# Simulate in-source build include-file behavior for out-of-source
+# builds.
+SET(CMAKE_INCLUDE_CURRENT_DIR 1)
+
+ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ COMMAND
+ ${CMAKE_COMMAND} ARGS -E
+ copy ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+)
+
+ADD_LIBRARY(GeneratedHeader main.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated.h)
+
diff --git a/Tests/CustomCommand/GeneratedHeader/generated.h.in b/Tests/CustomCommand/GeneratedHeader/generated.h.in
new file mode 100644
index 000000000..ae6f64c1c
--- /dev/null
+++ b/Tests/CustomCommand/GeneratedHeader/generated.h.in
@@ -0,0 +1 @@
+//hello
diff --git a/Tests/CustomCommand/GeneratedHeader/main.cpp b/Tests/CustomCommand/GeneratedHeader/main.cpp
new file mode 100644
index 000000000..0b43ffe83
--- /dev/null
+++ b/Tests/CustomCommand/GeneratedHeader/main.cpp
@@ -0,0 +1,5 @@
+#include "generated.h"
+int mainGeneratedHeader()
+{
+ return 0;
+}
diff --git a/Tests/CustomCommand/GeneratorInExtraDir/CMakeLists.txt b/Tests/CustomCommand/GeneratorInExtraDir/CMakeLists.txt
new file mode 100644
index 000000000..195a47792
--- /dev/null
+++ b/Tests/CustomCommand/GeneratorInExtraDir/CMakeLists.txt
@@ -0,0 +1,8 @@
+ADD_DEFINITIONS(-DGENERATOR_EXTERN)
+
+# add the executable which will be used for generating files
+ADD_EXECUTABLE(generator_extern ../generator.cxx)
+SET_TARGET_PROPERTIES(generator_extern PROPERTIES OUTPUT_NAME the_external_generator)
+
+# add an executable which will be called from ADD_CUSTOM_COMMAND( ... POST_BUILD)
+ADD_EXECUTABLE(dummy_generator ../generator.cxx)
diff --git a/Tests/CustomCommand/check_command_line.c.in b/Tests/CustomCommand/check_command_line.c.in
new file mode 100644
index 000000000..e0e0d2142
--- /dev/null
+++ b/Tests/CustomCommand/check_command_line.c.in
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <string.h>
+
+const char* expected_arguments[] =
+{
+@EXPECTED_ARGUMENTS@ 0
+};
+
+int main(int argc, const char* argv[])
+{
+ const char** a = argv+1;
+ const char** e = expected_arguments;
+ (void)argc;
+ for(;*a && *e; ++a, ++e)
+ {
+ if(strcmp(*a, *e) != 0)
+ {
+ fprintf(stderr, "Argument [%s] does not match expected [%s].\n",
+ *a, *e);
+ return 1;
+ }
+ else
+ {
+#if defined(CHECK_COMMAND_LINE_VERBOSE)
+ printf("[%s]\n", *a);
+#endif
+ }
+ }
+ if(*a || *e)
+ {
+ fprintf(stderr, "Number of arguments does not match expected.\n");
+ return 1;
+ }
+ printf("Command line escapes work!\n");
+ return 0;
+}
diff --git a/Tests/CustomCommand/check_mark.cmake b/Tests/CustomCommand/check_mark.cmake
new file mode 100644
index 000000000..8b0551f83
--- /dev/null
+++ b/Tests/CustomCommand/check_mark.cmake
@@ -0,0 +1,5 @@
+IF(EXISTS "${MARK_FILE}")
+ MESSAGE(FATAL_ERROR "Custom command run more than once!")
+ELSE(EXISTS "${MARK_FILE}")
+ FILE(WRITE "${MARK_FILE}" "check for running custom command twice\n")
+ENDIF(EXISTS "${MARK_FILE}")
diff --git a/Tests/CustomCommand/config.h.in b/Tests/CustomCommand/config.h.in
new file mode 100644
index 000000000..86c97bd95
--- /dev/null
+++ b/Tests/CustomCommand/config.h.in
@@ -0,0 +1 @@
+#define PROJECT_BINARY_DIR "@PROJECT_BINARY_DIR@"
diff --git a/Tests/CustomCommand/doc1.tex b/Tests/CustomCommand/doc1.tex
new file mode 100644
index 000000000..e6b6ccbe5
--- /dev/null
+++ b/Tests/CustomCommand/doc1.tex
@@ -0,0 +1 @@
+int doc() { return 7;}
diff --git a/Tests/CustomCommand/foo.h.in b/Tests/CustomCommand/foo.h.in
new file mode 100644
index 000000000..d7721a2a5
--- /dev/null
+++ b/Tests/CustomCommand/foo.h.in
@@ -0,0 +1 @@
+/* Empty header file just used to test header generation. */
diff --git a/Tests/CustomCommand/foo.in b/Tests/CustomCommand/foo.in
new file mode 100644
index 000000000..08c559df4
--- /dev/null
+++ b/Tests/CustomCommand/foo.in
@@ -0,0 +1,28 @@
+#include "doc1.h"
+#include "foo.h"
+#include "config.h"
+
+#include <stdio.h>
+
+int generated();
+int wrapped();
+
+int main ()
+{
+ if (generated()*wrapped()*doc() == 3*5*7)
+ {
+ FILE* fin = fopen(PROJECT_BINARY_DIR "/not_included.h", "r");
+ if(fin)
+ {
+ fclose(fin);
+ return 0;
+ }
+ else
+ {
+ return -2;
+ }
+ }
+
+ return -1;
+}
+
diff --git a/Tests/CustomCommand/gen_redirect_in.c b/Tests/CustomCommand/gen_redirect_in.c
new file mode 100644
index 000000000..8dd8f43f0
--- /dev/null
+++ b/Tests/CustomCommand/gen_redirect_in.c
@@ -0,0 +1,5 @@
+#if 1
+
+int gen_redirect() { return 3; }
+
+/* endif should be concatenated to generated file */
diff --git a/Tests/CustomCommand/generator.cxx b/Tests/CustomCommand/generator.cxx
new file mode 100644
index 000000000..cceac073a
--- /dev/null
+++ b/Tests/CustomCommand/generator.cxx
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ if ( argc < 2 )
+ {
+ fprintf(stderr, "Usage: %s <file>\n", argv[0]);
+ return 1;
+ }
+ FILE *fp = fopen(argv[1],"w");
+#ifdef GENERATOR_EXTERN
+ fprintf(fp,"int generated() { return 3; }\n");
+#else
+ fprintf(fp,"extern int gen_redirect(void);\n");
+ fprintf(fp,"int generated() { return gen_redirect(); }\n");
+#endif
+ fclose(fp);
+ return 0;
+}
diff --git a/Tests/CustomCommand/main.cxx b/Tests/CustomCommand/main.cxx
new file mode 100644
index 000000000..600e751dd
--- /dev/null
+++ b/Tests/CustomCommand/main.cxx
@@ -0,0 +1,6 @@
+extern int generated();
+
+int main()
+{
+ return generated();
+}
diff --git a/Tests/CustomCommand/tcat.cxx b/Tests/CustomCommand/tcat.cxx
new file mode 100644
index 000000000..89e3cb0a2
--- /dev/null
+++ b/Tests/CustomCommand/tcat.cxx
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int main()
+{
+ int c;
+ while((c = getc(stdin), c != EOF))
+ {
+ putc(c, stdout);
+ }
+ return 0;
+}
diff --git a/Tests/CustomCommand/wrapped.h b/Tests/CustomCommand/wrapped.h
new file mode 100644
index 000000000..fa882cb5b
--- /dev/null
+++ b/Tests/CustomCommand/wrapped.h
@@ -0,0 +1 @@
+/* empty file */
diff --git a/Tests/CustomCommand/wrapper.cxx b/Tests/CustomCommand/wrapper.cxx
new file mode 100644
index 000000000..93cb079fe
--- /dev/null
+++ b/Tests/CustomCommand/wrapper.cxx
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+ if ( argc < 3 )
+ {
+ fprintf(stderr, "Usage: %s <file1> <file2>\n", argv[0]);
+ return 1;
+ }
+ FILE *fp = fopen(argv[1],"w");
+ fprintf(fp,"extern int wrapped_help();\n");
+ fprintf(fp,"int wrapped() { return wrapped_help(); }\n");
+ fclose(fp);
+ fp = fopen(argv[2],"w");
+ fprintf(fp,"int wrapped_help() { return 5; }\n");
+ fclose(fp);
+#ifdef CMAKE_INTDIR
+ /* The VS6 IDE passes a leading ".\\" in its variable expansion. */
+# if defined(_MSC_VER) && _MSC_VER == 1200
+# define CFG_DIR ".\\" CMAKE_INTDIR
+# else
+# define CFG_DIR CMAKE_INTDIR
+# endif
+ const char* cfg = (argc >= 4)? argv[3] : "";
+ if(strcmp(cfg, CFG_DIR) != 0)
+ {
+ fprintf(stderr,
+ "Did not receive expected configuration argument:\n"
+ " expected [" CFG_DIR "]\n"
+ " received [%s]\n", cfg);
+ return 1;
+ }
+#endif
+ return 0;
+}