CMakeTutorial icon indicating copy to clipboard operation
CMakeTutorial copied to clipboard

关于FindPackage的一个问题

Open Juddd opened this issue 3 years ago • 2 comments

请问find_package(GLOG)成功后如何用cmakelist.txt中把这个库的位置打印出来?我试着用message打印,好像只有message(${GLOG_FOUND})的值为1,你页面上说的GLOG_INCLUDE_DIR、GLOG_INCLUDES、GLOG_LIBRARY、GLOG_LIBRARIES这几个值都为空,但我想把这库的位置打印出来,请问我该怎么办呢

Juddd avatar Aug 22 '22 15:08 Juddd

你好,应该是只有内置模块会确定有这几个变量,如果是像glog这种,可能只会有target。https://cliutils.gitlab.io/modern-cmake/chapters/basics.html 这个教程的 Targets are your friend 章节,对target有详细的介绍。也就是说glog创建了一个target叫glog,里面应该已经包含了头文件,库文件等等,但是并没有将这些作为单独的变量设置出来。具体的它暴露了哪些变量,可以看glog中的CMakeLists.txt。

BrightXiaoHan avatar Aug 25 '22 08:08 BrightXiaoHan

嗯,我通过这里定义的print_target_properties把所有属性都打印出来: print_target_properties(glog::glog) image

Juddd avatar Sep 02 '22 10:09 Juddd