1
0

ReferenceImport.cmake 2.6 KB

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