0

I've installed libevent on macOS -

$ brew install libevent

I'm trying to import it in my CMakeLists.txt -

cmake_minimum_required(VERSION 3.14)
project(xyz)
set(CMAKE_CXX_STANDARD 17)
find_package(libevent REQUIRED)

I get the following CMake error -

CMake Error at CMakeLists.txt:6 (find_package):
  By not providing "Findlibevent.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "libevent",
  but CMake did not find one.

  Could not find a package configuration file provided by "libevent" with any
  of the following names:

    libeventConfig.cmake
    libevent-config.cmake

  Add the installation prefix of "libevent" to CMAKE_PREFIX_PATH or set
  "libevent_DIR" to a directory containing one of the above files.  If
  "libevent" provides a separate development package or SDK, be sure it has
  been installed.

Could someone please tell how to import libevent installed in the system in CMake?

Gautham
  • 766
  • 7
  • 15

2 Answers2

0

I have same trouble but I work arond this by adding:

link_directories(
  /usr/local/lib
  /usr/lib
)
INCLUDE_DIRECTORIES(
  /usr/local/include/
  /usr/include
)

It just tell the Makefile where to find libevent header and library.

Jasper Li
  • 1
  • 1
0
  1. You must install pkg-config

    brew install pkg-config
    
  2. then in CMakeList.txt

    find_package(PkgConfig QUIET)
    if(PKG_CONFIG_FOUND)
        pkg_search_module(LIBEVENT libevent )
        if (LIBEVENT_FOUND)
            message(STATUS "Found libevent ${LIBEVENT_FOUND}")
            message(STATUS "libevent inc : ${LIBEVENT_INCLUDE_DIRS}")
            message(STATUS "libevent lib : ${LIBEVENT_LIBRARIES}")
        endif ()
    endif()
    
    # ...
    add_executable(${PROJECT_NAME} ${SRC_FILES})
    target_include_directories(${PROJECT_NAME} PRIVATE ${LIBEVENT_INCLUDE_DIRS})
    target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBEVENT_LIBRARIES})
    
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Dean Wong
  • 116
  • 4