Debian Codegraph @

Tests/RunCMake/NinjaMultiConfig/CustomCommandsAndTargets.cmake

raw
1 set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
2
3 enable_language(C)
4
5 file(REMOVE "${CMAKE_BINARY_DIR}/target_files_custom.cmake")
6
7 function(get_write_file_command var filename)
8 set(${var} ${CMAKE_COMMAND} -DOUTPUT_FILE=${filename} -DGENEX_CONFIG=$<CONFIG> -DINTDIR_CONFIG=${CMAKE_CFG_INTDIR} -P ${CMAKE_SOURCE_DIR}/WriteFile.cmake PARENT_SCOPE)
9 endfunction()
10
11 function(create_targets prefix)
12 get_write_file_command(cmd ${prefix}Command.txt)
13 add_custom_command(OUTPUT ${prefix}Command.txt COMMAND ${cmd})
14 add_custom_target(${prefix}Command DEPENDS ${prefix}Command.txt)
15
16 get_write_file_command(cmd ${prefix}Target.txt)
17 add_custom_target(${prefix}Target COMMAND ${cmd} BYPRODUCTS ${prefix}Target.txt)
18
19 get_write_file_command(cmd ${prefix}PostBuild.txt)
20 add_executable(${prefix}PostBuild ${CMAKE_SOURCE_DIR}/main.c)
21 add_custom_command(TARGET ${prefix}PostBuild POST_BUILD COMMAND ${cmd} BYPRODUCTS ${prefix}PostBuild.txt)
22
23 get_write_file_command(cmd ${prefix}TargetPostBuild.txt)
24 add_custom_target(${prefix}TargetPostBuild)
25 add_custom_command(TARGET ${prefix}TargetPostBuild POST_BUILD COMMAND ${cmd} BYPRODUCTS ${prefix}TargetPostBuild.txt)
26
27 file(APPEND "${CMAKE_BINARY_DIR}/target_files_custom.cmake"
28 "set(TARGET_DEPENDS_${prefix}Command [==[${CMAKE_CURRENT_BINARY_DIR}/${prefix}Command.txt]==])
29 set(TARGET_BYPRODUCTS_${prefix}Target [==[${CMAKE_CURRENT_BINARY_DIR}/${prefix}Target.txt]==])
30 set(TARGET_BYPRODUCTS_${prefix}PostBuild [==[${CMAKE_CURRENT_BINARY_DIR}/${prefix}PostBuild.txt]==])
31 set(TARGET_BYPRODUCTS_${prefix}TargetPostBuild [==[${CMAKE_CURRENT_BINARY_DIR}/${prefix}TargetPostBuild.txt]==])
32 ")
33 endfunction()
34
35 add_subdirectory(CustomCommandsAndTargetsSubdir)
36
37 create_targets(Top)
38
39 add_executable(RootExe main.c)
40 add_custom_target(RootCustom COMMAND ${CMAKE_COMMAND} -E touch RootCustom.txt BYPRODUCTS RootCustom.txt)
41 add_custom_command(OUTPUT main.c COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/main.c ${CMAKE_CURRENT_BINARY_DIR}/main.c DEPENDS RootCustom)
42 add_executable(LeafExe ${CMAKE_CURRENT_BINARY_DIR}/main.c)
43 add_custom_target(LeafCustom COMMAND ${CMAKE_COMMAND} -E touch LeafCustom.txt BYPRODUCTS LeafCustom.txt DEPENDS RootCustom RootExe)
44 add_dependencies(LeafExe RootExe)
45 file(APPEND "${CMAKE_BINARY_DIR}/target_files_custom.cmake"
46 "set(TARGET_BYPRODUCTS_LeafCustom [==[${CMAKE_CURRENT_BINARY_DIR}/LeafCustom.txt]==])
47 set(TARGET_BYPRODUCTS_LeafExe [==[${CMAKE_CURRENT_BINARY_DIR}/main.c]==])
48 set(TARGET_BYPRODUCTS_RootCustom [==[${CMAKE_CURRENT_BINARY_DIR}/RootCustom.txt]==])
49 ")
50
51 include(${CMAKE_CURRENT_LIST_DIR}/Common.cmake)
52 generate_output_files(TopPostBuild SubdirPostBuild RootExe LeafExe)
53 file(APPEND "${CMAKE_BINARY_DIR}/target_files.cmake" "include(\${CMAKE_CURRENT_LIST_DIR}/target_files_custom.cmake)\n")