summaryrefslogtreecommitdiffstats
path: root/Tests/GhsMulti/GhsMultiCustomTarget/CMakeLists.txt.in
blob: fed946cc5a39e79bfbc2ce874edf36989e71c94a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(test C)

if(CMAKE_C_COMPILER_ID STREQUAL "GHS")
  add_link_options("-non_shared")
endif()

add_library(lib1 lib1.c)

set(TEST_MISSING_TARGET_SRC 0)
set(TEST_MISSING_TARGET_DEP 0)
set(TEST_MISSING_DEP 0)
set(TEST_DEP_CYCLE 0)

add_executable(exe1 exe1.c)
target_link_libraries(exe1 lib1)

add_custom_target(target_cmd ALL
  COMMAND ${CMAKE_COMMAND} -E echo "target_cmd" > target_cmd
  COMMAND ${CMAKE_COMMAND} -E echo "target_cmd_extra" > target_cmd_extra.txt
  BYPRODUCTS target_cmd target_cmd_extra.txt
  COMMENT "CT: Processing target_cmd")

add_custom_command(TARGET target_cmd PRE_BUILD
  COMMAND ${CMAKE_COMMAND} -E echo "target_cmd_prebuild" > target_cmd_prebuild.txt
  BYPRODUCTS target_cmd_prebuild.txt
  COMMENT "CT: Processing target_cmd_prebuild")
#event does not run for custom targets
add_custom_command(TARGET target_cmd PRE_LINK
  COMMAND ${CMAKE_COMMAND} -E echo "executing target_cmd_prelink commands"
  COMMAND ${CMAKE_COMMAND} -E echo "target_cmd_prelink" > target_cmd_prelink.txt
  BYPRODUCTS target_cmd_prelink.txt
  COMMENT "CT: Processing target_cmd_prelink")
add_custom_command(TARGET target_cmd POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E echo "executing target_cmd_postbuild commands"
  COMMAND ${CMAKE_COMMAND} -E echo "target_cmd_postbuild" > target_cmd_postbuild.txt
  BYPRODUCTS target_cmd_postbuild.txt
  COMMENT "CT: Processing target_cmd_postbuild")

add_custom_target(target_empty ALL
  COMMENT "CT: Processing target_empty")

add_custom_command(TARGET target_empty PRE_BUILD
  COMMAND ${CMAKE_COMMAND} -E echo "target_empty_prebuild" > target_empty_prebuild.txt
  BYPRODUCTS target_empty_prebuild.txt
  COMMENT "CT: Processing target_empty_prebuild")
add_custom_command(TARGET target_empty POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E echo "target_empty_postbuild" > target_empty_postbuild.txt
  BYPRODUCTS target_empty_postbuild.txt
  COMMENT "CT: Processing target_empty_postbuild")

add_dependencies(target_cmd target_empty)

add_custom_command(
  OUTPUT out_of_order_dep.txt
  COMMAND ${CMAKE_COMMAND} -E echo "out_of_order_dep" > out_of_order_dep.txt
  COMMENT "CT: generate text file out_of_order_dep"
  DEPENDS dependsA.txt
)

if(TEST_MISSING_TARGET_SRC)
  set(SRC_FILE does_not_exist)
endif()
if(TEST_MISSING_TARGET_DEP)
  set(DEP_FILE does_not_exist)
endif()

add_custom_target(target_update_files
  DEPENDS genc_do_not_list.txt ${DEP_FILE}
  SOURCES gena.txt genb.txt another_file.c ${SRC_FILE}
  BYPRODUCTS junkit.txt
  COMMAND ${CMAKE_COMMAND} -E copy another_file.c junkit.txt
  COMMENT "CT: Processing target_update_files")

add_custom_command(
  OUTPUT force_rebuild gena.txt genb.txt genc_do_not_list.txt
  COMMAND ${CMAKE_COMMAND} -E copy dependsA.txt gena.txt
  COMMAND ${CMAKE_COMMAND} -E echo "genb" > genb.txt
  COMMAND ${CMAKE_COMMAND} -E echo "genc" > genc_do_not_list.txt
  DEPENDS out_of_order_dep.txt dependsA.txt
  COMMENT "CT: generate text files A, B, and C"
)

if(TEST_MISSING_DEP)
  set(MISSING_DEP MISSING_DEP)
endif()
if(TEST_DEP_CYCLE)
  set(DEP_CYCLE out_of_order_dep.txt)
endif()

add_custom_command(
  OUTPUT dependsA.txt
  COMMAND ${CMAKE_COMMAND} -E echo "dependsA" > dependsA.txt
  DEPENDS ${MISSING_DEP} ${DEP_CYCLE} another_file.c
  COMMENT "CT: generate text file dependsA"
)

add_custom_command(
  OUTPUT another_file.c
  COMMAND ${CMAKE_COMMAND} -E echo "//auto-gen file" > another_file.c
  COMMENT "CT: generate C file another_file"
)

add_dependencies(target_update_files target_empty)