Files
CMake/Tests/RunCMake/VS10Project/VsImageVersion-check.cmake
Nikita Nemkin e5fd973b14 VS: Set the linker image version using the target's VERSION property
This matches the behavior of NMake, Ninja and older Visual Studio
generators.

Fixes: #13130
2025-02-11 17:36:34 +05:00

29 lines
1006 B
CMake

macro(ensure_link_version projectFile expected)
if(NOT EXISTS "${projectFile}")
set(RunCMake_TEST_FAILED "Project file ${projectFile} does not exist.")
return()
endif()
file(STRINGS "${projectFile}" lines)
set(version "")
foreach(line IN LISTS lines)
if(line MATCHES "<Link>")
set(in_link TRUE)
elseif(line MATCHES "</Link>")
if(NOT version STREQUAL "${expected}")
set(RunCMake_TEST_FAILED "<Version> not found or incorrect: ${version} vs ${expected}")
return()
endif()
set(in_link FALSE)
set(version "")
elseif(in_link AND line MATCHES "<Version>([^<]+)</Version>")
set(version ${CMAKE_MATCH_1})
endif()
endforeach()
endmacro()
ensure_link_version("${RunCMake_TEST_BINARY_DIR}/app-C.vcxproj" 0.1)
ensure_link_version("${RunCMake_TEST_BINARY_DIR}/app-CXX.vcxproj" 1.0)
ensure_link_version("${RunCMake_TEST_BINARY_DIR}/lib-C.vcxproj" 65535.65535)
ensure_link_version("${RunCMake_TEST_BINARY_DIR}/lib-CXX.vcxproj" "")