简体   繁体   English

安装CMake之后,我找不到带有`find_package`的软件包

[英]After CMake install, I can't find a package with `find_package`

I have installed a library (SDL) with the following command: 我已经使用以下命令安装了库(SDL):

cmake --build . --target install

I read in the documentation that installed packages are going to be registered in the CMAKE_SYSTEM_PREFIX_PATH . 我在文档中读到,已安装的软件包将在CMAKE_SYSTEM_PREFIX_PATH进行注册。

But when I print out the variable it is empty. 但是当我打印出变量时,它是空的。

Currently I am using Windows, and I read online that I should register the installation path in the registry, but it did not help at all. 当前,我正在使用Windows,并且在网上阅读了我应该在注册表中注册安装路径的信息,但是它根本没有帮助。

How can I find, for example, SDL with find_package()? 例如,如何查找带有find_package()的SDL?

Try this: 尝试这个:

Using the get_cmake_property function the following loop will print out all CMake variables defined and their values: 使用get_cmake_property函数,以下循环将打印出所有已定义的CMake变量及其值:

 get_cmake_property(_variableNames VARIABLES) list (SORT _variableNames) foreach (_variableName ${_variableNames}) message(STATUS "${_variableName}=${${_variableName}}") endforeach() 

To print environment variables use CMake's command mode: 要打印环境变量,请使用CMake的命令模式:

 execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment") 

It prints: 它打印:

-- CMAKE_SYSTEM_PREFIX_PATH=/usr/local;/usr;/;/usr;/usr/local;/usr/X11R6;/usr/pkg;/opt

(Credits to Sakra ) 归功于Sakra

You can search your source tree for a file named FindSDL*.cmake then try to find this file in your CMAKE_SYSTEM_PREFIX_PATH directories. 您可以在源树中搜索名为FindSDL*.cmake文件,然后尝试在CMAKE_SYSTEM_PREFIX_PATH目录中找到该文件。

If CMAKE_SYSTEM_PREFIX_PATH is still empty, try to locate FindSDL*.cmake in your entire computer to check whether files are being installed somewhere cmake knows or try to append this path to your CMAKE_SYSTEM_PREFIX_PATH . 如果CMAKE_SYSTEM_PREFIX_PATH仍然为空,请尝试在整个计算机中找到FindSDL*.cmake ,以检查是否在cmake知道的位置安装了文件,或尝试将此路径附加到CMAKE_SYSTEM_PREFIX_PATH

You can also check this link: Using SDL2 with CMake 您也可以检查此链接: 将SDL2与CMake一起使用

I believe the reason this wasn't working for you is because your find_package command came before your project command in your CMakeLists.txt file. 我认为这对您不起作用的原因是,您的find_package命令位于CMakeLists.txt文件中的project命令之前。 If you ensure project is the first command (after cmake_minimum_required(VERSION <NUM> ) then all of the CMAKE_SYSTEM_*** variables will be initialized correctly :) 如果确保project是第一个命令(在cmake_minimum_required(VERSION <NUM> ),则所有CMAKE_SYSTEM_***变量都将正确初始化:)

I actually stumbled across this post after having the exact same problem (see my comment on the initial question). 在遇到完全相同的问题后,我实际上偶然发现了该帖子(请参阅我对第一个问题的评论)。 I tried the advice posted by j4x using the foreach VARIABLES command to print all the variables and serendipitously pasted it after my project command. 我使用了foreach VARIABLES命令尝试了j4x发布的建议,以打印所有变量,并在我的project命令之后偶然地将其粘贴。 I noticed CMAKE_SYSTEM_PREFIX_PATH was a sensible value - I then moved the code above the project command and noticed far fewer variables were printed :P CMAKE_SYSTEM_PREFIX_PATH was no where to be seen... 我注意到CMAKE_SYSTEM_PREFIX_PATH是一个合理的值-然后我将代码移到了project命令上方,并注意到打印出的变量少得多:P CMAKE_SYSTEM_PREFIX_PATH在哪里都看不到...

I hope this works for you too! 我希望这也对您有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM