4

I'm converting a project from Autotools to CMake. We have a configure.ac file, with the statement:

AC_CHECK_LIB([gsuffix], [gsuffix_create], [], AC_MSG_ERROR([Can not find gsuffix library]))

I want to replace it to cmake, and not sure how (it doesn't have pkg-config) What I need is:

  • check libgsuffix exists and find path.
  • Check gsuffix_create exists in libgsuffix
  • Add -lgsuffix to compilation - this I think I know how to do.

Can anyone point me to the right direction?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
Eyal H
  • 991
  • 5
  • 22

2 Answers2

2

There is no one to one translation. In general, with CMake you don't check whether every header and every library actually works. If you find the file, you assume it will do the trick.

  • Maybe find_package is right for you, depending someone already wrote such a test or your library provides an according config file.

  • Find_library is meant to find libraries, but by name.

  • If you really have to check that your library works, use CheckLibraryExists.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
1

As mentioned, did not find anyway to do this with one command.

I didn't have enough time to understand how to do something completely generic, so I can give my skeleton for a FindGSUFFIX.cmake:

FIND_LIBRARY(GSUFFIX_LIBRARY NAMES gsuffix)

INCLUDE(CheckLibraryExists)
CHECK_LIBRARY_EXISTS(gsuffix gsuffix_create ${GSUFFIX_LIBRARY} GSUFFIX_VERIFIED)

# Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GSUFFIX DEFAULT_MSG GSUFFIX_LIBRARY GSUFFIX_VERIFIED)

MARK_AS_ADVANCED(GSUFFIX_LIBRARY)
Eyal H
  • 991
  • 5
  • 22