FileSetImport.cmake 7.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. enable_language(C)
  2. get_property(_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  3. function(assert_prop_eq tgt prop value)
  4. unset(actual_value)
  5. get_property(actual_value TARGET ${tgt} PROPERTY ${prop})
  6. if(NOT actual_value STREQUAL value)
  7. message(SEND_ERROR "Expected value of ${prop}:\n ${value}\nActual value:\n ${actual_value}")
  8. endif()
  9. endfunction()
  10. get_filename_component(export_build_dir "${CMAKE_BINARY_DIR}" DIRECTORY)
  11. string(APPEND export_build_dir "/FileSetExport-build")
  12. include("${export_build_dir}/export.cmake")
  13. include("${export_build_dir}/install/lib/cmake/export.cmake")
  14. assert_prop_eq(export::lib1 HEADER_SETS "")
  15. assert_prop_eq(export::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;dir3;e;f;g")
  16. assert_prop_eq(export::lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/error.c")
  17. assert_prop_eq(export::lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}")
  18. assert_prop_eq(export::lib1 HEADER_SET_b "${CMAKE_CURRENT_SOURCE_DIR}/h2.h")
  19. assert_prop_eq(export::lib1 HEADER_DIRS_b "${CMAKE_CURRENT_SOURCE_DIR}")
  20. assert_prop_eq(export::lib1 HEADER_SET_c "$<1:dir/dir.h>")
  21. assert_prop_eq(export::lib1 HEADER_DIRS_c "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>")
  22. assert_prop_eq(export::lib1 HEADER_SET_d "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty.h")
  23. assert_prop_eq(export::lib1 HEADER_DIRS_d "${CMAKE_CURRENT_SOURCE_DIR}")
  24. assert_prop_eq(export::lib1 HEADER_SET_e "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>/empty2.h")
  25. assert_prop_eq(export::lib1 HEADER_DIRS_e "${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>")
  26. assert_prop_eq(export::lib1 HEADER_SET_f "${CMAKE_CURRENT_SOURCE_DIR}/empty3.h")
  27. assert_prop_eq(export::lib1 HEADER_DIRS_f "${CMAKE_CURRENT_SOURCE_DIR}")
  28. assert_prop_eq(export::lib1 HEADER_SET_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1/file1.h;${CMAKE_CURRENT_SOURCE_DIR}/dir2/file2.h")
  29. assert_prop_eq(export::lib1 HEADER_DIRS_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2")
  30. assert_prop_eq(export::lib1 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR};$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2;${CMAKE_CURRENT_SOURCE_DIR}/dir3;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/$<IF:$<CONFIG:Debug>,debug,release>>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir1>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir2>;$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/dir3>")
  31. assert_prop_eq(install::lib1 HEADER_SETS "")
  32. assert_prop_eq(install::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;dir3;e;f;g")
  33. assert_prop_eq(install::lib1 HEADER_SET "${export_build_dir}/install/include/error.c")
  34. assert_prop_eq(install::lib1 HEADER_DIRS "${export_build_dir}/install/include")
  35. assert_prop_eq(install::lib1 HEADER_SET_b "${export_build_dir}/install/include/h2.h")
  36. assert_prop_eq(install::lib1 HEADER_DIRS_b "${export_build_dir}/install/include")
  37. assert_prop_eq(install::lib1 HEADER_SET_c "${export_build_dir}/install/include/dir/dir.h")
  38. assert_prop_eq(install::lib1 HEADER_DIRS_c "${export_build_dir}/install/include/dir")
  39. if(_multi_config)
  40. assert_prop_eq(install::lib1 HEADER_SET_d "$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug/empty.h>;$<$<CONFIG:Release>:${export_build_dir}/install/include/release/empty.h>")
  41. else()
  42. assert_prop_eq(install::lib1 HEADER_SET_d "${export_build_dir}/install/include/debug/empty.h")
  43. endif()
  44. assert_prop_eq(install::lib1 HEADER_DIRS_d "${export_build_dir}/install/include")
  45. if(_multi_config)
  46. assert_prop_eq(install::lib1 HEADER_SET_e "$<$<CONFIG:Debug>:${export_build_dir}/install/include/empty2.h>;$<$<CONFIG:Release>:${export_build_dir}/install/include/empty2.h>")
  47. else()
  48. assert_prop_eq(install::lib1 HEADER_SET_e "${export_build_dir}/install/include/empty2.h")
  49. endif()
  50. assert_prop_eq(install::lib1 HEADER_DIRS_e "${export_build_dir}/install/include")
  51. if(_multi_config)
  52. assert_prop_eq(install::lib1 HEADER_SET_f "$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug/empty3.h>;$<$<CONFIG:Release>:${export_build_dir}/install/include/release/empty3.h>")
  53. assert_prop_eq(install::lib1 HEADER_DIRS_f "$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug>;$<$<CONFIG:Release>:${export_build_dir}/install/include/release>")
  54. else()
  55. assert_prop_eq(install::lib1 HEADER_SET_f "${export_build_dir}/install/include/debug/empty3.h")
  56. assert_prop_eq(install::lib1 HEADER_DIRS_f "${export_build_dir}/install/include/debug")
  57. endif()
  58. assert_prop_eq(install::lib1 HEADER_SET_g "${export_build_dir}/install/include/file1.h;${export_build_dir}/install/include/file2.h")
  59. assert_prop_eq(install::lib1 HEADER_DIRS_g "${export_build_dir}/install/include")
  60. if(_multi_config)
  61. assert_prop_eq(install::lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:$<$<CONFIG:Debug>:${export_build_dir}/install/include/debug>>;$<BUILD_INTERFACE:$<$<CONFIG:Release>:${export_build_dir}/install/include/release>>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir3>")
  62. else()
  63. assert_prop_eq(install::lib1 INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/debug>;$<BUILD_INTERFACE:${export_build_dir}/install/include>;$<BUILD_INTERFACE:${export_build_dir}/install/include/dir3>")
  64. endif()
  65. file(GLOB_RECURSE actual
  66. LIST_DIRECTORIES TRUE
  67. RELATIVE "${CMAKE_BINARY_DIR}/../FileSetExport-build/install/include"
  68. "${CMAKE_BINARY_DIR}/../FileSetExport-build/install/include/*"
  69. )
  70. if(actual)
  71. list(SORT actual)
  72. endif()
  73. if(_multi_config)
  74. set(expect "^debug;debug/empty\\.h;debug/empty3\\.h;dir;dir/dir\\.h;dir3;dir3/dir3\.h;empty2\\.h;error\\.c;file1\\.h;file2\\.h;h2\\.h;release;release/empty\\.h;release/empty3\\.h$")
  75. else()
  76. set(expect "^debug;debug/empty\\.h;debug/empty3\\.h;dir;dir/dir\\.h;dir3;dir3/dir3\.h;empty2\\.h;error\\.c;file1\\.h;file2\\.h;h2\\.h$")
  77. endif()
  78. if(NOT "${actual}" MATCHES "${expect}")
  79. message(SEND_ERROR "Installed files:
  80. ${actual}
  81. do not match what we expected:
  82. ${expect}
  83. in directory:
  84. ${CMAKE_INSTALL_PREFIX}")
  85. endif()
  86. add_library(lib2_export STATIC lib2.c)
  87. target_link_libraries(lib2_export PRIVATE export::lib1)
  88. add_library(lib2_install STATIC lib2.c)
  89. target_link_libraries(lib2_install PRIVATE install::lib1)