I’m trying to use the cmake’s function:
CHECK_LIBRARY_EXISTS(library function location variable)
How can I check if the C++ library are available ?
CHECK_LIBRARY_EXISTS(yaml-cpp "YAML::Token" ${YAML-CPP_PATHS} HAVE_YAML-CPP)
IF(HAVE_YAML-CPP)
MESSAGE(STATUS "YAML-CPP libraries founded: OK")
ENDIF(HAVE_YAML-CPP)
IF(NOT HAVE_YAML-CPP)
MESSAGE(FATAL_ERROR "ERROR: unable to link YAML::Token")
ENDIF(NOT HAVE_YAML-CPP)
That code snip don’t work.
The
CheckLibraryExistsmodule only works for C symbols, not C++. Personally I would just usefind_libraryandfind_pathto find the library and include path. If the library doesn’t contain the right symbols, the user is going to notice soon enough during the linking…Since yaml-cpp installs a pkg-config file, you can also use the
FindPkgConfigmodule. However, since yaml-cpp itself is built using CMake, you should encourage them to actually install ayaml-cpp-config.cmakefile. See e.g. this tutorial for more information.