CMakeLists.txt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(CheckCXXSourceCompiles)
  14. macro(do_try_compile prefix)
  15. set(CMAKE_REQUIRED_LIBRARIES ${prefix}::headeronly)
  16. check_cxx_source_compiles(
  17. "
  18. #include \"headeronly.h\"
  19. #ifndef HEADERONLY_DEFINE
  20. #error Expected HEADERONLY_DEFINE
  21. #endif
  22. int main(int,char**)
  23. {
  24. HeaderOnly ho;
  25. return ho.foo();
  26. }
  27. " ${prefix}IFACE_TRY_COMPILE)
  28. if(NOT ${prefix}IFACE_TRY_COMPILE)
  29. message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}")
  30. endif()
  31. if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_auto_type;")
  32. set(CMAKE_REQUIRED_LIBRARIES ${prefix}::use_auto_type)
  33. check_cxx_source_compiles(
  34. "
  35. int main(int,char**)
  36. {
  37. auto value = 0;
  38. return value;
  39. }
  40. " ${prefix}IMPORTED_IFACE_AUTO_TYPE)
  41. if(NOT ${prefix}IMPORTED_IFACE_AUTO_TYPE)
  42. message(SEND_ERROR "${prefix} try_compile with IMPORTED INTERFACE target failed!\n\n${OUTPUT}")
  43. endif()
  44. endif()
  45. endmacro()
  46. do_try_compile(bld)
  47. add_executable(headeronlytest_exp headeronlytest.cpp)
  48. target_link_libraries(headeronlytest_exp exp::headeronly)
  49. set_property(TARGET exp::sharediface APPEND PROPERTY INTERFACE_LINK_LIBRARIES define_iface)
  50. add_executable(interfacetest_exp interfacetest.cpp)
  51. target_link_libraries(interfacetest_exp exp::sharediface)
  52. do_try_compile(exp)