CMakeLists.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. cmake_minimum_required(VERSION 2.8)
  2. project(InterfaceLibrary)
  3. add_library(iface_nodepends INTERFACE)
  4. target_compile_definitions(iface_nodepends INTERFACE IFACE_DEFINE)
  5. add_subdirectory(headerdir)
  6. # Add an interface target in a subdirectory that uses an imported interface.
  7. add_subdirectory(ifacedir)
  8. # Poison an imported interface with the same name as that in the subdir
  9. # to ensure that the transitive lookup occurs in the subdir.
  10. add_library(imp::iface INTERFACE IMPORTED)
  11. set_property(TARGET imp::iface APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SOMEPROP)
  12. set_property(TARGET imp::iface PROPERTY INTERFACE_SOMEPROP OFF)
  13. set_property(TARGET imp::iface PROPERTY INTERFACE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/does_not_exist.cpp)
  14. add_library(objlib OBJECT obj.cpp)
  15. add_library(iface_objlib INTERFACE)
  16. target_sources(iface_objlib INTERFACE $<TARGET_OBJECTS:objlib>)
  17. add_library(intermediate INTERFACE)
  18. target_link_libraries(intermediate INTERFACE iface_objlib)
  19. add_library(item_fake_tgt STATIC item_fake.cpp)
  20. set_property(TARGET item_fake_tgt PROPERTY OUTPUT_NAME item_fake)
  21. add_library(item_real STATIC item.cpp)
  22. add_library(item_iface INTERFACE IMPORTED)
  23. set_property(TARGET item_iface PROPERTY IMPORTED_LIBNAME item_real)
  24. add_dependencies(item_iface item_real)
  25. link_directories(${CMAKE_CURRENT_BINARY_DIR})
  26. add_executable(InterfaceLibrary definetestexe.cpp)
  27. target_link_libraries(InterfaceLibrary
  28. iface_nodepends
  29. headeriface
  30. subiface
  31. intermediate
  32. item_iface
  33. item_fake # ensure that 'item_real' is ordered in place of item_iface
  34. )
  35. add_dependencies(InterfaceLibrary item_fake_tgt)
  36. add_subdirectory(libsdir)
  37. add_executable(sharedlibtestexe sharedlibtestexe.cpp)
  38. target_link_libraries(sharedlibtestexe shared_iface imported::iface)
  39. add_library(broken EXCLUDE_FROM_ALL broken.cpp)
  40. add_library(iface_broken INTERFACE)
  41. # This is not a dependency, so broken will not be built (and the error in
  42. # it will not be hit)
  43. target_link_libraries(iface_broken INTERFACE broken)
  44. add_library(iface_whitelist INTERFACE)
  45. # The target property CUSTOM will never be evaluated on the INTERFACE library.
  46. target_link_libraries(iface_whitelist INTERFACE $<$<BOOL:$<TARGET_PROPERTY:CUSTOM>>:irrelevant>)
  47. add_executable(exec_whitelist dummy.cpp)
  48. target_link_libraries(exec_whitelist iface_whitelist)
  49. add_library(iface_imported INTERFACE IMPORTED)
  50. set_property(TARGET iface_imported PROPERTY
  51. INTERFACE_COMPILE_DEFINITIONS
  52. $<$<CONFIG:SPECIAL>:SPECIAL_MODE>
  53. $<$<CONFIG:Debug>:DEBUG_MODE>
  54. )
  55. set_property(TARGET iface_imported PROPERTY
  56. MAP_IMPORTED_CONFIG_DEBUG SPECIAL
  57. )
  58. add_executable(map_config map_config.cpp)
  59. target_link_libraries(map_config iface_imported)