summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build6
-rw-r--r--src/libcamera/include/utils.h1
-rw-r--r--src/libcamera/utils.cpp49
3 files changed, 53 insertions, 3 deletions
diff --git a/meson.build b/meson.build
index c6e6a934..9fc5cc52 100644
--- a/meson.build
+++ b/meson.build
@@ -93,6 +93,12 @@ if get_option('test')
subdir('test')
endif
+# Create a symlink from the build root to the source root. This is used when
+# running libcamera from the build directory to locate resources in the source
+# directory (such as IPA configuration files).
+run_command('ln', '-fsT', meson.source_root(),
+ join_paths(meson.build_root(), 'source'))
+
configure_file(output : 'config.h', configuration : config_h)
pkg_mod = import('pkgconfig')
diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h
index 242eeded..3334ff16 100644
--- a/src/libcamera/include/utils.h
+++ b/src/libcamera/include/utils.h
@@ -188,6 +188,7 @@ private:
details::StringSplitter split(const std::string &str, const std::string &delim);
std::string libcameraBuildPath();
+std::string libcameraSourcePath();
} /* namespace utils */
diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp
index 97f9b632..a96ca7f4 100644
--- a/src/libcamera/utils.cpp
+++ b/src/libcamera/utils.cpp
@@ -10,10 +10,13 @@
#include <dlfcn.h>
#include <elf.h>
#include <iomanip>
+#include <limits.h>
#include <link.h>
#include <sstream>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
/**
@@ -360,9 +363,10 @@ bool isLibcameraInstalled()
*
* During development, it is useful to run libcamera binaries directly from the
* build directory without installing them. This function helps components that
- * need to locate resources, such as IPA modules or IPA proxy workers, by
- * providing them with the path to the root of the build directory. Callers can
- * then use it to complement or override searches in system-wide directories.
+ * need to locate resources in the build tree, such as IPA modules or IPA proxy
+ * workers, by providing them with the path to the root of the build directory.
+ * Callers can then use it to complement or override searches in system-wide
+ * directories.
*
* If libcamera has been installed, the build directory path is not available
* and this function returns an empty string.
@@ -385,6 +389,45 @@ std::string libcameraBuildPath()
return dirname(info.dli_fname) + "/../../";
}
+/**
+ * \brief Retrieve the path to the source directory
+ *
+ * During development, it is useful to run libcamera binaries directly from the
+ * build directory without installing them. This function helps components that
+ * need to locate resources in the source tree, such as IPA configuration
+ * files, by providing them with the path to the root of the source directory.
+ * Callers can then use it to complement or override searches in system-wide
+ * directories.
+ *
+ * If libcamera has been installed, the source directory path is not available
+ * and this function returns an empty string.
+ *
+ * \return The path to the source directory if running from a build directory,
+ * or an empty string otherwise
+ */
+std::string libcameraSourcePath()
+{
+ std::string path = libcameraBuildPath();
+ if (path.empty())
+ return std::string();
+
+ path += "source";
+
+ char *real = realpath(path.c_str(), nullptr);
+ if (!real)
+ return std::string();
+
+ path = real;
+ free(real);
+
+ struct stat statbuf;
+ int ret = stat(path.c_str(), &statbuf);
+ if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFDIR)
+ return std::string();
+
+ return path + "/";
+}
+
} /* namespace utils */
} /* namespace libcamera */
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455