summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorJuan Ramos <juan.ramos@kitware.com>2024-05-28 03:19:05 (GMT)
committerBrad King <brad.king@kitware.com>2024-07-01 16:02:49 (GMT)
commit197cb419d13d5dbb704be97bd3ee04ce514fa58f (patch)
tree7fae6062e544659541c9dd97946ada61fe1c7310 /Tests
parent033713530a077893be93e52ef577205cb8466b9d (diff)
downloadCMake-197cb419d13d5dbb704be97bd3ee04ce514fa58f.zip
CMake-197cb419d13d5dbb704be97bd3ee04ce514fa58f.tar.gz
CMake-197cb419d13d5dbb704be97bd3ee04ce514fa58f.tar.bz2
add_custom_command: Add CODEGEN support
By specifying CODEGEN as an argument to add_custom_command the custom command will be added to a codegen build target. The intent is to provide a convenient way for users to get their generated files without having to build the whole project. This can be helpful for code analysis tools which can be useful for IDEs and CI.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-NEW-result.txt1
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-NEW-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-NEW.cmake6
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-OLD-result.txt1
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-OLD-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-OLD.cmake9
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-WARN-stderr.txt9
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-WARN.cmake6
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-codegen-build-result.txt1
-rw-r--r--Tests/RunCMake/CMP0171/CMP0171-codegen.cmake0
-rw-r--r--Tests/RunCMake/CMP0171/CMakeLists.txt6
-rw-r--r--Tests/RunCMake/CMP0171/RunCMakeTest.cmake18
-rw-r--r--Tests/RunCMake/CMakeLists.txt4
-rw-r--r--Tests/RunCMake/Codegen/CMakeLists.txt7
-rw-r--r--Tests/RunCMake/Codegen/RunCMakeTest.cmake33
-rw-r--r--Tests/RunCMake/Codegen/add-custom-command-depends-build-check.cmake5
-rw-r--r--Tests/RunCMake/Codegen/add-custom-command-depends.cmake16
-rw-r--r--Tests/RunCMake/Codegen/add-dependencies-build-check.cmake5
-rw-r--r--Tests/RunCMake/Codegen/add-dependencies.cmake18
-rw-r--r--Tests/RunCMake/Codegen/append-implicit-depends-result.txt1
-rw-r--r--Tests/RunCMake/Codegen/append-implicit-depends-stderr.txt2
-rw-r--r--Tests/RunCMake/Codegen/append-implicit-depends.cmake19
-rw-r--r--Tests/RunCMake/Codegen/byproducts-build-check.cmake5
-rw-r--r--Tests/RunCMake/Codegen/byproducts.cmake19
-rw-r--r--Tests/RunCMake/Codegen/error.c1
-rw-r--r--Tests/RunCMake/Codegen/exclude-from-all.cmake11
-rw-r--r--Tests/RunCMake/Codegen/generated.h.in1
-rw-r--r--Tests/RunCMake/Codegen/implicit-depends-append-codegen-result.txt1
-rw-r--r--Tests/RunCMake/Codegen/implicit-depends-append-codegen-stderr.txt4
-rw-r--r--Tests/RunCMake/Codegen/implicit-depends-append-codegen.cmake18
-rw-r--r--Tests/RunCMake/Codegen/implicit-depends-result.txt1
-rw-r--r--Tests/RunCMake/Codegen/implicit-depends-stderr.txt4
-rw-r--r--Tests/RunCMake/Codegen/implicit-depends.cmake11
-rw-r--r--Tests/RunCMake/Codegen/main.c4
-rw-r--r--Tests/RunCMake/Codegen/min-graph-1-build-check.cmake13
-rw-r--r--Tests/RunCMake/Codegen/min-graph-1.cmake26
-rw-r--r--Tests/RunCMake/Codegen/min-graph-2-build-check.cmake5
-rw-r--r--Tests/RunCMake/Codegen/min-graph-2.cmake18
-rw-r--r--Tests/RunCMake/Codegen/min-graph-3-build-check.cmake5
-rw-r--r--Tests/RunCMake/Codegen/min-graph-3.cmake12
-rw-r--r--Tests/RunCMake/Codegen/no-codegen-check.cmake5
-rw-r--r--Tests/RunCMake/Codegen/no-codegen.cmake6
-rw-r--r--Tests/RunCMake/Codegen/no-output-result.txt1
-rw-r--r--Tests/RunCMake/Codegen/no-output-stderr.txt4
-rw-r--r--Tests/RunCMake/Codegen/no-output.cmake11
45 files changed, 360 insertions, 1 deletions
diff --git a/Tests/RunCMake/CMP0171/CMP0171-NEW-result.txt b/Tests/RunCMake/CMP0171/CMP0171-NEW-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0171/CMP0171-NEW-stderr.txt b/Tests/RunCMake/CMP0171/CMP0171-NEW-stderr.txt
new file mode 100644
index 0000000..155ddd2
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0171-NEW\.cmake:[0-9]+ \(add_custom_target\):
+ The target name "codegen" is reserved\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CMP0171/CMP0171-NEW.cmake b/Tests/RunCMake/CMP0171/CMP0171-NEW.cmake
new file mode 100644
index 0000000..547f6c0
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-NEW.cmake
@@ -0,0 +1,6 @@
+# codegen is now a reserved name and this will cause an error since the policy is new.
+add_custom_target(codegen
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+)
diff --git a/Tests/RunCMake/CMP0171/CMP0171-OLD-result.txt b/Tests/RunCMake/CMP0171/CMP0171-OLD-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-OLD-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0171/CMP0171-OLD-stderr.txt b/Tests/RunCMake/CMP0171/CMP0171-OLD-stderr.txt
new file mode 100644
index 0000000..1ae3318
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-OLD-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0171-OLD\.cmake:[0-9]+ \(add_custom_command\):
+ add_custom_command CODEGEN option requires policy CMP0171 be set to NEW\!
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CMP0171/CMP0171-OLD.cmake b/Tests/RunCMake/CMP0171/CMP0171-OLD.cmake
new file mode 100644
index 0000000..c34b3fb
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-OLD.cmake
@@ -0,0 +1,9 @@
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp
+ # This will cause an error since the CODEGEN option
+ # requires that CMP0171 is set to NEW
+ CODEGEN
+)
diff --git a/Tests/RunCMake/CMP0171/CMP0171-WARN-stderr.txt b/Tests/RunCMake/CMP0171/CMP0171-WARN-stderr.txt
new file mode 100644
index 0000000..ee79553
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-WARN-stderr.txt
@@ -0,0 +1,9 @@
+CMake Warning \(dev\) at CMP0171-WARN\.cmake:[0-9]+ \(add_custom_target\):
+ Policy CMP0171 is not set: 'codegen' is a reserved target name\. Run "cmake
+ --help-policy CMP0171" for policy details. Use the cmake_policy command to
+ set the policy and suppress this warning\.
+
+ The target name "codegen" is reserved\.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
+This warning is for project developers\. Use -Wno-dev to suppress it\.
diff --git a/Tests/RunCMake/CMP0171/CMP0171-WARN.cmake b/Tests/RunCMake/CMP0171/CMP0171-WARN.cmake
new file mode 100644
index 0000000..6d61723
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-WARN.cmake
@@ -0,0 +1,6 @@
+# CMake should warn the user if they have a target named codegen.
+add_custom_target(codegen
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+)
diff --git a/Tests/RunCMake/CMP0171/CMP0171-codegen-build-result.txt b/Tests/RunCMake/CMP0171/CMP0171-codegen-build-result.txt
new file mode 100644
index 0000000..d197c91
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-codegen-build-result.txt
@@ -0,0 +1 @@
+[^0]
diff --git a/Tests/RunCMake/CMP0171/CMP0171-codegen.cmake b/Tests/RunCMake/CMP0171/CMP0171-codegen.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMP0171-codegen.cmake
diff --git a/Tests/RunCMake/CMP0171/CMakeLists.txt b/Tests/RunCMake/CMP0171/CMakeLists.txt
new file mode 100644
index 0000000..1a5755c
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 3.29)
+project(${RunCMake_TEST} LANGUAGES C)
+
+include(${RunCMake_TEST}.cmake)
+
+enable_testing()
diff --git a/Tests/RunCMake/CMP0171/RunCMakeTest.cmake b/Tests/RunCMake/CMP0171/RunCMakeTest.cmake
new file mode 100644
index 0000000..75941d7
--- /dev/null
+++ b/Tests/RunCMake/CMP0171/RunCMakeTest.cmake
@@ -0,0 +1,18 @@
+include(RunCMake)
+
+run_cmake("CMP0171-WARN")
+
+run_cmake_with_options(CMP0171-OLD "-DCMAKE_POLICY_DEFAULT_CMP0171=OLD")
+
+run_cmake_with_options(CMP0171-NEW "-DCMAKE_POLICY_DEFAULT_CMP0171=NEW")
+
+# The entire point of this test is to ensure the codegen target is not created
+# unintentionally. It can only be created if CMP0171 is NEW.
+block()
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0171-codegen-build)
+ run_cmake(CMP0171-codegen)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_OUTPUT_MERGE 1)
+ # This command will fail with either 1 or 2 depending.
+ run_cmake_command(CMP0171-codegen-build ${CMAKE_COMMAND} --build . --config Debug --target codegen)
+endblock()
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index bfa59d6..db5ef96 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -180,6 +180,7 @@ add_RunCMake_test(CMP0163)
add_RunCMake_test(CMP0165)
add_RunCMake_test(CMP0169)
add_RunCMake_test(CMP0170)
+add_RunCMake_test(CMP0171)
# The test for Policy 65 requires the use of the
# CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode
@@ -1228,7 +1229,8 @@ add_RunCMake_test(CMakePresetsWorkflow
add_RunCMake_test(VerifyHeaderSets)
add_RunCMake_test(set_tests_properties)
-if(${CMAKE_GENERATOR} MATCHES "Make|Ninja")
+if(CMAKE_GENERATOR MATCHES "Make|Ninja")
+ add_RunCMake_test(Codegen)
add_RunCMake_test(TransformDepfile)
endif()
diff --git a/Tests/RunCMake/Codegen/CMakeLists.txt b/Tests/RunCMake/Codegen/CMakeLists.txt
new file mode 100644
index 0000000..f65150d
--- /dev/null
+++ b/Tests/RunCMake/Codegen/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.29)
+project(${RunCMake_TEST} LANGUAGES C)
+
+# This value is read from the top level CMakeLists.txt
+cmake_policy(SET CMP0171 NEW)
+
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/Codegen/RunCMakeTest.cmake b/Tests/RunCMake/Codegen/RunCMakeTest.cmake
new file mode 100644
index 0000000..bbd70b0
--- /dev/null
+++ b/Tests/RunCMake/Codegen/RunCMakeTest.cmake
@@ -0,0 +1,33 @@
+include(RunCMake)
+
+function(run_codegen case)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build)
+
+ run_cmake(${case})
+
+ set(RunCMake_TEST_NO_CLEAN 1)
+
+ run_cmake_command(${case}-build ${CMAKE_COMMAND} --build . --target codegen --config Debug)
+endfunction()
+
+# Builds codegen target when there are no custom commands marked codegen
+run_codegen("no-codegen")
+
+# We don't want codegen to drive parts of the project that are EXCLUDE_FROM_ALL
+run_codegen("exclude-from-all")
+
+# Ensures codegen builds minimal build graphs
+run_codegen("min-graph-1")
+run_codegen("min-graph-2")
+run_codegen("min-graph-3")
+
+# Handle specific cases that can affect codegen
+run_codegen("add-dependencies")
+run_codegen("add-custom-command-depends")
+run_codegen("byproducts")
+
+# Error handling
+run_cmake("implicit-depends")
+run_cmake("implicit-depends-append-codegen")
+run_cmake("append-implicit-depends")
+run_cmake("no-output")
diff --git a/Tests/RunCMake/Codegen/add-custom-command-depends-build-check.cmake b/Tests/RunCMake/Codegen/add-custom-command-depends-build-check.cmake
new file mode 100644
index 0000000..d371d73
--- /dev/null
+++ b/Tests/RunCMake/Codegen/add-custom-command-depends-build-check.cmake
@@ -0,0 +1,5 @@
+set(filename "${RunCMake_TEST_BINARY_DIR}/generated.hpp")
+if (NOT EXISTS "${filename}")
+ set(RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}")
+ return()
+endif()
diff --git a/Tests/RunCMake/Codegen/add-custom-command-depends.cmake b/Tests/RunCMake/Codegen/add-custom-command-depends.cmake
new file mode 100644
index 0000000..793ab5f
--- /dev/null
+++ b/Tests/RunCMake/Codegen/add-custom-command-depends.cmake
@@ -0,0 +1,16 @@
+add_custom_target(foobar
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+)
+
+add_custom_command(
+ OUTPUT generated.hpp
+ # This test will fail if DEPENDS isn't accounted for in the codegen build graph
+ DEPENDS foobar
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp
+ CODEGEN
+)
+
+add_custom_target(hpp_creator ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp)
diff --git a/Tests/RunCMake/Codegen/add-dependencies-build-check.cmake b/Tests/RunCMake/Codegen/add-dependencies-build-check.cmake
new file mode 100644
index 0000000..d371d73
--- /dev/null
+++ b/Tests/RunCMake/Codegen/add-dependencies-build-check.cmake
@@ -0,0 +1,5 @@
+set(filename "${RunCMake_TEST_BINARY_DIR}/generated.hpp")
+if (NOT EXISTS "${filename}")
+ set(RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}")
+ return()
+endif()
diff --git a/Tests/RunCMake/Codegen/add-dependencies.cmake b/Tests/RunCMake/Codegen/add-dependencies.cmake
new file mode 100644
index 0000000..fbb7e99
--- /dev/null
+++ b/Tests/RunCMake/Codegen/add-dependencies.cmake
@@ -0,0 +1,18 @@
+add_custom_target(foobar
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+)
+
+add_custom_command(
+ OUTPUT generated.hpp
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp
+ CODEGEN
+)
+
+add_custom_target(hpp_creator ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp)
+
+# This test will fail if add_dependencies isn't account for in the
+# codegen build graph
+add_dependencies(hpp_creator foobar)
diff --git a/Tests/RunCMake/Codegen/append-implicit-depends-result.txt b/Tests/RunCMake/Codegen/append-implicit-depends-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/Codegen/append-implicit-depends-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Codegen/append-implicit-depends-stderr.txt b/Tests/RunCMake/Codegen/append-implicit-depends-stderr.txt
new file mode 100644
index 0000000..c8ef03e
--- /dev/null
+++ b/Tests/RunCMake/Codegen/append-implicit-depends-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error:
+ Cannot append IMPLICIT_DEPENDS to existing CODEGEN custom command\.
diff --git a/Tests/RunCMake/Codegen/append-implicit-depends.cmake b/Tests/RunCMake/Codegen/append-implicit-depends.cmake
new file mode 100644
index 0000000..d212fe5
--- /dev/null
+++ b/Tests/RunCMake/Codegen/append-implicit-depends.cmake
@@ -0,0 +1,19 @@
+add_custom_command(
+ OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
+ COMMAND
+ ${CMAKE_COMMAND} -E
+ copy ${CMAKE_CURRENT_SOURCE_DIR}/error.c
+ ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
+ CODEGEN
+)
+
+add_custom_command(
+ OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
+
+ # ERROR out if IMPLICIT_DEPENDS is used with CODEGEN
+ IMPLICIT_DEPENDS C main.c
+
+ APPEND
+)
diff --git a/Tests/RunCMake/Codegen/byproducts-build-check.cmake b/Tests/RunCMake/Codegen/byproducts-build-check.cmake
new file mode 100644
index 0000000..d371d73
--- /dev/null
+++ b/Tests/RunCMake/Codegen/byproducts-build-check.cmake
@@ -0,0 +1,5 @@
+set(filename "${RunCMake_TEST_BINARY_DIR}/generated.hpp")
+if (NOT EXISTS "${filename}")
+ set(RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}")
+ return()
+endif()
diff --git a/Tests/RunCMake/Codegen/byproducts.cmake b/Tests/RunCMake/Codegen/byproducts.cmake
new file mode 100644
index 0000000..ea0b6c7
--- /dev/null
+++ b/Tests/RunCMake/Codegen/byproducts.cmake
@@ -0,0 +1,19 @@
+add_custom_target(foobar
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ BYPRODUCTS
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+)
+
+# This codegen step relies on the BYPRODUCTS of the previous command.
+# If foobar isn't properly accounted for as a dependency it will fail.
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp
+ CODEGEN
+)
+
+add_custom_target(hpp_creator ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp)
diff --git a/Tests/RunCMake/Codegen/error.c b/Tests/RunCMake/Codegen/error.c
new file mode 100644
index 0000000..34cb350
--- /dev/null
+++ b/Tests/RunCMake/Codegen/error.c
@@ -0,0 +1 @@
+#error "This file should not be compiled"
diff --git a/Tests/RunCMake/Codegen/exclude-from-all.cmake b/Tests/RunCMake/Codegen/exclude-from-all.cmake
new file mode 100644
index 0000000..bcd4ac0
--- /dev/null
+++ b/Tests/RunCMake/Codegen/exclude-from-all.cmake
@@ -0,0 +1,11 @@
+add_custom_command(
+ OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ COMMAND
+ ${CMAKE_COMMAND} -E false
+ CODEGEN
+)
+
+# We don't want codegen to drive parts of the project that are EXCLUDE_FROM_ALL.
+# This tests that foobar is properly excluded from the codegen build.
+add_executable(foobar EXCLUDE_FROM_ALL error.c ${CMAKE_CURRENT_BINARY_DIR}/generated.h)
diff --git a/Tests/RunCMake/Codegen/generated.h.in b/Tests/RunCMake/Codegen/generated.h.in
new file mode 100644
index 0000000..82ccf67
--- /dev/null
+++ b/Tests/RunCMake/Codegen/generated.h.in
@@ -0,0 +1 @@
+// hello
diff --git a/Tests/RunCMake/Codegen/implicit-depends-append-codegen-result.txt b/Tests/RunCMake/Codegen/implicit-depends-append-codegen-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/Codegen/implicit-depends-append-codegen-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Codegen/implicit-depends-append-codegen-stderr.txt b/Tests/RunCMake/Codegen/implicit-depends-append-codegen-stderr.txt
new file mode 100644
index 0000000..570cf62
--- /dev/null
+++ b/Tests/RunCMake/Codegen/implicit-depends-append-codegen-stderr.txt
@@ -0,0 +1,4 @@
+^CMake Error at implicit-depends-append-codegen\.cmake:[0-9]+ \(add_custom_command\):
+ add_custom_command CODEGEN may not be used with APPEND\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/Codegen/implicit-depends-append-codegen.cmake b/Tests/RunCMake/Codegen/implicit-depends-append-codegen.cmake
new file mode 100644
index 0000000..76151cc
--- /dev/null
+++ b/Tests/RunCMake/Codegen/implicit-depends-append-codegen.cmake
@@ -0,0 +1,18 @@
+add_custom_command(
+ OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
+
+ # ERROR out if IMPLICIT_DEPENDS is used with CODEGEN
+ IMPLICIT_DEPENDS C main.c
+)
+
+add_custom_command(
+ OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
+ COMMAND
+ ${CMAKE_COMMAND} -E
+ copy ${CMAKE_CURRENT_SOURCE_DIR}/error.c
+ ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
+ CODEGEN
+ APPEND
+)
diff --git a/Tests/RunCMake/Codegen/implicit-depends-result.txt b/Tests/RunCMake/Codegen/implicit-depends-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/Codegen/implicit-depends-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Codegen/implicit-depends-stderr.txt b/Tests/RunCMake/Codegen/implicit-depends-stderr.txt
new file mode 100644
index 0000000..b9ea8f4
--- /dev/null
+++ b/Tests/RunCMake/Codegen/implicit-depends-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at implicit-depends\.cmake:[0-9]+ \(add_custom_command\):
+ add_custom_command CODEGEN is not compatible with IMPLICIT_DEPENDS\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/Codegen/implicit-depends.cmake b/Tests/RunCMake/Codegen/implicit-depends.cmake
new file mode 100644
index 0000000..011d4b3
--- /dev/null
+++ b/Tests/RunCMake/Codegen/implicit-depends.cmake
@@ -0,0 +1,11 @@
+add_custom_command(
+ OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
+ COMMAND
+ ${CMAKE_COMMAND} -E
+ copy ${CMAKE_CURRENT_SOURCE_DIR}/error.c
+ ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
+ CODEGEN
+ # ERROR out if IMPLICIT_DEPENDS is used with CODEGEN
+ IMPLICIT_DEPENDS C main.c
+)
diff --git a/Tests/RunCMake/Codegen/main.c b/Tests/RunCMake/Codegen/main.c
new file mode 100644
index 0000000..8488f4e
--- /dev/null
+++ b/Tests/RunCMake/Codegen/main.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/Codegen/min-graph-1-build-check.cmake b/Tests/RunCMake/Codegen/min-graph-1-build-check.cmake
new file mode 100644
index 0000000..32e1557
--- /dev/null
+++ b/Tests/RunCMake/Codegen/min-graph-1-build-check.cmake
@@ -0,0 +1,13 @@
+set(filename "${RunCMake_TEST_BINARY_DIR}/generated.h")
+if (NOT EXISTS "${filename}")
+ set(RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}")
+ return()
+endif()
+
+# foobar should be built since it was needed
+# by the code generation
+set(filename "${RunCMake_TEST_BINARY_DIR}/foobar.txt")
+if (NOT EXISTS "${filename}")
+ set(RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}")
+ return()
+endif()
diff --git a/Tests/RunCMake/Codegen/min-graph-1.cmake b/Tests/RunCMake/Codegen/min-graph-1.cmake
new file mode 100644
index 0000000..ea47b8f
--- /dev/null
+++ b/Tests/RunCMake/Codegen/min-graph-1.cmake
@@ -0,0 +1,26 @@
+add_executable(foobar main.c)
+add_custom_command(
+ TARGET foobar POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E
+ copy ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/foobar.txt
+)
+
+add_custom_command(
+ OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ COMMAND
+ ${CMAKE_COMMAND} -E
+ copy ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ COMMAND
+ # Generate a header file that requires foobar
+ foobar
+ CODEGEN
+)
+
+add_library(errorlib
+ # If this library is built error.c will cause the build to fail
+ error.c
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+)
diff --git a/Tests/RunCMake/Codegen/min-graph-2-build-check.cmake b/Tests/RunCMake/Codegen/min-graph-2-build-check.cmake
new file mode 100644
index 0000000..fab168b
--- /dev/null
+++ b/Tests/RunCMake/Codegen/min-graph-2-build-check.cmake
@@ -0,0 +1,5 @@
+set(filename "${RunCMake_TEST_BINARY_DIR}/generated.h")
+if (NOT EXISTS "${filename}")
+ set(RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}")
+ return()
+endif()
diff --git a/Tests/RunCMake/Codegen/min-graph-2.cmake b/Tests/RunCMake/Codegen/min-graph-2.cmake
new file mode 100644
index 0000000..277a901
--- /dev/null
+++ b/Tests/RunCMake/Codegen/min-graph-2.cmake
@@ -0,0 +1,18 @@
+add_custom_command(
+ OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ COMMAND
+ ${CMAKE_COMMAND} -E
+ copy ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+ CODEGEN
+)
+
+# This target should not be built. It has no reason
+# to be part of the codegen build graph
+add_custom_target(error_custom_target ALL
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+
+ # Cause the build to fail
+ COMMAND ${CMAKE_COMMAND} -E false
+)
diff --git a/Tests/RunCMake/Codegen/min-graph-3-build-check.cmake b/Tests/RunCMake/Codegen/min-graph-3-build-check.cmake
new file mode 100644
index 0000000..734777b
--- /dev/null
+++ b/Tests/RunCMake/Codegen/min-graph-3-build-check.cmake
@@ -0,0 +1,5 @@
+set(filename "${RunCMake_TEST_BINARY_DIR}/error_lib.c")
+if (NOT EXISTS "${filename}")
+ set(RunCMake_TEST_FAILED "expected file NOT created:\n ${filename}")
+ return()
+endif()
diff --git a/Tests/RunCMake/Codegen/min-graph-3.cmake b/Tests/RunCMake/Codegen/min-graph-3.cmake
new file mode 100644
index 0000000..c7d61dc
--- /dev/null
+++ b/Tests/RunCMake/Codegen/min-graph-3.cmake
@@ -0,0 +1,12 @@
+add_custom_command(
+ OUTPUT
+ ${CMAKE_CURRENT_BINARY_DIR}/error_lib.c
+ COMMAND
+ ${CMAKE_COMMAND} -E
+ copy ${CMAKE_CURRENT_SOURCE_DIR}/error.c
+ ${CMAKE_CURRENT_BINARY_DIR}/error_lib.c
+ CODEGEN
+)
+
+# This test will fail if error_lib.c is actually compiled
+add_executable(foobar ${CMAKE_CURRENT_BINARY_DIR}/error_lib.c)
diff --git a/Tests/RunCMake/Codegen/no-codegen-check.cmake b/Tests/RunCMake/Codegen/no-codegen-check.cmake
new file mode 100644
index 0000000..97fc46b
--- /dev/null
+++ b/Tests/RunCMake/Codegen/no-codegen-check.cmake
@@ -0,0 +1,5 @@
+# Verify generated.hpp was NOT created
+set(unexpected "${RunCMake_TEST_BINARY_DIR}/generated.hpp")
+if(EXISTS "${unexpected}")
+ set(RunCMake_TEST_FAILED "unexpected file created:\n ${unexpected}")
+endif()
diff --git a/Tests/RunCMake/Codegen/no-codegen.cmake b/Tests/RunCMake/Codegen/no-codegen.cmake
new file mode 100644
index 0000000..00ddd03
--- /dev/null
+++ b/Tests/RunCMake/Codegen/no-codegen.cmake
@@ -0,0 +1,6 @@
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.hpp
+)
diff --git a/Tests/RunCMake/Codegen/no-output-result.txt b/Tests/RunCMake/Codegen/no-output-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/Codegen/no-output-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Codegen/no-output-stderr.txt b/Tests/RunCMake/Codegen/no-output-stderr.txt
new file mode 100644
index 0000000..7aad679
--- /dev/null
+++ b/Tests/RunCMake/Codegen/no-output-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at no-output\.cmake:[0-9]+ \(add_custom_command\):
+ add_custom_command CODEGEN requires at least 1 OUTPUT\.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/Codegen/no-output.cmake b/Tests/RunCMake/Codegen/no-output.cmake
new file mode 100644
index 0000000..61eb83c
--- /dev/null
+++ b/Tests/RunCMake/Codegen/no-output.cmake
@@ -0,0 +1,11 @@
+add_custom_target(foobar
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_CURRENT_SOURCE_DIR}/generated.h.in
+ ${CMAKE_CURRENT_BINARY_DIR}/generated.h
+)
+
+add_custom_command(TARGET foobar POST_BUILD
+ COMMAND
+ ${CMAKE_COMMAND} -E true
+ CODEGEN
+)