summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt24
1 files changed, 15 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4871b35..9009ccd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,7 @@ include(CheckLibraryExists)
 include(CheckStructHasMember)
 include(CheckSymbolExists)
 include(CheckTypeSize)
+include(FindPkgConfig)
 include(GNUInstallDirs)
 
 check_c_source_compiles([[
@@ -121,17 +122,22 @@ check_struct_has_member(
 
 option(WITH_LIBEDIT "Compile with libedit support")
 if(WITH_LIBEDIT)
-	check_include_file("histedit.h" HAVE_HISTEDIT_H)
-	check_library_exists(edit history_init /usr/lib LIBEDIT_FOUND)
-	if(HAVE_HISTEDIT_H AND LIBEDIT_FOUND)
-		link_libraries(edit)
+	pkg_check_modules(LIBEDIT IMPORTED_TARGET libedit)
+	if(LIBEDIT_FOUND)
+		link_libraries(PkgConfig::LIBEDIT)
 	else()
-		message(SEND_ERROR "Can't find libedit.")
+		check_include_file("histedit.h" HAVE_HISTEDIT_H)
+		check_library_exists(edit history_init /usr/lib LIBEDIT_FOUND)
+		if(HAVE_HISTEDIT_H AND LIBEDIT_FOUND)
+			link_libraries(edit)
+		else()
+			message(SEND_ERROR "Can't find libedit.")
+		endif()
+		set(CMAKE_REQUIRED_LIBRARIES edit)
+		check_symbol_exists(
+			_el_fn_sh_complete "histedit.h" HAVE__EL_FN_SH_COMPLETE
+		)
 	endif()
-	set(CMAKE_REQUIRED_LIBRARIES edit)
-	check_symbol_exists(
-		_el_fn_sh_complete "histedit.h" HAVE__EL_FN_SH_COMPLETE
-	)
 else()
 	add_compile_definitions(SMALL)
 endif()