diff options
Diffstat (limited to 'Tests/CustomCommandByproducts')
-rw-r--r-- | Tests/CustomCommandByproducts/CMakeLists.txt | 103 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/CustomCommandByproducts.c | 21 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/ProducerExe.c | 1 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/byproduct1.c.in | 1 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/byproduct2.c.in | 1 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/byproduct3.c.in | 1 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/byproduct4.c.in | 1 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/byproduct5.c.in | 1 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/byproduct6.c.in | 1 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/byproduct7.c.in | 1 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/byproduct8.c.in | 1 | ||||
-rw-r--r-- | Tests/CustomCommandByproducts/ninja-check.cmake | 20 |
12 files changed, 153 insertions, 0 deletions
diff --git a/Tests/CustomCommandByproducts/CMakeLists.txt b/Tests/CustomCommandByproducts/CMakeLists.txt new file mode 100644 index 0000000..c39a536 --- /dev/null +++ b/Tests/CustomCommandByproducts/CMakeLists.txt @@ -0,0 +1,103 @@ +cmake_minimum_required(VERSION 3.1) +project(CustomCommandByproducts C) + +# Generate a byproduct in a rule that runs in the target consuming it. +add_custom_command( + OUTPUT timestamp1.txt + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct1.c.in byproduct1.c + BYPRODUCTS byproduct1.c + COMMAND ${CMAKE_COMMAND} -E touch timestamp1.txt + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct1.c.in + ) + +# Generate a byproduct in a rule that runs in a dependency of the consumer. +add_custom_command( + OUTPUT timestamp2.txt + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct2.c.in byproduct2.c + BYPRODUCTS byproduct2.c + COMMAND ${CMAKE_COMMAND} -E touch timestamp2.txt + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/byproduct2.c.in + ) +add_custom_target(Producer2 DEPENDS timestamp2.txt) + +# Generate a byproduct in a custom target. +add_custom_target(Producer3_4 + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct3.c.in byproduct3.c + BYPRODUCTS byproduct3.c + ) + +# Generate a byproduct in a custom target POST_BUILD command. +add_custom_command( + TARGET Producer3_4 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct4.c.in byproduct4.c + BYPRODUCTS byproduct4.c + ) + +add_executable(ProducerExe ProducerExe.c) + +# Generate a byproduct in an executable POST_BUILD command. +add_custom_command( + TARGET ProducerExe POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct5.c.in byproduct5.c + BYPRODUCTS byproduct5.c + ) + +# Generate a byproduct in an executable PRE_LINK command. +add_custom_command( + TARGET ProducerExe PRE_LINK + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct6.c.in byproduct6.c + BYPRODUCTS byproduct6.c + ) + +# Generate a byproduct in an executable PRE_BUILD command. +add_custom_command( + TARGET ProducerExe PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct7.c.in byproduct7.c + BYPRODUCTS byproduct7.c + ) + +# Generate a byproduct in a custom command that consumes other byproducts. +add_custom_command(OUTPUT timestamp8.txt + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct8.c.in byproduct8.c + COMMAND ${CMAKE_COMMAND} -E touch timestamp8.txt + BYPRODUCTS byproduct8.c + DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/byproduct2.c + ${CMAKE_CURRENT_BINARY_DIR}/byproduct3.c + ${CMAKE_CURRENT_BINARY_DIR}/byproduct4.c + ${CMAKE_CURRENT_BINARY_DIR}/byproduct5.c + ${CMAKE_CURRENT_BINARY_DIR}/byproduct6.c + ${CMAKE_CURRENT_BINARY_DIR}/byproduct7.c + ${CMAKE_CURRENT_SOURCE_DIR}/byproduct8.c.in + ) + +# Add an executable consuming all the byproducts. +add_executable(CustomCommandByproducts + CustomCommandByproducts.c + byproduct1.c timestamp1.txt + byproduct2.c + byproduct3.c + byproduct4.c + byproduct5.c + byproduct6.c + byproduct7.c + byproduct8.c timestamp8.txt + ) +add_dependencies(CustomCommandByproducts Producer2) +add_dependencies(CustomCommandByproducts Producer3_4) +add_dependencies(CustomCommandByproducts ProducerExe) + +if(CMAKE_GENERATOR STREQUAL "Ninja") + add_custom_target(CheckNinja ALL + COMMENT "Checking build.ninja" + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/ninja-check.cmake + ) +endif() diff --git a/Tests/CustomCommandByproducts/CustomCommandByproducts.c b/Tests/CustomCommandByproducts/CustomCommandByproducts.c new file mode 100644 index 0000000..d9db9e6 --- /dev/null +++ b/Tests/CustomCommandByproducts/CustomCommandByproducts.c @@ -0,0 +1,21 @@ +extern int byproduct1(void); +extern int byproduct2(void); +extern int byproduct3(void); +extern int byproduct4(void); +extern int byproduct5(void); +extern int byproduct6(void); +extern int byproduct7(void); +extern int byproduct8(void); +int main(void) +{ + return ( + byproduct1() + + byproduct2() + + byproduct3() + + byproduct4() + + byproduct5() + + byproduct6() + + byproduct7() + + byproduct8() + + 0); +} diff --git a/Tests/CustomCommandByproducts/ProducerExe.c b/Tests/CustomCommandByproducts/ProducerExe.c new file mode 100644 index 0000000..78f2de1 --- /dev/null +++ b/Tests/CustomCommandByproducts/ProducerExe.c @@ -0,0 +1 @@ +int main(void) { return 0; } diff --git a/Tests/CustomCommandByproducts/byproduct1.c.in b/Tests/CustomCommandByproducts/byproduct1.c.in new file mode 100644 index 0000000..5c3cc24 --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct1.c.in @@ -0,0 +1 @@ +int byproduct1(void) { return 0; } diff --git a/Tests/CustomCommandByproducts/byproduct2.c.in b/Tests/CustomCommandByproducts/byproduct2.c.in new file mode 100644 index 0000000..eeb69ef --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct2.c.in @@ -0,0 +1 @@ +int byproduct2(void) { return 0; } diff --git a/Tests/CustomCommandByproducts/byproduct3.c.in b/Tests/CustomCommandByproducts/byproduct3.c.in new file mode 100644 index 0000000..7d15310 --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct3.c.in @@ -0,0 +1 @@ +int byproduct3(void) { return 0; } diff --git a/Tests/CustomCommandByproducts/byproduct4.c.in b/Tests/CustomCommandByproducts/byproduct4.c.in new file mode 100644 index 0000000..8b243dd --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct4.c.in @@ -0,0 +1 @@ +int byproduct4(void) { return 0; } diff --git a/Tests/CustomCommandByproducts/byproduct5.c.in b/Tests/CustomCommandByproducts/byproduct5.c.in new file mode 100644 index 0000000..47f5990 --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct5.c.in @@ -0,0 +1 @@ +int byproduct5(void) { return 0; } diff --git a/Tests/CustomCommandByproducts/byproduct6.c.in b/Tests/CustomCommandByproducts/byproduct6.c.in new file mode 100644 index 0000000..d70c14f --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct6.c.in @@ -0,0 +1 @@ +int byproduct6(void) { return 0; } diff --git a/Tests/CustomCommandByproducts/byproduct7.c.in b/Tests/CustomCommandByproducts/byproduct7.c.in new file mode 100644 index 0000000..0be5006 --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct7.c.in @@ -0,0 +1 @@ +int byproduct7(void) { return 0; } diff --git a/Tests/CustomCommandByproducts/byproduct8.c.in b/Tests/CustomCommandByproducts/byproduct8.c.in new file mode 100644 index 0000000..abefd62 --- /dev/null +++ b/Tests/CustomCommandByproducts/byproduct8.c.in @@ -0,0 +1 @@ +int byproduct8(void) { return 0; } diff --git a/Tests/CustomCommandByproducts/ninja-check.cmake b/Tests/CustomCommandByproducts/ninja-check.cmake new file mode 100644 index 0000000..2fc3cc2 --- /dev/null +++ b/Tests/CustomCommandByproducts/ninja-check.cmake @@ -0,0 +1,20 @@ +file(READ build.ninja build_ninja) +if("${build_ninja}" MATCHES [====[ +# Unknown Build Time Dependencies. +# Tell Ninja that they may appear as side effects of build rules +# otherwise ordered by order-only dependencies. + +((build [^:]*: phony [^\n]* +)*)# ========]====]) + set(phony "${CMAKE_MATCH_1}") + if(NOT phony) + message(STATUS "build.ninja correctly does not have extra phony rules") + else() + string(REGEX REPLACE "\n+$" "" phony "${phony}") + string(REGEX REPLACE "\n" "\n " phony " ${phony}") + message(FATAL_ERROR "build.ninja incorrectly has extra phony rules:\n" + "${phony}") + endif() +else() + message(FATAL_ERROR "build.ninja is incorrectly missing expected block") +endif() |