英文:
CMake find_package built from source
问题
I'm running a CMake script to build a tool on a SUSE machine where I dont have admin rights. All my libraries / packages are built from source or extracted from RPMs as prebuilt binaries.
In my CMake script, there is a line searching for a package like this:
find_package(PkgConfig 0.27.1 REQUIRED)
find_package(GTK2 2.4 REQUIRED gtk gtkmm)
pkg_check_modules(atkmm REQUIRED IMPORTED_TARGET atkmm-1.6>=2.24.2)
However, I get one set of warnings and one error about not being able to find gtkmm (warning) or atkmm (error).
-- Some or all of the gtkmm libraries were not found. (missing: GTK2_GTKMM_LIBRARY GTK2_GTKMM_INCLUDE_DIR GTK2_GTKMMCONFIG_INCLUDE_DIR GTK2_GDKMM_INCLUDE_DIR GTK2_GDKMMCONFIG_INCLUDE_DIR GTK2_GDKMM_LIBRARY GTK2_GLIBMM_INCLUDE_DIR GTK2_GLIBMMCONFIG_INCLUDE_DIR GTK2_GLIBMM_LIBRARY)
-- Found PkgConfig: /usr/bin/pkg-config (found suitable version "0.29.2", minimum required is "0.27.1")
-- Checking for module 'atkmm-1.6>=2.24.2'
-- No package 'atkmm-1.6' found
Reading the somewhat dense documentation, I stumbled through and created cmake/Modules/Findatkmm.cmake with one line:
set(ATKMM_LIBRARY ${HOME}/opt/atkmm/usr/lib64/libatkmm-1.6.so.1)
英文:
I'm running a CMake script to build a tool on a SUSE machine where I dont have admin rights. All my libraries / packages are built from source or extracted from RPMs as prebuilt binaries.
In my CMake script, there is a line searching for a package like this
find_package(PkgConfig 0.27.1 REQUIRED)
find_package(GTK2 2.4 REQUIRED gtk gtkmm)
pkg_check_modules(atkmm REQUIRED IMPORTED_TARGET atkmm-1.6>=2.24.2)
However I get one set of warnings and one error about not being able to find gtkmm (warning) or atkmm (error).
-- Some or all of the gtkmm libraries were not found. (missing: GTK2_GTKMM_LIBRARY GTK2_GTKMM_INCLUDE_DIR GTK2_GTKMMCONFIG_INCLUDE_DIR GTK2_GDKMM_INCLUDE_DIR GTK2_GDKMMCONFIG_INCLUDE_DIR GTK2_GDKMM_LIBRARY GTK2_GLIBMM_INCLUDE_DIR GTK2_GLIBMMCONFIG_INCLUDE_DIR GTK2_GLIBMM_LIBRARY)
-- Found PkgConfig: /usr/bin/pkg-config (found suitable version "0.29.2", minimum required is "0.27.1")
-- Checking for module 'atkmm-1.6>=2.24.2'
-- No package 'atkmm-1.6' found
Reading the somewhat dense documentation, I stumbled through and created cmake/Modules/Findatkmm.cmake with one line
set(ATKMM_LIBRARY ${HOME}/opt/atkmm/usr/lib64/libatkmm-1.6.so.1)
(Replaced actual home dir path with $HOME prefix for writing here). It still throws the same error when I try to run cmake
Clearly, I'm using this command wrong, and/or misunderstand what its supposed to be doing. Any guidance would be greatly appreciated.
答案1
得分: 0
pkg_check_modules
是基于 pkgconfig
及其 .pc
文件来查找依赖项的。默认情况下,pkgconfig
仅在 /usr/lib/pkgconfig
中搜索,但可以通过设置环境变量 PKG_CONFIG_PATH
来添加额外的搜索路径。此外,当您的 cmake_minimum_required
版本为3.1或更高时,CMake 默认还会将 CMAKE_PREFIX_PATH
中指定的所有路径添加到该环境变量中。
因此,您有两个选项:
- 在调用 CMake 之前自行设置
PKG_CONFIG_PATH
- 设置
CMAKE_PREFIX_PATH
在这两种情况下,您都需要将变量设置为包含 atkmm.pc
文件的目录,很可能在您的情况下是 ${HOME}/opt/atkmm/usr/lib64/pkgconfig
。如果一切配置正确,您将不需要直接设置 ATKMM_LIBRARY
变量。
英文:
pkg_check_modules
builds on top of pkgconfig
and its .pc
files to find dependencies. By default, pkgconfig
only searches in /usr/lib/pkgconfig
, but the environment variable PKG_CONFIG_PATH
can be set to add additional search paths. Additionally, when your cmake_minimum_required
version is 3.1 or later, CMake will by default also add all of the paths specified in CMAKE_PREFIX_PATH
to that env variable.
So you have two options:
- Setting
PKG_CONFIG_PATH
yourself before calling CMake - Setting
CMAKE_PREFIX_PATH
In both cases you'll need to set the variable to the directory containing the atkmm.pc
file, most likely ${HOME}/opt/atkmm/usr/lib64/pkgconfig
in your case. If everything is configured correctly you will not need to set the ATKMM_LIBRARY
variable directly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论