Skip to content

Commit

Permalink
Detect readline library in CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
santhoshtr committed Oct 11, 2024
1 parent e837035 commit 572a0c7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.20)

list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/src/cmake")

find_package(FLEX)
find_package(BISON)
find_package(readline)

set(CMAKE_CXX_FLAGS "-O3 -Wall -std=c++17 -ansi")

Expand All @@ -21,6 +24,10 @@ else()
message(STATUS "Flex not found, so executables won't be generated.")
endif()

if(NOT READLINE_FOUND)
message(STATUS "Readline not found, so executables won't be generated.")
endif()

# Include dir
include_directories(/usr/local/include)

Expand Down
35 changes: 35 additions & 0 deletions src/cmake/Findreadline.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Try to find libreadline
# Once done, this will define
#
# READLINE_FOUND - system has readline
# READLINE_INCLUDE_DIRS - readline include directories
# READLINE_LIBRARIES - libraries need to use readline
#
# and the following imported targets
#
# READLINE::READLINE

find_path(READLINE_INCLUDE_DIR
NAMES readline/readline.h
HINTS ${READLINE_ROOT})

find_library(READLINE_LIBRARY
NAMES readline
HINTS ${READLINE_ROOT}
PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(readline
REQUIRED_VARS READLINE_LIBRARY READLINE_INCLUDE_DIR)

mark_as_advanced(READLINE_FOUND READLINE_LIBRARY READLINE_INCLUDE_DIR)

if (READLINE_FOUND AND NOT TARGET READLINE::READLINE)
add_library(READLINE::READLINE UNKNOWN IMPORTED)
set_target_properties(READLINE::READLINE PROPERTIES
IMPORTED_LOCATION "${READLINE_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${READLINE_INCLUDE_DIR}")
endif()

set(READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIR})
set(READLINE_LIBRARIES ${READLINE_LIBRARY})

0 comments on commit 572a0c7

Please sign in to comment.