| enable_language(C) | |
| # Files generated by custom targets can only be installed after the | |
| # preparation target has built them. | |
| set(file_payload "${CMAKE_CURRENT_BINARY_DIR}/file-payload.txt") | |
| add_custom_target(generate_file_payload | |
| COMMAND ${CMAKE_COMMAND} -E touch "${file_payload}" | |
| BYPRODUCTS "${file_payload}" | |
| ) | |
| install(FILES "${file_payload}" | |
| DESTINATION share/install-prep | |
| COMPONENT Payload | |
| BUILD_DEPENDS generate_file_payload | |
| ) | |
| set(code_payload "${CMAKE_CURRENT_BINARY_DIR}/code-payload.txt") | |
| add_custom_target(generate_code_payload | |
| COMMAND ${CMAKE_COMMAND} -E touch "${code_payload}" | |
| BYPRODUCTS "${code_payload}" | |
| ) | |
| install(CODE " | |
| if(NOT EXISTS \"${code_payload}\") | |
| message(FATAL_ERROR \"Preparation did not generate code-payload.txt\") | |
| endif() | |
| " | |
| COMPONENT Payload | |
| BUILD_DEPENDS generate_code_payload | |
| ) | |
| # Directory content generated by a custom target can only be installed | |
| # after the preparation target has generated it. | |
| set(dir_payload "${CMAKE_CURRENT_BINARY_DIR}/dir-payload") | |
| add_custom_target(generate_dir_payload | |
| COMMAND ${CMAKE_COMMAND} -E make_directory "${dir_payload}" | |
| COMMAND ${CMAKE_COMMAND} -E touch "${dir_payload}/dir-payload.txt" | |
| ) | |
| install(DIRECTORY "${dir_payload}/" | |
| DESTINATION share/install-prep | |
| COMPONENT Payload | |
| BUILD_DEPENDS generate_dir_payload | |
| ) | |
| # BUILD_DEPENDS may also name files. A file that the build generates is | |
| # prepared like an installed file, and an existing file needs no preparation. | |
| set(code_file "${CMAKE_CURRENT_BINARY_DIR}/code-file.txt") | |
| add_custom_command(OUTPUT "${code_file}" | |
| COMMAND ${CMAKE_COMMAND} -E touch "${code_file}" | |
| ) | |
| add_custom_target(generate_code_file DEPENDS "${code_file}") | |
| install(CODE " | |
| if(NOT EXISTS \"${code_file}\") | |
| message(FATAL_ERROR \"Preparation did not generate code-file.txt\") | |
| endif() | |
| " | |
| COMPONENT Payload | |
| BUILD_DEPENDS "${code_file}" "${CMAKE_CURRENT_SOURCE_DIR}/lib.c" | |
| ) | |
| add_subdirectory(build-depends) | |
| # BUILD_DEPENDS may also name the artifact linked by a target. | |
| set(artifact_dir "${CMAKE_CURRENT_BINARY_DIR}/artifacts") | |
| add_library(depends_artifact STATIC EXCLUDE_FROM_ALL lib.c) | |
| set_property(TARGET depends_artifact | |
| PROPERTY ARCHIVE_OUTPUT_DIRECTORY "$<1:${artifact_dir}>") | |
| set(depends_artifact_file "${artifact_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}depends_artifact${CMAKE_STATIC_LIBRARY_SUFFIX}") | |
| install(CODE " | |
| if(NOT EXISTS \"${depends_artifact_file}\") | |
| message(FATAL_ERROR \"Preparation did not build depends_artifact\") | |
| endif() | |
| " | |
| COMPONENT Payload | |
| BUILD_DEPENDS "${depends_artifact_file}" | |
| ) | |
| add_library(unit_tests STATIC neverbuild.c) |