diff options
author | Michael Stürmer <michael.stuermer@schaeffler.com> | 2018-03-20 11:22:02 (GMT) |
---|---|---|
committer | Michael Stürmer <michael.stuermer@schaeffler.com> | 2018-04-24 05:05:16 (GMT) |
commit | 359544a9074a26c3d5d7801932c809048763c341 (patch) | |
tree | 26fe547d976d208feb58362f2d28ac2bbb0e1901 /Tests/RunCMake/CSharpReferenceImport/ReferenceImport.cmake | |
parent | 43571073e06fdd3db289c3f99467260b5d445781 (diff) | |
download | CMake-359544a9074a26c3d5d7801932c809048763c341.zip CMake-359544a9074a26c3d5d7801932c809048763c341.tar.gz CMake-359544a9074a26c3d5d7801932c809048763c341.tar.bz2 |
add tests for using target_link_libraries() with imported managed targets
Diffstat (limited to 'Tests/RunCMake/CSharpReferenceImport/ReferenceImport.cmake')
-rw-r--r-- | Tests/RunCMake/CSharpReferenceImport/ReferenceImport.cmake | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/Tests/RunCMake/CSharpReferenceImport/ReferenceImport.cmake b/Tests/RunCMake/CSharpReferenceImport/ReferenceImport.cmake new file mode 100644 index 0000000..c65f623 --- /dev/null +++ b/Tests/RunCMake/CSharpReferenceImport/ReferenceImport.cmake @@ -0,0 +1,88 @@ +enable_language(CXX CSharp) + +if(NOT DEFINED exportFileName OR + NOT DEFINED exportNameSpace OR + NOT DEFINED exportTargetName) + message(FATAL_ERROR "export information missing") +endif() + +# Include generated export file. +if(NOT EXISTS "${exportFileName}") + message(FATAL_ERROR "exportFileNameCSharp does not exist: ${exportFileName}") +endif() +include(${exportFileName}) + +# Verify expected targets are imported +set(linkNames linkNameCSharp linkNameNative linkNameMixed + linkNamePure linkNameSafe) +set(linkNameCSharp "${exportNameSpace}:${exportTargetName}CSharp") +set(linkNameNative "${exportNameSpace}:${exportTargetName}Native") +set(linkNameMixed "${exportNameSpace}:${exportTargetName}Mixed") +set(linkNamePure "${exportNameSpace}:${exportTargetName}Pure") +set(linkNameSafe "${exportNameSpace}:${exportTargetName}Safe") +foreach(l ${linkNames}) + if(NOT TARGET ${${l}}) + message(FATAL_ERROR "imported target not found (${${l}})") + endif() +endforeach() + +# Test referencing managed assemblies from C# executable. +add_executable(ReferenceImportCSharp ReferenceImport.cs) +target_link_libraries(ReferenceImportCSharp + ${linkNameCSharp} + ${linkNameNative} # ignored + ${linkNameMixed} + ${linkNamePure} + ${linkNameSafe} + ) + +# native C++ executable. +add_executable(ReferenceImportNative ReferenceImportNative.cxx) +target_link_libraries(ReferenceImportNative + ${linkNameCSharp} # ignored + ${linkNameNative} + ${linkNameMixed} + ${linkNamePure} # ignored + ${linkNameSafe} # ignored + ) +add_custom_command(TARGET ReferenceImportNative POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "$<TARGET_FILE:${linkNameNative}>" + "${CMAKE_BINARY_DIR}/$<CONFIG>" + ) + +# mixed C++ executable. +add_executable(ReferenceImportMixed ReferenceImportMixed.cxx) +target_link_libraries(ReferenceImportMixed + ${linkNameCSharp} + ${linkNameNative} + ${linkNameMixed} + ${linkNamePure} + ${linkNameSafe} + ) +set_target_properties(ReferenceImportMixed PROPERTIES + COMMON_LANGUAGE_RUNTIME "") + +# pure C++ executable. +add_executable(ReferenceImportPure ReferenceImportPure.cxx) +target_link_libraries(ReferenceImportPure + ${linkNameCSharp} + ${linkNameNative} # ignored + ${linkNameMixed} + ${linkNamePure} + ${linkNameSafe} + ) +set_target_properties(ReferenceImportPure PROPERTIES + COMMON_LANGUAGE_RUNTIME "pure") + +# native C++ executable. +add_executable(ReferenceImportSafe ReferenceImportSafe.cxx) +target_link_libraries(ReferenceImportSafe + ${linkNameCSharp} + ${linkNameNative} # ignored + ${linkNameMixed} + ${linkNamePure} + ${linkNameSafe} + ) +set_target_properties(ReferenceImportSafe PROPERTIES + COMMON_LANGUAGE_RUNTIME "safe") |