aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/development/cmake/module
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-04-06 01:16:01 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-04-06 01:16:01 +0200
commitc660b71b9689af89bc09671e6a6de7f9943e2709 (patch)
treec14da0ff0caa101dd8906c231593c96c1204a3ec /src/development/cmake/module
parent7f8aef4d417e427153caba4255a2282cb9dd30d9 (diff)
downloadnotes-c660b71b9689af89bc09671e6a6de7f9943e2709.tar.gz
notes-c660b71b9689af89bc09671e6a6de7f9943e2709.zip
cmake: freq vars + module example
Diffstat (limited to 'src/development/cmake/module')
-rw-r--r--src/development/cmake/module/.gitignore1
-rw-r--r--src/development/cmake/module/CMakeLists.txt27
-rw-r--r--src/development/cmake/module/Makefile14
-rw-r--r--src/development/cmake/module/bar/BarConfig.cmake1
-rw-r--r--src/development/cmake/module/bar/FindBar.cmake2
-rw-r--r--src/development/cmake/module/cmake/moose.cmake7
-rw-r--r--src/development/cmake/module/foo/FindFoo.cmake2
-rw-r--r--src/development/cmake/module/foo/FooConfig.cmake1
8 files changed, 55 insertions, 0 deletions
diff --git a/src/development/cmake/module/.gitignore b/src/development/cmake/module/.gitignore
new file mode 100644
index 0000000..378eac2
--- /dev/null
+++ b/src/development/cmake/module/.gitignore
@@ -0,0 +1 @@
+build
diff --git a/src/development/cmake/module/CMakeLists.txt b/src/development/cmake/module/CMakeLists.txt
new file mode 100644
index 0000000..f52d282
--- /dev/null
+++ b/src/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/src/development/cmake/module/Makefile b/src/development/cmake/module/Makefile
new file mode 100644
index 0000000..39f0389
--- /dev/null
+++ b/src/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/src/development/cmake/module/bar/BarConfig.cmake b/src/development/cmake/module/bar/BarConfig.cmake
new file mode 100644
index 0000000..d5164cf
--- /dev/null
+++ b/src/development/cmake/module/bar/BarConfig.cmake
@@ -0,0 +1 @@
+message("BarConfig invoked")
diff --git a/src/development/cmake/module/bar/FindBar.cmake b/src/development/cmake/module/bar/FindBar.cmake
new file mode 100644
index 0000000..f2047ea
--- /dev/null
+++ b/src/development/cmake/module/bar/FindBar.cmake
@@ -0,0 +1,2 @@
+message("FindBar invoked")
+set(Bar_FOUND 1)
diff --git a/src/development/cmake/module/cmake/moose.cmake b/src/development/cmake/module/cmake/moose.cmake
new file mode 100644
index 0000000..3052671
--- /dev/null
+++ b/src/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/src/development/cmake/module/foo/FindFoo.cmake b/src/development/cmake/module/foo/FindFoo.cmake
new file mode 100644
index 0000000..0653bb8
--- /dev/null
+++ b/src/development/cmake/module/foo/FindFoo.cmake
@@ -0,0 +1,2 @@
+message("FindFoo invoked")
+set(Foo_FOUND 1)
diff --git a/src/development/cmake/module/foo/FooConfig.cmake b/src/development/cmake/module/foo/FooConfig.cmake
new file mode 100644
index 0000000..a575ef2
--- /dev/null
+++ b/src/development/cmake/module/foo/FooConfig.cmake
@@ -0,0 +1 @@
+message("FooConfig invoked")