aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2023-11-04 21:34:00 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2023-11-04 21:34:00 +0100
commitf2b0515fdd1cb84bebe24cac59498b682b49de80 (patch)
tree982de03ee12c0bc1e6114af6d53acd93af6180a0 /src
parentcdfb2d84b16cf363558d9d2534a26963b53d05b2 (diff)
downloadnotes-f2b0515fdd1cb84bebe24cac59498b682b49de80.tar.gz
notes-f2b0515fdd1cb84bebe24cac59498b682b49de80.zip
cmake: add note about PRIVATE/PUBLIC/INTERFACE
Diffstat (limited to 'src')
-rw-r--r--src/SUMMARY.md1
-rw-r--r--src/development/README.md1
-rw-r--r--src/development/cmake.md39
3 files changed, 41 insertions, 0 deletions
diff --git a/src/SUMMARY.md b/src/SUMMARY.md
index b6da0b7..a17f1ca 100644
--- a/src/SUMMARY.md
+++ b/src/SUMMARY.md
@@ -45,6 +45,7 @@
- [c++](./development/c++.md)
- [glibc](./development/glibc.md)
- [gcc](./development/gcc.md)
+ - [cmake](./development/cmake.md)
- [make](./development/make.md)
- [ld.so](./development/ld.so.md)
- [symbol versioning](./development/symbolver.md)
diff --git a/src/development/README.md b/src/development/README.md
index 117ef17..af18a02 100644
--- a/src/development/README.md
+++ b/src/development/README.md
@@ -4,6 +4,7 @@
- [c++](./c++.md)
- [glibc](./glibc.md)
- [gcc](./gcc.md)
+- [cmake](./cmake.md)
- [make](./make.md)
- [ld.so](./ld.so.md)
- [symbol versioning](./symbolver.md)
diff --git a/src/development/cmake.md b/src/development/cmake.md
new file mode 100644
index 0000000..d0bbeea
--- /dev/null
+++ b/src/development/cmake.md
@@ -0,0 +1,39 @@
+# cmake(1)
+
+## `PRIVATE` / `PUBLIC` / `INTERFACE`
+
+These modifier control where properties for a given target are visible.
+
+- `PRIVATE`: Only for the target itself.
+- `PUBLIC`: For the target itself and anyone linking against it.
+- `INTERFACE`: Only for anyone linking against the target.
+
+The following gives an example for preprocessor definitions specified on a
+library target. This behaves in the same way for other properties like for
+example include directories.
+```cmake
+# CMakeLists.txt
+
+cmake_minimum_required(VERSION 3.14)
+project(moose)
+
+# -- LIBRARY
+add_library(liba STATIC liba.cc)
+target_compile_definitions(liba PUBLIC DEF_PUBLIC)
+target_compile_definitions(liba PRIVATE DEF_PRIVATE)
+target_compile_definitions(liba INTERFACE DEF_INTERFACE)
+
+# -- APPLICATION
+add_executable(main main.cc)
+target_link_libraries(main liba)
+```
+
+```sh
+> touch liba.cc; echo "int main() {}" > main.cc
+> cmake -B build -S . -G Ninja
+> ninja -C build -j1 --verbose
+[1/4] /usr/bin/c++ -DDEF_PRIVATE -DDEF_PUBLIC [..] .../liba.cc
+[2/4] [..]
+[3/4] /usr/bin/c++ -DDEF_INTERFACE -DDEF_PUBLIC [..] .../main.cc
+[4/4] [..]
+```