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

BUILD_INTERFACE fatal error: 'hiredis/hiredis.h' file not found #1270

Open
Portgas-D-Asce opened this issue Jul 25, 2024 · 2 comments
Open

Comments

@Portgas-D-Asce
Copy link

Portgas-D-Asce commented Jul 25, 2024

a strange thing in

TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

in INSTALL_INTERFACE, using #include <hiredis/hiredis.h> is ok

in BUILD_INTERFACE, I have to change it to #include <hiredis.h>

keep them same maybe better

@michael-grunder
Copy link
Collaborator

Can you provide some more context? What's failing exactly?

@Portgas-D-Asce
Copy link
Author

Can you provide some more context? What's failing exactly?

firstly, fetch hiredis into my project and use it by target_link_libraries

find_package(hiredis 1.2.0 QUIET)
if (NOT hiredis_FOUND)
    include(FetchContent)
    fetchcontent_declare(hiredis
        GIT_REPOSITORY https://github.com/redis/hiredis.git
        GIT_TAG v1.2.0
        SOURCE_DIR ${CMAKE_BINARY_DIR}/_deps/hiredis
    )
    fetchcontent_makeavailable(hiredis)
    if(NOT hiredis_POPULATED)
        message(FATAL_ERROR "fetch hiredis failed!")
    endif ()
endif ()

target_link_libraries(redis_pool
    PUBLIC
    hiredis::hiredis
)

then include <hiredis/hireids.h> in my header file,but clion complains "hiredis/hiredis.h file not found",so print redis::redis's properties

include(CMakePrintHelpers)
cmake_print_properties(
    TARGETS
    hiredis::hiredis
    PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES
)
# Properties for TARGET hiredis::hiredis:
#    hiredis::hiredis.INTERFACE_INCLUDE_DIRECTORIES = "$<INSTALL_INTERFACE:include>;$<BUILD_INTERFACE:/xx/Project/cmake-build-debug/_deps/hiredis>"

the reason why clion complains in BUILD_INTERFACE is obvious. it's why

  • in INSTALL_INTERFACE use include <hiredis/hireids.h>
  • in BUILD_INTERFACE have to use include <hireids.h>

in most of others libraries, both of them are same and better for using.

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