build: cmake: generate version files with add_custom_command()

instead of using execute_process(), let's use add_custom_command()
to generate the SCYLLA-{VERSION,RELEASE,PRODUCT}-FILE, so that we
can let other targets depend on these generated files. and generate
them on demand.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
This commit is contained in:
Kefu Chai
2023-07-19 12:54:51 +08:00
parent 8bc42f54d4
commit bb7d99ad37

View File

@@ -4,13 +4,23 @@
function(add_version_library name source)
set(version_file ${CMAKE_CURRENT_BINARY_DIR}/SCYLLA-VERSION-FILE)
set(release_file ${CMAKE_CURRENT_BINARY_DIR}/SCYLLA-RELEASE-FILE)
execute_process(
set(product_file ${CMAKE_CURRENT_BINARY_DIR}/SCYLLA-PRODUCT-FILE)
set(scylla_version_files
${version_file}
${release_file}
${product_file})
add_custom_command(
OUTPUT ${scylla_version_files}
COMMAND ${CMAKE_SOURCE_DIR}/SCYLLA-VERSION-GEN --output-dir "${CMAKE_CURRENT_BINARY_DIR}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_custom_target(scylla-version
DEPENDS ${scylla_version_files})
file(STRINGS ${version_file} scylla_version)
file(STRINGS ${release_file} scylla_release)
add_library(${name} OBJECT ${source})
add_dependencies(${name} scylla-version)
target_compile_definitions(${name}
PRIVATE
SCYLLA_VERSION=\"${scylla_version}\"