Reputation: 4379
I wrote a package finding module for the Stanford Network Analysis Platform (SNAP), which works as expected on macOS but fails on Linux, for some reason it reports not finding Snap despite having apparently located the relevant paths/files.
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)
On macOS, Snap is installed in /opt/Snap
, and this script gets invoked from CMakeLists.txt
with find_package(Snap REQUIRED)
. On macOS, this works perfectly, however on Ubuntu, the script reports that Snap is not found, even though the paths Snap_CORE
, Snap_GLIB_CORE
, and Snap_LIBRARY
appear to have been located. On mac I am using cmake version 3.10.2 and on Linux I have tried both versions 2.8 and 3.9, and still I have the same error.
Since I cannot modify /opt
on the Linux machine, I have installed Snap elsewhere and modified the Snap root directory on the second line as:
set(Snap_ROOT_DIR $ENV{WORKSPACE_ROOT}/elsewhere/Snap)
The error given on the Linux machine:
-- 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)
It seems like this should work fine, but somehow it is not working, and only fails on Linux.
Thank you!
Upvotes: 2
Views: 289
Reputation: 4379
The first argument of find_package_handle_standard_args
should be Snap
instead of Snap_FOUND
.
find_package_handle_standard_args(Snap DEFAULT_MSG
Snap_CORE
Snap_GLIB_CORE
Snap_LIBRARY)
Upvotes: 1