| 1 |
enable_language(CXX CSharp) |
| 2 |
|
| 3 |
if(NOT DEFINED exportFileName OR |
| 4 |
NOT DEFINED exportNameSpace OR |
| 5 |
NOT DEFINED exportTargetName) |
| 6 |
message(FATAL_ERROR "export information missing") |
| 7 |
endif() |
| 8 |
|
| 9 |
# Include generated export file. |
| 10 |
if(NOT EXISTS "${exportFileName}") |
| 11 |
message(FATAL_ERROR "exportFileNameCSharp does not exist: ${exportFileName}") |
| 12 |
endif() |
| 13 |
include(${exportFileName}) |
| 14 |
|
| 15 |
# Verify expected targets are imported |
| 16 |
set(linkNames linkNameCSharp linkNameNative linkNameMixed |
| 17 |
linkNamePure linkNameSafe) |
| 18 |
set(linkNameCSharp "${exportNameSpace}:${exportTargetName}CSharp") |
| 19 |
set(linkNameNative "${exportNameSpace}:${exportTargetName}Native") |
| 20 |
set(linkNameMixed "${exportNameSpace}:${exportTargetName}Mixed") |
| 21 |
set(linkNamePure "${exportNameSpace}:${exportTargetName}Pure") |
| 22 |
set(linkNameSafe "${exportNameSpace}:${exportTargetName}Safe") |
| 23 |
foreach(l ${linkNames}) |
| 24 |
if(NOT TARGET ${${l}}) |
| 25 |
message(FATAL_ERROR "imported target not found (${${l}})") |
| 26 |
endif() |
| 27 |
endforeach() |
| 28 |
|
| 29 |
# Test referencing managed assemblies from C# executable. |
| 30 |
add_executable(ReferenceImportCSharp ReferenceImport.cs) |
| 31 |
target_link_libraries(ReferenceImportCSharp |
| 32 |
${linkNameCSharp} |
| 33 |
${linkNameNative} # ignored |
| 34 |
${linkNameMixed} |
| 35 |
${linkNamePure} |
| 36 |
${linkNameSafe} |
| 37 |
) |
| 38 |
|
| 39 |
# native C++ executable. |
| 40 |
add_executable(ReferenceImportNative ReferenceImportNative.cxx) |
| 41 |
target_link_libraries(ReferenceImportNative |
| 42 |
${linkNameCSharp} # ignored |
| 43 |
${linkNameNative} |
| 44 |
${linkNameMixed} |
| 45 |
${linkNamePure} # ignored |
| 46 |
${linkNameSafe} # ignored |
| 47 |
) |
| 48 |
add_custom_command(TARGET ReferenceImportNative POST_BUILD |
| 49 |
COMMAND ${CMAKE_COMMAND} -E copy_if_different |
| 50 |
"$<TARGET_FILE:${linkNameNative}>" |
| 51 |
"${CMAKE_BINARY_DIR}/$<CONFIG>" |
| 52 |
) |
| 53 |
|
| 54 |
# mixed C++ executable. |
| 55 |
add_executable(ReferenceImportMixed ReferenceImportMixed.cxx) |
| 56 |
target_link_libraries(ReferenceImportMixed |
| 57 |
${linkNameCSharp} |
| 58 |
${linkNameNative} |
| 59 |
${linkNameMixed} |
| 60 |
${linkNamePure} |
| 61 |
${linkNameSafe} |
| 62 |
) |
| 63 |
set_target_properties(ReferenceImportMixed PROPERTIES |
| 64 |
COMMON_LANGUAGE_RUNTIME "") |
| 65 |
|
| 66 |
# pure C++ executable. |
| 67 |
add_executable(ReferenceImportPure ReferenceImportPure.cxx) |
| 68 |
target_link_libraries(ReferenceImportPure |
| 69 |
${linkNameCSharp} |
| 70 |
${linkNameNative} # ignored |
| 71 |
${linkNameMixed} |
| 72 |
${linkNamePure} |
| 73 |
${linkNameSafe} |
| 74 |
) |
| 75 |
set_target_properties(ReferenceImportPure PROPERTIES |
| 76 |
COMMON_LANGUAGE_RUNTIME "pure") |
| 77 |
|
| 78 |
# native C++ executable. |
| 79 |
add_executable(ReferenceImportSafe ReferenceImportSafe.cxx) |
| 80 |
target_link_libraries(ReferenceImportSafe |
| 81 |
${linkNameCSharp} |
| 82 |
${linkNameNative} # ignored |
| 83 |
${linkNameMixed} |
| 84 |
${linkNamePure} |
| 85 |
${linkNameSafe} |
| 86 |
) |
| 87 |
set_target_properties(ReferenceImportSafe PROPERTIES |
| 88 |
COMMON_LANGUAGE_RUNTIME "safe") |