summaryrefslogtreecommitdiff
path: root/mesonbuild/cmake/data/preload.cmake
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2020-02-19 20:05:19 +0100
committerDaniel Mensinger <daniel@mensinger-ka.de>2020-02-20 11:16:37 +0100
commit113ec96626fe7cd2edc0bc4815ae2fc21cfb0546 (patch)
treec793ed45ea352e1f4ceb9ef279f6f96ab64e526c /mesonbuild/cmake/data/preload.cmake
parent31eb41ec2fd2c7ed06406fb4e5ea87af5010d4e5 (diff)
downloadmeson-113ec96626fe7cd2edc0bc4815ae2fc21cfb0546.tar.gz
cmake: Fix relative paths for add_custom_{command,target}
Do this by tracking CMAKE_CURRENT_{SOURCE,BINARY}_DIR variables. This is achieved by injecting CMake code with CMAKE_PROJECT_INCLUDE and overriding some builtin functions with a wrapper that adds additional trace information.
Diffstat (limited to 'mesonbuild/cmake/data/preload.cmake')
-rw-r--r--mesonbuild/cmake/data/preload.cmake35
1 files changed, 35 insertions, 0 deletions
diff --git a/mesonbuild/cmake/data/preload.cmake b/mesonbuild/cmake/data/preload.cmake
new file mode 100644
index 000000000..30178fba5
--- /dev/null
+++ b/mesonbuild/cmake/data/preload.cmake
@@ -0,0 +1,35 @@
+if(MESON_PS_LOADED)
+ return()
+endif()
+
+set(MESON_PS_LOADED ON)
+
+# Dummy macros that have a special meaning in the meson code
+macro(meson_ps_execute_delayed_calls)
+endmacro()
+
+macro(meson_ps_reload_vars)
+endmacro()
+
+# Helper macro to inspect the current CMake state
+macro(meson_ps_inspect_vars)
+ set(MESON_PS_CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+ set(MESON_PS_CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+ meson_ps_execute_delayed_calls()
+endmacro()
+
+
+# Override some system functions with custom code and forward the args
+# to the original function
+macro(add_custom_command)
+ meson_ps_inspect_vars()
+ _add_custom_command(${ARGV})
+endmacro()
+
+macro(add_custom_target)
+ meson_ps_inspect_vars()
+ _add_custom_target(${ARGV})
+endmacro()
+
+set(MESON_PS_DELAYED_CALLS add_custom_command;add_custom_target)
+meson_ps_reload_vars()