GraphvizTestProject.cmake 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # For the sake of clarity, we model a dummy but realistic application:
  2. #
  3. # - We have two executables, for a console and a GUI variant of that app
  4. # - Both executables depend on a CoreLibrary (STATIC)
  5. # - The GUI executable also depends on a GraphicLibrary (SHARED)
  6. # - We build two GraphicDrivers as MODULEs
  7. # - The CoreLibrary depends on a third-party header-only (INTERFACE)
  8. # GoofyLoggingLibrary, which we rename using an ALIAS for obvious reasons
  9. # - All library depend on a common INTERFACE library holding compiler flags
  10. # - We have a custom target to generate a man page
  11. # - Someone has added an UNKNOWN, IMPORTED crypto mining library!
  12. # - We have a circular dependency between two libraries
  13. add_subdirectory(test_project/third_party_project)
  14. add_library(SeriousLoggingLibrary ALIAS GoofyLoggingLibrary)
  15. add_library(TheBestLoggingLibrary ALIAS GoofyLoggingLibrary)
  16. add_library(CompilerFlags INTERFACE)
  17. target_compile_definitions(CompilerFlags INTERFACE --optimize=EVERYTHING)
  18. add_library(CoreLibrary STATIC test_project/core_library.c)
  19. target_link_libraries(CoreLibrary PUBLIC CompilerFlags)
  20. target_link_libraries(CoreLibrary PRIVATE SeriousLoggingLibrary)
  21. add_library(SystemLibrary STATIC test_project/system_library.c)
  22. # Create a circular dependency.
  23. # See https://gitlab.kitware.com/cmake/cmake/issues/20720
  24. target_link_libraries(CoreLibrary PRIVATE SystemLibrary)
  25. target_link_libraries(SystemLibrary PRIVATE CoreLibrary)
  26. add_library(GraphicLibraryObjects OBJECT test_project/graphic_library.c)
  27. add_library(GraphicLibrary SHARED)
  28. target_link_libraries(GraphicLibrary PUBLIC CompilerFlags)
  29. target_link_libraries(GraphicLibrary PRIVATE GraphicLibraryObjects)
  30. target_link_libraries(GraphicLibrary PRIVATE CoreLibrary)
  31. # Test target labels with quotes in them; they should be escaped in the dot
  32. # file.
  33. # See https://gitlab.kitware.com/cmake/cmake/-/issues/19746
  34. target_link_libraries(GraphicLibrary PRIVATE "\"-lm\"")
  35. # Note: modules are standalone, but can have dependencies.
  36. add_library(GraphicDriverOpenGL MODULE test_project/module.c)
  37. target_link_libraries(GraphicDriverOpenGL PRIVATE CompilerFlags)
  38. target_link_libraries(GraphicDriverOpenGL PRIVATE CoreLibrary)
  39. add_library(GraphicDriverVulkan MODULE test_project/module.c)
  40. target_link_libraries(GraphicDriverVulkan PRIVATE CompilerFlags)
  41. target_link_libraries(GraphicDriverVulkan PRIVATE CoreLibrary)
  42. add_executable(GraphicApplication test_project/main.c)
  43. target_link_libraries(GraphicApplication CoreLibrary)
  44. target_link_libraries(GraphicApplication GraphicLibrary)
  45. add_executable(ConsoleApplication test_project/main.c)
  46. target_link_libraries(ConsoleApplication CoreLibrary)
  47. # No one will ever notice...
  48. add_library(CryptoCurrencyMiningLibrary UNKNOWN IMPORTED)
  49. target_link_libraries(ConsoleApplication CryptoCurrencyMiningLibrary)
  50. add_custom_target(GenerateManPage COMMAND ${CMAKE_COMMAND} --version)
  51. add_dependencies(ConsoleApplication GenerateManPage)