CMakeLists.txt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. get_property(item_iface_dependencies TARGET item_iface PROPERTY MANUALLY_ADDED_DEPENDENCIES)
  26. link_directories(${CMAKE_CURRENT_BINARY_DIR})
  27. add_executable(InterfaceLibrary definetestexe.cpp)
  28. target_link_libraries(InterfaceLibrary
  29. iface_nodepends
  30. headeriface
  31. subiface
  32. intermediate
  33. item_iface
  34. item_fake # ensure that 'item_real' is ordered in place of item_iface
  35. )
  36. add_dependencies(InterfaceLibrary item_fake_tgt)
  37. add_subdirectory(libsdir)
  38. add_subdirectory(excluded EXCLUDE_FROM_ALL)
  39. add_executable(sharedlibtestexe sharedlibtestexe.cpp)
  40. target_link_libraries(sharedlibtestexe shared_iface imported::iface)
  41. add_library(broken EXCLUDE_FROM_ALL broken.cpp)
  42. add_library(iface_broken INTERFACE)
  43. # This is not a dependency, so broken will not be built (and the error in
  44. # it will not be hit)
  45. target_link_libraries(iface_broken INTERFACE broken)
  46. add_library(iface_whitelist INTERFACE)
  47. # The target property CUSTOM will never be evaluated on the INTERFACE library.
  48. target_link_libraries(iface_whitelist INTERFACE $<$<BOOL:$<TARGET_PROPERTY:CUSTOM>>:irrelevant>)
  49. add_executable(exec_whitelist dummy.cpp)
  50. target_link_libraries(exec_whitelist iface_whitelist)
  51. add_library(iface_imported INTERFACE IMPORTED)
  52. set_property(TARGET iface_imported PROPERTY
  53. INTERFACE_COMPILE_DEFINITIONS
  54. $<$<CONFIG:SPECIAL>:SPECIAL_MODE>
  55. $<$<CONFIG:Debug>:DEBUG_MODE>
  56. )
  57. set_property(TARGET iface_imported PROPERTY
  58. MAP_IMPORTED_CONFIG_DEBUG SPECIAL
  59. )
  60. add_executable(map_config map_config.cpp)
  61. target_link_libraries(map_config iface_imported)