CMakeLists.txt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. cmake_minimum_required(VERSION 3.24...3.28)
  2. project(cxx_modules_library NONE)
  3. find_package(export_usage REQUIRED)
  4. if (NOT TARGET CXXModules::export_usage)
  5. message(FATAL_ERROR
  6. "Missing imported target")
  7. endif ()
  8. if (NOT TARGET CXXModules::export_used)
  9. message(FATAL_ERROR
  10. "Missing imported target")
  11. endif ()
  12. if (NOT TARGET CXXModules::export_build)
  13. message(FATAL_ERROR
  14. "Missing imported target")
  15. endif ()
  16. if (NOT TARGET CXXModules::export_install)
  17. message(FATAL_ERROR
  18. "Missing imported target")
  19. endif ()
  20. if (TARGET CXXModules::export_never)
  21. message(FATAL_ERROR
  22. "Extra imported target")
  23. endif ()
  24. function (check_property expected property)
  25. get_property(actual TARGET CXXModules::export_usage
  26. PROPERTY "${property}")
  27. if (NOT actual STREQUAL expected)
  28. message(SEND_ERROR
  29. "Mismatch for ${property}:\n expected: ${expected}\n actual: ${actual}")
  30. endif ()
  31. endfunction ()
  32. check_property("/usr/exported;/usr/buildiface" "IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES")
  33. check_property("exported;buildiface" "IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS")
  34. check_property("cxx_std_20;cxx_std_11;cxx_std_14" "IMPORTED_CXX_MODULES_COMPILE_FEATURES")
  35. check_property("${export_interfaces_flag}100;${export_interfaces_flag}200" "IMPORTED_CXX_MODULES_COMPILE_OPTIONS")
  36. check_property("CXXModules::export_used;CXXModules::export_build" "IMPORTED_CXX_MODULES_LINK_LIBRARIES")
  37. # Extract the export-dependent targets from the export file.
  38. file(STRINGS "${export_usage_DIR}/export_usage-targets.cmake" usage_dependent_targets
  39. REGEX "foreach._target ")
  40. # Rudimentary argument splitting.
  41. string(REPLACE " " ";" usage_dependent_targets "${usage_dependent_targets}")
  42. # Keep only "target" names.
  43. list(FILTER usage_dependent_targets INCLUDE REGEX "CXXModules::")
  44. # Strip quotes.
  45. string(REPLACE "\"" "" usage_dependent_targets "${usage_dependent_targets}")
  46. if (NOT "CXXModules::export_used" IN_LIST usage_dependent_targets)
  47. message(SEND_ERROR
  48. "The main export does not require the 'CXXModules::export_used' target")
  49. endif ()
  50. if (NOT "CXXModules::export_build" IN_LIST usage_dependent_targets)
  51. message(SEND_ERROR
  52. "The main export does not require the 'CXXModules::export_build' target")
  53. endif ()
  54. if ("CXXModules::export_install" IN_LIST usage_dependent_targets)
  55. message(SEND_ERROR
  56. "The main export requires the 'CXXModules::export_install' target")
  57. endif ()