Skip to content

Commit 08af3bc

Browse files
authored
Merge pull request #25275 from compnerd/editing-editing
build: improve libedit handling for builds
2 parents fba5027 + aca0509 commit 08af3bc

File tree

7 files changed

+82
-17
lines changed

7 files changed

+82
-17
lines changed

CMakeLists.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -915,14 +915,11 @@ else()
915915
find_package(LibXml2)
916916
endif()
917917

918-
# You need libedit linked in order to check if you have el_wgets.
919-
cmake_push_check_state()
920-
list(APPEND CMAKE_REQUIRED_LIBRARIES "edit")
921-
check_symbol_exists(el_wgets "histedit.h" HAVE_EL_WGETS)
922-
if(HAVE_EL_WGETS)
923-
set(HAVE_UNICODE_LIBEDIT 1)
918+
if(LLVM_ENABLE_LIBEDIT)
919+
find_package(LibEdit REQUIRED)
920+
else()
921+
find_package(LibEdit)
924922
endif()
925-
cmake_pop_check_state()
926923

927924
check_symbol_exists(wait4 "sys/wait.h" HAVE_WAIT4)
928925

cmake/modules/FindLibEdit.cmake

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#.rst:
2+
# FindLibEdit
3+
# -----------
4+
#
5+
# Find libedit library and headers
6+
#
7+
# The module defines the following variables:
8+
#
9+
# ::
10+
#
11+
# libedit_FOUND - true if libedit was found
12+
# libedit_INCLUDE_DIRS - include search path
13+
# libedit_LIBRARIES - libraries to link
14+
# libedit_VERSION - version number
15+
16+
if(libedit_INCLUDE_DIRS AND libedit_LIBRARIES)
17+
set(libedit_FOUND TRUE)
18+
else()
19+
find_package(PkgConfig QUIET)
20+
pkg_check_modules(PC_LIBEDIT QUIET libedit)
21+
22+
find_path(libedit_INCLUDE_DIRS
23+
NAMES
24+
histedit.h
25+
HINTS
26+
${PC_LIBEDIT_INCLUDEDIR}
27+
${PC_LIBEDIT_INCLUDE_DIRS}
28+
${CMAKE_INSTALL_FULL_INCLUDEDIR})
29+
find_library(libedit_LIBRARIES
30+
NAMES
31+
edit libedit
32+
HINTS
33+
${PC_LIBEDIT_LIBDIR}
34+
${PC_LIBEDIT_LIBRARY_DIRS}
35+
${CMAKE_INSTALL_FULL_LIBDIR})
36+
37+
if(libedit_INCLUDE_DIRS AND EXISTS "${libedit_INCLUDE_DIRS}/histedit.h")
38+
file(STRINGS "${libedit_INCLUDE_DIRS}/histedit.h"
39+
libedit_major_version_str
40+
REGEX "^#define[ \t]+LIBEDIT_MAJOR[ \t]+[0-9]+")
41+
string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MAJOR[ \t]+([0-9]+)" "\\1"
42+
LIBEDIT_MAJOR_VERSION "${libedit_major_version_str}")
43+
44+
file(STRINGS "${libedit_INCLUDE_DIRS}/histedit.h"
45+
libedit_minor_version_str
46+
REGEX "^#define[ \t]+LIBEDIT_MINOR[ \t]+[0-9]+")
47+
string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MINOR[ \t]+([0-9]+)" "\\1"
48+
LIBEDIT_MINOR_VERSION "${libedit_minor_version_str}")
49+
50+
set(libedit_VERSION_STRING "${libedit_major_version}.${libedit_minor_version}")
51+
endif()
52+
53+
include(FindPackageHandleStandardArgs)
54+
find_package_handle_standard_args(libedit
55+
REQUIRED_VARS
56+
libedit_INCLUDE_DIRS
57+
libedit_LIBRARIES
58+
VERSION_VAR
59+
libedit_VERSION_STRING)
60+
mark_as_advanced(libedit_INCLUDE_DIRS libedit_LIBRARIES)
61+
endif()
62+

include/swift/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ if(SWIFT_BUILD_REMOTE_MIRROR)
55
endif()
66

77
if(SWIFT_INCLUDE_TOOLS)
8+
if(libedit_FOUND)
9+
set(HAVE_UNICODE_LIBEDIT TRUE)
10+
endif()
811
configure_file(Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Config.h
912
ESCAPE_QUOTES @ONLY)
1013
add_subdirectory(Option)

tools/SourceKit/tools/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include_directories(
66

77
add_swift_lib_subdirectory(sourcekitd)
88
add_swift_tool_subdirectory(sourcekitd-test)
9-
if(HAVE_UNICODE_LIBEDIT)
9+
if(libedit_FOUND)
1010
add_swift_tool_subdirectory(sourcekitd-repl)
1111
endif()
1212
add_swift_tool_subdirectory(complete-test)

tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} edit)
2-
check_symbol_exists(el_wgets "histedit.h" HAVE_UNICODE_LIBEDIT)
3-
4-
if(HAVE_UNICODE_LIBEDIT)
1+
if(libedit_FOUND)
52
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
63
set(SOURCEKITD_REPL_LINK_LIBS sourcekitdInProc)
74
else()
@@ -10,9 +7,13 @@ if(HAVE_UNICODE_LIBEDIT)
107

118
add_sourcekit_executable(sourcekitd-repl
129
sourcekitd-repl.cpp
13-
LINK_LIBS ${SOURCEKITD_REPL_LINK_LIBS} edit
10+
LINK_LIBS ${SOURCEKITD_REPL_LINK_LIBS}
1411
LLVM_LINK_COMPONENTS support coverage lto
1512
)
13+
target_include_directories(sourcekitd-repl PRIVATE
14+
${libedit_INCLUDE_DIRS})
15+
target_link_libraries(sourcekitd-repl PRIVATE
16+
${libedit_LIBRARIES})
1617
if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
1718
target_link_libraries(sourcekitd-repl PRIVATE dispatch BlocksRuntime)
1819
endif()

tools/driver/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ target_link_libraries(swift
99
PRIVATE
1010
swiftDriver
1111
swiftFrontendTool)
12-
if(HAVE_UNICODE_LIBEDIT)
13-
target_link_libraries(swift PRIVATE edit)
12+
if(libedit_FOUND)
13+
target_link_libraries(swift PRIVATE
14+
${libedit_LIBRARIES})
1415
endif()
1516

1617
swift_create_post_build_symlink(swift

tools/swift-remoteast-test/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ target_link_libraries(swift-remoteast-test
77
swiftFrontendTool
88
swiftRemoteAST)
99
set_target_properties(swift-remoteast-test PROPERTIES ENABLE_EXPORTS 1)
10-
if(HAVE_UNICODE_LIBEDIT)
11-
target_link_libraries(swift-remoteast-test PRIVATE edit)
10+
if(libedit_FOUND)
11+
target_link_libraries(swift-remoteast-test PRIVATE
12+
${libedit_LIBRARIES})
1213
endif()
1314

1415
# If building as part of clang, make sure the headers are installed.

0 commit comments

Comments
 (0)