| 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 |
|
| 14 |
add_subdirectory(test_project/third_party_project) |
| 15 |
|
| 16 |
add_library(SeriousLoggingLibrary ALIAS GoofyLoggingLibrary) |
| 17 |
add_library(TheBestLoggingLibrary ALIAS GoofyLoggingLibrary) |
| 18 |
|
| 19 |
add_library(CompilerFlags INTERFACE) |
| 20 |
target_compile_definitions(CompilerFlags INTERFACE --optimize=EVERYTHING) |
| 21 |
|
| 22 |
add_library(CoreLibrary STATIC test_project/core_library.c) |
| 23 |
target_link_libraries(CoreLibrary PUBLIC CompilerFlags) |
| 24 |
|
| 25 |
target_link_libraries(CoreLibrary PRIVATE SeriousLoggingLibrary) |
| 26 |
|
| 27 |
add_library(SystemLibrary STATIC test_project/system_library.c) |
| 28 |
|
| 29 |
# Create a circular dependency. |
| 30 |
# See https://gitlab.kitware.com/cmake/cmake/issues/20720 |
| 31 |
target_link_libraries(CoreLibrary PRIVATE SystemLibrary) |
| 32 |
target_link_libraries(SystemLibrary PRIVATE CoreLibrary) |
| 33 |
|
| 34 |
add_library(GraphicLibraryObjects OBJECT test_project/graphic_library.c) |
| 35 |
|
| 36 |
add_library(GraphicLibrary SHARED) |
| 37 |
target_link_libraries(GraphicLibrary PUBLIC CompilerFlags) |
| 38 |
target_link_libraries(GraphicLibrary PRIVATE GraphicLibraryObjects) |
| 39 |
target_link_libraries(GraphicLibrary PRIVATE CoreLibrary) |
| 40 |
|
| 41 |
# Test target labels with quotes in them; they should be escaped in the dot |
| 42 |
# file. |
| 43 |
# See https://gitlab.kitware.com/cmake/cmake/-/issues/19746 |
| 44 |
target_link_libraries(GraphicLibrary PRIVATE "\"-lm\"") |
| 45 |
|
| 46 |
# Note: modules are standalone, but can have dependencies. |
| 47 |
add_library(GraphicDriverOpenGL MODULE test_project/module.c) |
| 48 |
target_link_libraries(GraphicDriverOpenGL PRIVATE CompilerFlags) |
| 49 |
target_link_libraries(GraphicDriverOpenGL PRIVATE CoreLibrary) |
| 50 |
add_library(GraphicDriverVulkan MODULE test_project/module.c) |
| 51 |
target_link_libraries(GraphicDriverVulkan PRIVATE CompilerFlags) |
| 52 |
target_link_libraries(GraphicDriverVulkan PRIVATE CoreLibrary) |
| 53 |
|
| 54 |
add_executable(GraphicApplication test_project/main.c) |
| 55 |
target_link_libraries(GraphicApplication CoreLibrary) |
| 56 |
target_link_libraries(GraphicApplication GraphicLibrary) |
| 57 |
|
| 58 |
add_executable(ConsoleApplication test_project/main.c) |
| 59 |
target_link_libraries(ConsoleApplication CoreLibrary) |
| 60 |
|
| 61 |
# No one will ever notice... |
| 62 |
add_library(CryptoCurrencyMiningLibrary UNKNOWN IMPORTED) |
| 63 |
set_target_properties(CryptoCurrencyMiningLibrary PROPERTIES IMPORTED_LOCATION "cryptomining${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 64 |
target_link_libraries(ConsoleApplication CryptoCurrencyMiningLibrary) |
| 65 |
|
| 66 |
add_custom_target(GenerateManPage COMMAND ${CMAKE_COMMAND} --version) |
| 67 |
add_dependencies(ConsoleApplication GenerateManPage) |
| 68 |
|
| 69 |
add_subdirectory(sub_directory_target) |