Search code examples
c++cmakevisual-studio-2017cmake-gui

Why can't Cmake find the library using include_directories?


I am trying to configure a project for Visual Studio 2017 in CMake and gives me the error: microhttpd NOT found This was the only problem while configuring it, I tried it turning the flag off and worked. I included these two lines:

include_directories(${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR}/include)

I had the microhttpd.h in includes and the libmicrohttpd.lib in the lib folder. How can I properly tweak the following code to find it(in CmakeLists.txt the part of Finding this library):

include_directories(${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR}/includes)

option(MICROHTTPD_REQUIRED "Enable or disable the requirement of microhttp (http deamon)" ON)
find_library(MHTD NAMES microhttpd)
if("${MHTD}" STREQUAL "MHTD-NOTFOUND")
    if(MICROHTTPD_REQUIRED)
        message(FATAL_ERROR "microhttpd NOT found: use `-DMICROHTTPD_REQUIRED=OFF` to build without http deamon support")
    else()
        message(STATUS "microhttpd NOT found: disable http server")
        add_definitions("-DCONF_NO_HTTPD")
    endif()
else()
    set(LIBS ${LIBS} ${MHTD})
endif()

Do I need to use other function than include_directories?


Solution

  • It should be:

    find_library(MHTD microhttpd "path/to/the/lib")
    

    The second parameter is the library filename. The third is the path where the library is located.