libcamera: utils: Add a function to retrieve the libcamera source tree
Similarly to libcameraBuildPath(), there's a need to locate resources within the source tree when running libcamera without installing it. Support this use case with a new utils::libcameraSourcePath() function. The implementation uses a symlink from the build root to the source root in order to avoid hardcoding the path to the source root in the libcamera.so binary. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
6e1cd1394e
commit
cc15ab4316
3 changed files with 53 additions and 3 deletions
|
@ -93,6 +93,12 @@ if get_option('test')
|
||||||
subdir('test')
|
subdir('test')
|
||||||
endif
|
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)
|
configure_file(output : 'config.h', configuration : config_h)
|
||||||
|
|
||||||
pkg_mod = import('pkgconfig')
|
pkg_mod = import('pkgconfig')
|
||||||
|
|
|
@ -188,6 +188,7 @@ private:
|
||||||
details::StringSplitter split(const std::string &str, const std::string &delim);
|
details::StringSplitter split(const std::string &str, const std::string &delim);
|
||||||
|
|
||||||
std::string libcameraBuildPath();
|
std::string libcameraBuildPath();
|
||||||
|
std::string libcameraSourcePath();
|
||||||
|
|
||||||
} /* namespace utils */
|
} /* namespace utils */
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,13 @@
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <elf.h>
|
#include <elf.h>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <limits.h>
|
||||||
#include <link.h>
|
#include <link.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -360,9 +363,10 @@ bool isLibcameraInstalled()
|
||||||
*
|
*
|
||||||
* During development, it is useful to run libcamera binaries directly from the
|
* During development, it is useful to run libcamera binaries directly from the
|
||||||
* build directory without installing them. This function helps components that
|
* build directory without installing them. This function helps components that
|
||||||
* need to locate resources, such as IPA modules or IPA proxy workers, by
|
* need to locate resources in the build tree, such as IPA modules or IPA proxy
|
||||||
* providing them with the path to the root of the build directory. Callers can
|
* workers, by providing them with the path to the root of the build directory.
|
||||||
* then use it to complement or override searches in system-wide directories.
|
* 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
|
* If libcamera has been installed, the build directory path is not available
|
||||||
* and this function returns an empty string.
|
* and this function returns an empty string.
|
||||||
|
@ -385,6 +389,45 @@ std::string libcameraBuildPath()
|
||||||
return dirname(info.dli_fname) + "/../../";
|
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 utils */
|
||||||
|
|
||||||
} /* namespace libcamera */
|
} /* namespace libcamera */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue