2

I am developing a project in C++ that utilizes RediSearch. I would like to be able to call RediSearch functions in a form similar to #include <redisearch/document.h> utilizing CMake without having to alter the RediSearch project.

This question should be applicable to using CMake with any external CMake project, but all I have found is very specific to a certain set of projects or simply do not work.

Attempts

I have attempted to use ExternalProject such as in this project, using Config files and find_package() as in this project, directly using add_subdirectory and target_link_libraries, linking to the src/ folder directly, etc.

I have also tried including the following lines in my CMakeLists.txt

set(RS_INCLUDE_DIR libs/RediSearch/src)

set(GCC_COVERAGE_COMPILE_FLAGS "-I${RS_INCLUDE_DIR} -Wall -g -fPIC -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")

include_directories(${RS_INCLUDE_DIR})

but receive the following error:

CMakeFiles/prjct.dir/src/main.cpp.o: In function `RedisModule_Init':
....
collect2: error: 1d returned 1 exit status
.... 

Resulting errors include but are not limited to:

  • Not being able to locate the package when using find_package (as described in the aforementioned projects) and presenting an error such as:
    • CMake Error at /opt/cmake-3.13.3-Linux-x86_64/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137
      Could NOT find RediSearch (missing: RediSearch_INCLUDE_DIR)
      Call Stack (most recent call first):
      /opt/cmake-3.13.3-Linux-x86_64/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
      cmake/FindRediSearch.cmake:27 (find_package_handle_standard_args)
      CMakeLists.txt:48 (find_package)
      
    
    
  • If CMake does not give any errors, then on make: redisearch/document.h: No such file or directory

To detail my project structure:

prjct
| src/
| | main.cpp
| include/
| | prjct/
| | | myheader.hpp
| libs/
| | RediSearch/     <- As git submodule
| cmake/
| | prjctConfig.cmake.in
| CMakeLists.txt

I want to, from any src/ file such as main.cpp, utilize RediSearch (or for that matter any project which would be built with CMake) in the form #include <redisearch/document.h>. I do not want to alter RediSearch files or configuration at all - everything should be conducted through my project.

Note: I am using cmake version 3.13.3

patyx
  • 324
  • 1
  • 3
  • 17
  • 1
    Please show what you have attempted with `CMake`. And explain what happened. – drescherjm Feb 12 '19 at 01:05
  • You want to use it as a library or over network? – Not_a_Golfer Feb 12 '19 at 11:47
  • @drescherjm as explained in my post I attempted the methods described [here](https://github.com/Crascit/DownloadProject) and [here](https://github.com/pabloariasal/modern-cmake-sample) in addition to directly including the project through the use of `add_subdirectory` and `target_link_libraries`. – patyx Feb 12 '19 at 14:54
  • @Not_a_Golfer yes, as a library. I have edited the post with an example of the desired project structure. – patyx Feb 12 '19 at 14:54
  • 1
    It relies a lot on redis proper and most of the code assumes it is running inside a redis instance. Unless your code is also a redis module, it will be painful. – Not_a_Golfer Feb 12 '19 at 15:25
  • @Not_a_Golfer would it therefore be more feasible to write a separate c++ client library such as [JRediSearch](https://github.com/RedisLabs/JRediSearch)? – patyx Feb 12 '19 at 15:30
  • 1
    Most certainly! – Not_a_Golfer Feb 12 '19 at 19:29
  • You could probably just utilize hiredis or a similar existing C library. A proper C++ client would be nice, though :) – Mark Nunberg Feb 13 '19 at 16:08

0 Answers0