Skip to content

[Build] Version Header Generation #3173

Open
@AlexandreSinger

Description

@AlexandreSinger

The way that VTR generates its version information creates a file that is used to hold the new version information:

# We always update the vtr_version.cpp file every time the project is built,
# to ensure the git revision and dirty status are up to date.
#
# We need to do this in two stages:
#
# 1) We a custom target 'version' (which is always out of date) so it will always be run.
# It touches the unprocessed version input file so it too will always be out of date.
#
# 2) The custom command depends on the touched version input file and generates the processed
# version file, with updated values. The custom command uses the configure_version.cmake
# script to generate the up-to-date vtr_version.cpp
add_custom_target(version ALL
COMMAND ${CMAKE_COMMAND} -E touch ${VTR_VERSION_FILE_IN})
add_custom_command(OUTPUT ${VTR_VERSION_FILE_OUT}
COMMAND ${CMAKE_COMMAND}
-D IN_FILE=${VTR_VERSION_FILE_IN}
-D OUT_FILE=${VTR_VERSION_FILE_OUT}
-D VTR_VERSION_MAJOR=${VTR_VERSION_MAJOR}
-D VTR_VERSION_MINOR=${VTR_VERSION_MINOR}
-D VTR_VERSION_PATCH=${VTR_VERSION_PATCH}
-D VTR_VERSION_PRERELEASE=${VTR_VERSION_PRERELEASE}
-D VTR_COMPILER_INFO=${VTR_COMPILER_INFO}
-D VTR_BUILD_INFO=${VTR_BUILD_INFO}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/configure_version.cmake
MAIN_DEPENDENCY ${VTR_VERSION_FILE_IN}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM)

This usually works fine, however some users use sudo to build VTR which will cause the build system to create a file that only sudoers can access.

What the VTR build system is doing here is a common enough technique that CMake actually has a utility to do exactly this which should do exactly what we want.

@gadfort Pointed me to how OpenROAD does the exact same thing:

https://github.com/The-OpenROAD-Project/OpenROAD/blob/ac667f3cc7d3904115d0da6836b9df488cee0b8b/CMakeLists.txt#L111-L115

We should move to this simpler interface which should also fix this sudo issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions