diff --git a/CMakeLists.txt b/CMakeLists.txt index b3c5ad761..a55b5794e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,10 +58,13 @@ add_custom_target(clean_all find_package(Threads REQUIRED) # optional readline -find_package(Readline REQUIRED) -if (READLINE_FOUND) - include_directories(SYSTEM ${READLINE_INCLUDE_DIR}) - add_definitions(-DHAS_READLINE) +option(USE_READLINE "Use GNU Readline library if available (default ON). \ +Set this to OFF to prevent linking with Readline even if it is available." ON) +if (USE_READLINE) + find_package(Readline) + if (READLINE_FOUND) + add_definitions(-DHAS_READLINE) + endif() endif() # ----------------------------------------------------------------------------- @@ -265,7 +268,7 @@ set(memgraph_src_files set(MEMGRAPH_ALL_LIBS stdc++fs Threads::Threads fmt cppitertools antlr_opencypher_parser_lib dl glog gflags) if (READLINE_FOUND) - list(APPEND MEMGRAPH_ALL_LIBS ${READLINE_LIBRARY}) + list(APPEND MEMGRAPH_ALL_LIBS readline) endif() # STATIC library used by memgraph executables diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake index a2c93348f..9ef93ad58 100644 --- a/cmake/FindReadline.cmake +++ b/cmake/FindReadline.cmake @@ -5,6 +5,11 @@ # READLINE_LIBRARY will be a path to the library. # READLINE_INCLUDE_DIR will be a path to the include directory. # READLINE_FOUND will be TRUE if the library is found. +# +# If the library is found, an imported target `readline` will be provided. This +# can be used for linking via `target_link_libraries`, without the need to +# explicitly include READLINE_INCLUDE_DIR and link with READLINE_LIBRARY. For +# example: `target_link_libraries(my_executable readline)`. if (READLINE_LIBRARY AND READLINE_INCLUDE_DIR) set(READLINE_FOUND TRUE) else() @@ -24,4 +29,7 @@ else() endif() endif() mark_as_advanced(READLINE_LIBRARY READLINE_INCLUDE_DIR) + add_library(readline SHARED IMPORTED) + set_property(TARGET readline PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${READLINE_INCLUDE_DIR}) + set_property(TARGET readline PROPERTY IMPORTED_LOCATION ${READLINE_LIBRARY}) endif() diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt index 8f9d20c17..7fcfea517 100644 --- a/tests/manual/CMakeLists.txt +++ b/tests/manual/CMakeLists.txt @@ -1,10 +1,3 @@ -# optional readline -find_package(Readline) -if (READLINE_FOUND) - include_directories(SYSTEM ${READLINE_INCLUDE_DIR}) - add_definitions(-DHAS_READLINE) -endif() - # set current directory name as a test type get_filename_component(test_type ${CMAKE_CURRENT_SOURCE_DIR} NAME) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b805ec7d6..b1f04fb1e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -36,9 +36,8 @@ disallow_in_source_build() find_package(Threads REQUIRED) # optional readline -find_package(Readline REQUIRED) +find_package(Readline) if (READLINE_FOUND) - include_directories(SYSTEM ${READLINE_INCLUDE_DIR}) add_definitions(-DHAS_READLINE) endif() diff --git a/tools/apollo/build_release b/tools/apollo/build_release index de33e8009..9edcdb6cc 100644 --- a/tools/apollo/build_release +++ b/tools/apollo/build_release @@ -9,7 +9,7 @@ TIMEOUT=600 ./init bash -c "doxygen Doxyfile >/dev/null 2>/dev/null" cd build -cmake -DCMAKE_BUILD_TYPE=release .. +cmake -DCMAKE_BUILD_TYPE=Release -DUSE_READLINE=OFF .. TIMEOUT=1000 make -j$THREADS cd ../tools