CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # Import targets from the exported build tree.
  2. include(${Import_BINARY_DIR}/../Export/ExportInterfaceBuildTree.cmake)
  3. # Import targets from the exported install tree.
  4. include(${CMAKE_INSTALL_PREFIX}/lib/exp/expInterface.cmake)
  5. add_library(define_iface INTERFACE)
  6. set_property(TARGET define_iface PROPERTY
  7. INTERFACE_COMPILE_DEFINITIONS DEFINE_IFACE_DEFINE)
  8. add_executable(headeronlytest_bld headeronlytest.cpp)
  9. target_link_libraries(headeronlytest_bld bld::headeronly)
  10. set_property(TARGET bld::sharediface APPEND PROPERTY INTERFACE_LINK_LIBRARIES define_iface)
  11. add_executable(interfacetest_bld interfacetest.cpp)
  12. target_link_libraries(interfacetest_bld bld::sharediface)
  13. include(CheckCSourceCompiles)
  14. include(CheckCXXSourceCompiles)
  15. macro(do_try_compile prefix)
  16. set(CMAKE_REQUIRED_LIBRARIES ${prefix}::headeronly)
  17. check_cxx_source_compiles(
  18. "
  19. #include \"headeronly.h\"
  20. #ifndef HEADERONLY_DEFINE
  21. #error Expected HEADERONLY_DEFINE
  22. #endif
  23. int main(int,char**)
  24. {
  25. HeaderOnly ho;
  26. return ho.foo();
  27. }
  28. " ${prefix}IFACE_TRY_COMPILE)
  29. if(NOT ${prefix}IFACE_TRY_COMPILE)
  30. message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}")
  31. endif()
  32. if (";${CMAKE_C_COMPILE_FEATURES};" MATCHES ";c_restrict;")
  33. set(CMAKE_REQUIRED_LIBRARIES ${prefix}::use_c_restrict)
  34. check_c_source_compiles(
  35. "
  36. int foo(int * restrict a, int * restrict b)
  37. {
  38. (void)a;
  39. (void)b;
  40. return 0;
  41. }
  42. int main()
  43. {
  44. return 0;
  45. }
  46. " ${prefix}IMPORTED_IFACE_C_RESTRICT)
  47. if(NOT ${prefix}IMPORTED_IFACE_C_RESTRICT)
  48. message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}")
  49. endif()
  50. endif()
  51. if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_auto_type;")
  52. set(CMAKE_REQUIRED_LIBRARIES ${prefix}::use_auto_type)
  53. check_cxx_source_compiles(
  54. "
  55. int main(int,char**)
  56. {
  57. auto value = 0;
  58. return value;
  59. }
  60. " ${prefix}IMPORTED_IFACE_AUTO_TYPE)
  61. if(NOT ${prefix}IMPORTED_IFACE_AUTO_TYPE)
  62. message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}")
  63. endif()
  64. endif()
  65. endmacro()
  66. do_try_compile(bld)
  67. add_executable(source_target_test_bld source_target_test.cpp)
  68. target_link_libraries(source_target_test_bld bld::source_target)
  69. target_compile_definitions(source_target_test_bld PRIVATE USE_FROM_BUILD_DIR)
  70. add_executable(source_target_test_exp source_target_test.cpp)
  71. target_link_libraries(source_target_test_exp exp::source_target)
  72. target_compile_definitions(source_target_test_exp PRIVATE USE_FROM_INSTALL_DIR)
  73. add_executable(headeronlytest_exp headeronlytest.cpp)
  74. target_link_libraries(headeronlytest_exp exp::headeronly)
  75. set_property(TARGET exp::sharediface APPEND PROPERTY INTERFACE_LINK_LIBRARIES define_iface)
  76. add_executable(interfacetest_exp interfacetest.cpp)
  77. target_link_libraries(interfacetest_exp exp::sharediface)
  78. if(NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;$]" OR CMAKE_GENERATOR STREQUAL "Xcode")
  79. add_executable(pch_iface_test_bld pch_iface_test.cpp)
  80. target_link_libraries(pch_iface_test_bld bld::pch_iface)
  81. add_executable(pch_iface_test_exp pch_iface_test.cpp)
  82. target_link_libraries(pch_iface_test_exp exp::pch_iface)
  83. if(CMAKE_CXX_COMPILE_OPTIONS_USE_PCH)
  84. target_compile_definitions(pch_iface_test_bld PRIVATE EXPECT_PCH)
  85. target_compile_definitions(pch_iface_test_exp PRIVATE EXPECT_PCH)
  86. endif()
  87. endif()
  88. do_try_compile(exp)
  89. foreach(ns exp bld)
  90. get_property(defs TARGET ${ns}::cmakeonly PROPERTY INTERFACE_COMPILE_DEFINITIONS)
  91. if(NOT defs STREQUAL [[DEF="\"\$\B"]])
  92. message(SEND_ERROR
  93. "${ns}::cmakeonly property INTERFACE_COMPILE_DEFINITIONS is:\n"
  94. " ${defs}\n"
  95. "not\n"
  96. " " [[DEF="\"\$\B"]] "\n")
  97. endif()
  98. get_property(custom TARGET ${ns}::cmakeonly PROPERTY custom_property)
  99. if(NOT custom STREQUAL "CustomPropertyValue")
  100. message(SEND_ERROR
  101. "${ns}::cmakeonly property custom_property is:\n"
  102. " ${custom}\n"
  103. "not\n"
  104. " CustomPropertyValue\n")
  105. endif()
  106. endforeach()