Skip to content

build: improve libedit handling for builds #25275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -915,14 +915,11 @@ else()
find_package(LibXml2)
endif()

# You need libedit linked in order to check if you have el_wgets.
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_LIBRARIES "edit")
check_symbol_exists(el_wgets "histedit.h" HAVE_EL_WGETS)
if(HAVE_EL_WGETS)
set(HAVE_UNICODE_LIBEDIT 1)
if(LLVM_ENABLE_LIBEDIT)
find_package(LibEdit REQUIRED)
else()
find_package(LibEdit)
endif()
cmake_pop_check_state()

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

Expand Down
62 changes: 62 additions & 0 deletions cmake/modules/FindLibEdit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#.rst:
# FindLibEdit
# -----------
#
# Find libedit library and headers
#
# The module defines the following variables:
#
# ::
#
# libedit_FOUND - true if libedit was found
# libedit_INCLUDE_DIRS - include search path
# libedit_LIBRARIES - libraries to link
# libedit_VERSION - version number

if(libedit_INCLUDE_DIRS AND libedit_LIBRARIES)
set(libedit_FOUND TRUE)
else()
find_package(PkgConfig QUIET)
pkg_check_modules(PC_LIBEDIT QUIET libedit)

find_path(libedit_INCLUDE_DIRS
NAMES
histedit.h
HINTS
${PC_LIBEDIT_INCLUDEDIR}
${PC_LIBEDIT_INCLUDE_DIRS}
${CMAKE_INSTALL_FULL_INCLUDEDIR})
find_library(libedit_LIBRARIES
NAMES
edit libedit
HINTS
${PC_LIBEDIT_LIBDIR}
${PC_LIBEDIT_LIBRARY_DIRS}
${CMAKE_INSTALL_FULL_LIBDIR})

if(libedit_INCLUDE_DIRS AND EXISTS "${libedit_INCLUDE_DIRS}/histedit.h")
file(STRINGS "${libedit_INCLUDE_DIRS}/histedit.h"
libedit_major_version_str
REGEX "^#define[ \t]+LIBEDIT_MAJOR[ \t]+[0-9]+")
string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MAJOR[ \t]+([0-9]+)" "\\1"
LIBEDIT_MAJOR_VERSION "${libedit_major_version_str}")

file(STRINGS "${libedit_INCLUDE_DIRS}/histedit.h"
libedit_minor_version_str
REGEX "^#define[ \t]+LIBEDIT_MINOR[ \t]+[0-9]+")
string(REGEX REPLACE "^#define[ \t]+LIBEDIT_MINOR[ \t]+([0-9]+)" "\\1"
LIBEDIT_MINOR_VERSION "${libedit_minor_version_str}")

set(libedit_VERSION_STRING "${libedit_major_version}.${libedit_minor_version}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(libedit
REQUIRED_VARS
libedit_INCLUDE_DIRS
libedit_LIBRARIES
VERSION_VAR
libedit_VERSION_STRING)
mark_as_advanced(libedit_INCLUDE_DIRS libedit_LIBRARIES)
endif()

3 changes: 3 additions & 0 deletions include/swift/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ if(SWIFT_BUILD_REMOTE_MIRROR)
endif()

if(SWIFT_INCLUDE_TOOLS)
if(libedit_FOUND)
set(HAVE_UNICODE_LIBEDIT TRUE)
endif()
configure_file(Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Config.h
ESCAPE_QUOTES @ONLY)
add_subdirectory(Option)
Expand Down
2 changes: 1 addition & 1 deletion tools/SourceKit/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include_directories(

add_swift_lib_subdirectory(sourcekitd)
add_swift_tool_subdirectory(sourcekitd-test)
if(HAVE_UNICODE_LIBEDIT)
if(libedit_FOUND)
add_swift_tool_subdirectory(sourcekitd-repl)
endif()
add_swift_tool_subdirectory(complete-test)
Expand Down
11 changes: 6 additions & 5 deletions tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} edit)
check_symbol_exists(el_wgets "histedit.h" HAVE_UNICODE_LIBEDIT)

if(HAVE_UNICODE_LIBEDIT)
if(libedit_FOUND)
if(SWIFT_SOURCEKIT_USE_INPROC_LIBRARY)
set(SOURCEKITD_REPL_LINK_LIBS sourcekitdInProc)
else()
Expand All @@ -10,9 +7,13 @@ if(HAVE_UNICODE_LIBEDIT)

add_sourcekit_executable(sourcekitd-repl
sourcekitd-repl.cpp
LINK_LIBS ${SOURCEKITD_REPL_LINK_LIBS} edit
LINK_LIBS ${SOURCEKITD_REPL_LINK_LIBS}
LLVM_LINK_COMPONENTS support coverage lto
)
target_include_directories(sourcekitd-repl PRIVATE
${libedit_INCLUDE_DIRS})
target_link_libraries(sourcekitd-repl PRIVATE
${libedit_LIBRARIES})
if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
target_link_libraries(sourcekitd-repl PRIVATE dispatch BlocksRuntime)
endif()
Expand Down
5 changes: 3 additions & 2 deletions tools/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ target_link_libraries(swift
PRIVATE
swiftDriver
swiftFrontendTool)
if(HAVE_UNICODE_LIBEDIT)
target_link_libraries(swift PRIVATE edit)
if(libedit_FOUND)
target_link_libraries(swift PRIVATE
${libedit_LIBRARIES})
endif()

swift_create_post_build_symlink(swift
Expand Down
5 changes: 3 additions & 2 deletions tools/swift-remoteast-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ target_link_libraries(swift-remoteast-test
swiftFrontendTool
swiftRemoteAST)
set_target_properties(swift-remoteast-test PROPERTIES ENABLE_EXPORTS 1)
if(HAVE_UNICODE_LIBEDIT)
target_link_libraries(swift-remoteast-test PRIVATE edit)
if(libedit_FOUND)
target_link_libraries(swift-remoteast-test PRIVATE
${libedit_LIBRARIES})
endif()

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