Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem including libmemcached in CMakeLists.txt #139

Open
kwach opened this issue Jun 5, 2023 · 3 comments
Open

Problem including libmemcached in CMakeLists.txt #139

kwach opened this issue Jun 5, 2023 · 3 comments

Comments

@kwach
Copy link

kwach commented Jun 5, 2023

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
Copy link
Author

kwach commented Jun 6, 2023

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
Copy link
Collaborator

m6w6 commented Jun 7, 2023

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
Copy link
Collaborator

m6w6 commented Jun 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants