awesomized / libmemcached

Resurrection of libmemcached
https://awesomized.github.io/libmemcached/
BSD 3-Clause "New" or "Revised" License
45 stars 26 forks source link

Problem including libmemcached in CMakeLists.txt #139

Open kwach opened 1 year ago

kwach commented 1 year ago

I'm trying to add libmemcached target in my project by

add_subdirectory(${AWESOMIZED_MEMCACHED_DIR})

and it seems that it fails to find _Configure:

CMake Error at cmake-build-debug/_deps/libmemcached-src/CMake/_Include.cmake:1 (include):
  include could not find requested file:

    _Configure

that is included from CMake/_Include like so:

include(_Configure)

I found that this fixes the issue:

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

And this is how I learned about difference :D

There is a difference between these variables. CMAKE_SOURCE_DIR does indeed refer to the folder where the top-level CMakeLists.txt is defined. However, PROJECT_SOURCE_DIR refers to the folder of the CMakeLists.txt containing the most recent project() command.

Thus in most cases PROJCET_SOURCE_DIR variable should be used

kwach commented 1 year ago

Also it might be a typo in

macro(check_symbol NAME HEADER)
    make_have_identifier(${NAME} HAVE)
    configure_define(${HAVE})
    cmake_push_check_state()
    if(${ARGC} GREATER 1)
        string(APPEND CMAKE_REQUIRED_FLAGS " ${ARGV2}")  # <--- here
    endif()
    list(APPEND CMAKE_REQUIRED_DEFINITIONS ${GLOBAL_DEFINITION_FLAGS})
    check_symbol_exists(${NAME} ${HEADER} ${HAVE})
    cmake_pop_check_state()
endmacro()

Probably should be:

macro(check_symbol NAME HEADER)
    make_have_identifier(${NAME} HAVE)
    configure_define(${HAVE})
    cmake_push_check_state()
    if(${ARGC} GREATER 1)
        string(APPEND CMAKE_REQUIRED_FLAGS " ${ARGN}")
    endif()
    list(APPEND CMAKE_REQUIRED_DEFINITIONS ${GLOBAL_DEFINITION_FLAGS})
    check_symbol_exists(${NAME} ${HEADER} ${HAVE})
    cmake_pop_check_state()
endmacro()

For some reason it contains a project directory and that breaks the check (ld) ARGN is always empty for me, anyway

m6w6 commented 1 year ago

Hi!

Thus in most cases PROJCET_SOURCE_DIR variable should be used

Thanks, that's very useful to know! I was learning CMake when I wrote all of this so, there might be some quirks!

I'm trying to add libmemcached target in my project by add_subdirectory(${AWESOMIZED_MEMCACHED_DIR})

Do you really need to include the source directory? I think CMake provides ways to build dep projects, or libmemcached should generate appropriate /usr/lib/cmake files on build/install.

Also it might be a typo in string(APPEND CMAKE_REQUIRED_FLAGS " ${ARGV2}") # <--- here

No, I don't think so, see https://cmake.org/cmake/help/latest/command/macro.html and https://cmake.org/cmake/help/latest/command/function.html It is for adding a custom compiler flag if needed to check for a symbol. Apparently it's not used anymore. The actual bug could be that ARGC should maybe checked to be greater than 2?

m6w6 commented 1 year ago

Nevertheless, thanks for your report. I'm open to bug fixes and PRs!