我为Stanford Network Analysis Platform(SNAP)编写了一个包查找模块,该模块在macOS上按预期工作但在Linux上失败,出于某种原因,尽管显然找不到相关的路径/文件,但它仍然没有找到Snap。 / p>
FindSnap.cmake
:
include(FindPackageHandleStandardArgs)
set(Snap_ROOT_DIR $ENV{WORKSPACE_ROOT}/opt/Snap)
message(STATUS "Snap_ROOT_DIR: " ${Snap_ROOT_DIR})
find_path(Snap_CORE
NAMES "Snap.h"
PATH_SUFFIXES snap-core
HINTS ${Snap_ROOT_DIR}
DOC "The Snap include directory")
message(STATUS "Snap core: " ${Snap_CORE})
find_path(Snap_GLIB_CORE
NAMES "base.h"
PATH_SUFFIXES glib-core
HINTS ${Snap_ROOT_DIR}
DOC "The Snap GLib include directory")
message(STATUS "Glib core: " ${Snap_GLIB_CORE})
find_library(Snap_LIBRARY
NAMES libsnap.a
HINTS ${Snap_ROOT_DIR}/snap-core
DOC "The Snap library")
message(STATUS "Snap Library: " ${Snap_LIBRARY})
find_package_handle_standard_args(Snap_FOUND DEFAULT_MSG
Snap_CORE
Snap_GLIB_CORE
Snap_LIBRARY)
if (Snap_FOUND)
set(Snap_LIBRARIES ${Snap_LIBRARY})
set(Snap_INCLUDE_DIRS ${Snap_CORE} ${Snap_GLIB_CORE})
set(Snap_DEFINITIONS)
message(STATUS "Snap Found: " ${Snap_INCLUDE_DIRS})
else()
message(FATAL_ERROR "Package Snap not found")
endif (Snap_FOUND)
mark_as_advanced(Snap_ROOT_DIR Snap_INCLUDE_DIR Snap_LIBRARY)
在macOS上,Snap安装在/opt/Snap
中,此脚本将从CMakeLists.txt
find_package(Snap REQUIRED)
调用。在macOS上,这非常有效,但是在Ubuntu上,脚本报告找不到Snap,即使路径Snap_CORE
,Snap_GLIB_CORE
和Snap_LIBRARY
似乎已找到。在Mac上我使用cmake版本3.10.2,在Linux上我尝试了2.8和3.9版本,但我仍然有同样的错误。
由于我无法在Linux机器上修改/opt
,我在其他地方安装了Snap并修改了第二行的Snap根目录:
set(Snap_ROOT_DIR $ENV{WORKSPACE_ROOT}/elsewhere/Snap)
Linux机器上给出的错误:
-- Snap_ROOT_DIR: /afs/cs.stanford.edu/u/jdeaton/repos/snap
-- Snap core: /afs/cs.stanford.edu/u/jdeaton/repos/snap/snap-core
-- Glib core: /afs/cs.stanford.edu/u/jdeaton/repos/snap/glib-core
-- Snap Library: /afs/cs.stanford.edu/u/jdeaton/repos/snap/snap-core/libsnap.a
-- Found Snap_FOUND: /afs/cs.stanford.edu/u/jdeaton/repos/snap/snap-core
CMake Error at cmake/FindSnap.cmake:43 (message):
Package Snap not found
Call Stack (most recent call first):
CMakeLists.txt:6 (find_package)
看起来这应该可以正常工作,但不知何故它不起作用,只能在Linux上失败。
谢谢!
答案 0 :(得分:1)
find_package_handle_standard_args
的第一个参数应该是Snap
而不是Snap_FOUND
。
find_package_handle_standard_args(Snap DEFAULT_MSG
Snap_CORE
Snap_GLIB_CORE
Snap_LIBRARY)