CMakeLists.txt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. endmacro()
  32. do_try_compile(bld)
  33. add_executable(headeronlytest_exp headeronlytest.cpp)
  34. target_link_libraries(headeronlytest_exp exp::headeronly)
  35. set_property(TARGET exp::sharediface APPEND PROPERTY INTERFACE_LINK_LIBRARIES define_iface)
  36. add_executable(interfacetest_exp interfacetest.cpp)
  37. target_link_libraries(interfacetest_exp exp::sharediface)
  38. do_try_compile(exp)