db41258d16
Ersetzt das Geruest (counter/notebook) durch ein echtes Beispiel und teilt es in zwei eigenstaendige Projekte, wie P1204R0 es fuer Bibliothek plus Programm verlangt. libpda: textfile (C, Datei-I/O und Feld-Escaping), calculator (Recursive-Descent-Parser mit std::expected), contact, editor, explorer. Exportiert pda::pda ueber install(EXPORT) und ist per find_package(pda) benutzbar. pda: Shell ohne Ein-/Ausgabe (execute() gibt Text zurueck, deshalb ohne Terminal testbar), REPL und Stapelbetrieb in main.cpp. examples/consumer und tools/check-install.sh pruefen die Export-Kette Ende-zu-Ende: installieren, dann ein fremdes Projekt dagegen bauen. docs/CMAKE.md erklaert das Target-Modell, PUBLIC/PRIVATE/INTERFACE, Generator-Ausdruecke, install/export und Symbolsichtbarkeit an diesem Projekt. 71 Tests gruen unter Homebrew-clang 22, Apple clang und GCC 16, statisch und shared, mit und ohne ASan/UBSan. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
32 lines
1.3 KiB
CMake
32 lines
1.3 KiB
CMake
# ---------------------------------------------------------------------------
|
|
# Beispiel: ein FREMDES Projekt benutzt libpda.
|
|
#
|
|
# Dieses Verzeichnis ist bewusst NICHT Teil des Superprojekts -- es wird
|
|
# nirgends per add_subdirectory eingebunden. Es wird eigenstaendig
|
|
# konfiguriert, gegen eine INSTALLIERTE libpda:
|
|
#
|
|
# cmake -S examples/consumer -B build/consumer \
|
|
# -DCMAKE_PREFIX_PATH=/pfad/zur/installation
|
|
#
|
|
# Genau das macht tools/check-install.sh automatisch. Wenn das hier baut, ist
|
|
# der Export in libpda/CMakeLists.txt korrekt -- und nur dann.
|
|
# ---------------------------------------------------------------------------
|
|
cmake_minimum_required(VERSION 3.28)
|
|
|
|
project(pda_consumer VERSION 1.0.0 LANGUAGES CXX)
|
|
|
|
# find_package sucht pdaConfig.cmake in CMAKE_PREFIX_PATH unter
|
|
# lib/cmake/pda/. Findet es die Datei nicht, bricht REQUIRED sofort ab --
|
|
# mit einer Meldung, die sagt, wo gesucht wurde.
|
|
find_package(pda 0.1 REQUIRED)
|
|
|
|
add_executable(consumer main.cpp)
|
|
|
|
# pda::pda -- der Name aus dem NAMESPACE-Argument von install(EXPORT).
|
|
# Include-Pfade, der C++23-Standard und die Bibliotheksdatei kommen alle
|
|
# ueber dieses eine Target. Kein target_include_directories noetig, kein
|
|
# -lpda, kein Pfad von Hand.
|
|
target_link_libraries(consumer PRIVATE pda::pda)
|
|
|
|
message(STATUS "consumer: libpda ${pda_VERSION} gefunden")
|