diff options
author | johannst <johannst@users.noreply.github.com> | 2024-04-05 23:16:19 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2024-04-05 23:16:19 +0000 |
commit | 63d71256f83e5da6479d90d1bbdaf17ad6d31f02 (patch) | |
tree | 764f346960e00afaf945673a365d0063f64f29ff /development | |
parent | 1d01762f8b174573dd58e6da1630bd92bc193512 (diff) | |
download | notes-63d71256f83e5da6479d90d1bbdaf17ad6d31f02.tar.gz notes-63d71256f83e5da6479d90d1bbdaf17ad6d31f02.zip |
deploy: c660b71b9689af89bc09671e6a6de7f9943e2709
Diffstat (limited to 'development')
-rw-r--r-- | development/cmake.html | 22 | ||||
-rw-r--r-- | development/cmake/module/.gitignore | 1 | ||||
-rw-r--r-- | development/cmake/module/CMakeLists.txt | 27 | ||||
-rw-r--r-- | development/cmake/module/Makefile | 14 | ||||
-rw-r--r-- | development/cmake/module/bar/BarConfig.cmake | 1 | ||||
-rw-r--r-- | development/cmake/module/bar/FindBar.cmake | 2 | ||||
-rw-r--r-- | development/cmake/module/cmake/moose.cmake | 7 | ||||
-rw-r--r-- | development/cmake/module/foo/FindFoo.cmake | 2 | ||||
-rw-r--r-- | development/cmake/module/foo/FooConfig.cmake | 1 |
9 files changed, 77 insertions, 0 deletions
diff --git a/development/cmake.html b/development/cmake.html index 85ed59f..7bc4339 100644 --- a/development/cmake.html +++ b/development/cmake.html @@ -177,6 +177,19 @@ <div id="content" class="content"> <main> <h1 id="cmake1"><a class="header" href="#cmake1">cmake(1)</a></h1> +<h2 id="frequently-used-variables"><a class="header" href="#frequently-used-variables">Frequently used variables</a></h2> +<pre><code># Install location. +CMAKE_INSTALL_PREFIX=<path> + +# Generate compile_commands.json? +CMAKE_EXPORT_COMPILE_COMMANDS={0,1} + +# Project build type. +CMAKE_BUILD_TYPE={Debug, Release, RelWithDebInfo, MinSizeRel} + +# C++ standard. +CMAKE_CXX_STANDARD={14,17,..} +</code></pre> <h2 id="private--public--interface"><a class="header" href="#private--public--interface"><code>PRIVATE</code> / <code>PUBLIC</code> / <code>INTERFACE</code></a></h2> <p>These modifier control where properties for a given target are visible.</p> <ul> @@ -211,6 +224,15 @@ target_link_libraries(main liba) [3/4] /usr/bin/c++ -DDEF_INTERFACE -DDEF_PUBLIC [..] .../main.cc [4/4] [..] </code></pre> +<h2 id="find_package-ref"><a class="header" href="#find_package-ref"><code>find_package</code> [<a href="https://cmake.org/cmake/help/latest/command/find_package.html">ref</a>]</a></h2> +<p>A small example to play with can be found in <a href="https://github.com/johannst/notes/tree/master/src/development/cmake/module">cmake/module</a>.</p> +<pre><code class="language-cmake">find_package(Name MODULE) +</code></pre> +<p>Looks for <code>FindName.cmake</code> in paths given by <code>CMAKE_MODULE_PATH</code> and then builtin paths.</p> +<pre><code class="language-cmake">find_package(Name CONFIG) +</code></pre> +<p>Looks for <code>name-config.cmake</code> or <code>NameConfig.cmake</code> in paths given by +<code>CMAKE_PREFIX_PATH</code>, or path given by <code>Name_DIR</code> and then builtin paths.</p> </main> diff --git a/development/cmake/module/.gitignore b/development/cmake/module/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/development/cmake/module/.gitignore @@ -0,0 +1 @@ +build diff --git a/development/cmake/module/CMakeLists.txt b/development/cmake/module/CMakeLists.txt new file mode 100644 index 0000000..f52d282 --- /dev/null +++ b/development/cmake/module/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.10) +project(hello-pkg) + +# Include as file. +include(cmake/moose.cmake) +# Include as module (search CMAKE_MODULE_PATH, then builtin paths). +include(moose) + +# -- Foo package --------------------------------------------------------------- + +# Find module (uses CMAKE_MODULE_PATH, Foo_DIR, builtin paths). +message("==> find_package(Foo MODULE)") +find_package(Foo MODULE) + +# Find config (uses CMAKE_PREFIX_PATH, Foo_DIR, builtin paths). +message("==> find_package(Foo CONFIG)") +find_package(Foo CONFIG REQUIRED) + +# -- Bar package --------------------------------------------------------------- + +# Find module (uses CMAKE_MODULE_PATH, Bar_DIR, builtin paths). +message("==> find_package(Bar MODULE)") +find_package(Bar MODULE) + +# Find config (uses CMAKE_PREFIX_PATH, Bar_DIR, builtin paths). +message("==> find_package(Bar CONFIG)") +find_package(Bar CONFIG REQUIRED) diff --git a/development/cmake/module/Makefile b/development/cmake/module/Makefile new file mode 100644 index 0000000..39f0389 --- /dev/null +++ b/development/cmake/module/Makefile @@ -0,0 +1,14 @@ +DBG ?= n +CMAKE_DBG-y = -DCMAKE_FIND_DEBUG_MODE=1 + +all: + @# CMAKE_MODULE_PATH for include() and find_package module flows. + @# CMAKE_PREFIX_PATH for find_package config flow. + @# Bar_DIR package specific for find_package config flow. + cmake . -B build -DCMAKE_MODULE_PATH="cmake;foo;bar" -DCMAKE_PREFIX_PATH="foo" -DBar_DIR=bar $(CMAKE_DBG-$(DBG)) + +debug: + $(MAKE) all DBG=y + +clean: + $(RM) -r build diff --git a/development/cmake/module/bar/BarConfig.cmake b/development/cmake/module/bar/BarConfig.cmake new file mode 100644 index 0000000..d5164cf --- /dev/null +++ b/development/cmake/module/bar/BarConfig.cmake @@ -0,0 +1 @@ +message("BarConfig invoked") diff --git a/development/cmake/module/bar/FindBar.cmake b/development/cmake/module/bar/FindBar.cmake new file mode 100644 index 0000000..f2047ea --- /dev/null +++ b/development/cmake/module/bar/FindBar.cmake @@ -0,0 +1,2 @@ +message("FindBar invoked") +set(Bar_FOUND 1) diff --git a/development/cmake/module/cmake/moose.cmake b/development/cmake/module/cmake/moose.cmake new file mode 100644 index 0000000..3052671 --- /dev/null +++ b/development/cmake/module/cmake/moose.cmake @@ -0,0 +1,7 @@ +# Add include guard with the scope of the includers directory downwards. +#include_guard(DIRECTORY) + +# Add global include guard (whole build). +#include_guard(GLOBAL) + +message("moose invoked") diff --git a/development/cmake/module/foo/FindFoo.cmake b/development/cmake/module/foo/FindFoo.cmake new file mode 100644 index 0000000..0653bb8 --- /dev/null +++ b/development/cmake/module/foo/FindFoo.cmake @@ -0,0 +1,2 @@ +message("FindFoo invoked") +set(Foo_FOUND 1) diff --git a/development/cmake/module/foo/FooConfig.cmake b/development/cmake/module/foo/FooConfig.cmake new file mode 100644 index 0000000..a575ef2 --- /dev/null +++ b/development/cmake/module/foo/FooConfig.cmake @@ -0,0 +1 @@ +message("FooConfig invoked") |