Skip to content

Commit

Permalink
Use add_custom_command over add_custom_target
Browse files Browse the repository at this point in the history
This fixes an issue where the CentOS CI kept failing because it couldn't
find the generated InterimVersion output file.

It seems like using the BYPRODUCTS statement in add_custom_target
didn't work because BYPRODUCTS was only added in CMake 3.2, so then
add_custom_target never ran, which is obviously a problem.

The solution is to use add_custom_command instead, and to solve the
problem that the interim version needs to be regenerated every time no
matter what (which is what BYPRODUCTS was supposed to do) we just add a
dummy output instead.
  • Loading branch information
InfoTeddy committed Jul 13, 2024
1 parent e3876fe commit c636713
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions desktop_version/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ if(NOT OFFICIAL_BUILD)
set(VERSION_INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/InterimVersion.in.c)
set(VERSION_OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/InterimVersion.out.c)

add_custom_target(
GenerateVersion ALL
# This BYPRODUCTS line is required for this to be ran every time
BYPRODUCTS ${VERSION_OUTPUT_FILE}
add_custom_command(
# This OUTPUT line is required for this to be ran every time
OUTPUT ${VERSION_OUTPUT_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/src/_dummy.c
COMMAND ${CMAKE_COMMAND}
# These args have to be passed through, otherwise the script can't see them
# Also, these args have to come BEFORE `-P`! (Otherwise it fails with an unclear error)
Expand All @@ -229,8 +228,6 @@ if(NOT OFFICIAL_BUILD)
-P ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake
)

add_dependencies(VVVVVV GenerateVersion)

target_compile_definitions(VVVVVV PRIVATE -DINTERIM_VERSION_EXISTS)

add_library(InterimVersion STATIC src/InterimVersion.out.c)
Expand Down

0 comments on commit c636713

Please sign in to comment.