Tests: Extend VS10Project to cover .targets file linking

With VS generators for 2010 and above, passing a `.targets` file to
`target_link_libraries` is expected to generate content in the
`.vcxproj` file to import the targets file.  Add a test to cover this.
This commit is contained in:
Soji Yamakawa 2016-11-11 21:34:38 -05:00 committed by Brad King
parent 8b33507aba
commit c9560a9a7b
5 changed files with 61 additions and 0 deletions

View File

@ -1,2 +1,3 @@
include(RunCMake) include(RunCMake)
run_cmake(VsConfigurationType) run_cmake(VsConfigurationType)
run_cmake(VsTargetsFileReferences)

View File

@ -0,0 +1,45 @@
set(files foo.vcxproj bar.vcxproj baz.vcxproj)
foreach(file ${files})
set(vsProjectFile ${RunCMake_TEST_BINARY_DIR}/${file})
if(NOT EXISTS "${vsProjectFile}")
set(RunCMake_TEST_FAILED "Project file ${vsProjectFile} does not exist.")
return()
endif()
set(waldoFound FALSE)
set(xyzzyFound FALSE)
file(STRINGS "${vsProjectFile}" lines)
foreach(line IN LISTS lines)
if(line MATCHES "^ *<Import Project=.*/>$")
if(line MATCHES "^.*waldo.targets.*$")
set(waldoFound TRUE)
message(STATUS "${file} is importing waldo.targets")
elseif(line MATCHES "^.*xyzzy.targets.*$")
set(xyzzyFound TRUE)
message(STATUS "${file} is importing xyzzy.targets")
endif()
endif()
endforeach()
if("${file}" STREQUAL "foo.vcxproj")
if(NOT xyzzyFound)
set(RunCMake_TEST_FAILED "xyzzy.targets not imported from ${file}")
return()
endif()
if(waldoFound)
set(RunCMake_TEST_FAILED "waldo.targets imported from ${file}")
return()
endif()
else()
if(NOT xyzzyFound)
set(RunCMake_TEST_FAILED "xyzzy.targets not imported from ${file}")
return()
endif()
if(NOT waldoFound)
set(RunCMake_TEST_FAILED "waldo.targets not imported from ${file}")
return()
endif()
endif()
endforeach()

View File

@ -0,0 +1,9 @@
enable_language(CXX)
add_library(foo foo.cpp)
target_link_libraries(foo ${CMAKE_BINARY_DIR}/xyzzy.targets)
add_library(bar bar.cpp)
target_link_libraries(bar foo ${CMAKE_BINARY_DIR}/waldo.targets)
add_executable(baz baz.cpp)
target_link_libraries(baz bar)

View File

@ -0,0 +1,3 @@
void bar()
{
}

View File

@ -0,0 +1,3 @@
void baz()
{
}