From 53084dbfd860a2ae458c49135c059c1ab1561e85 Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Wed, 20 Jan 2021 09:39:03 +0100 Subject: [PATCH] CMake: in Hunspell ABI check only link if external (Thanks Scott for the patch and comment) For the HAVE_HUNSPELL_CXXABI check, only test a (real) link command if an external libhunspell is used or if macOS is used (see 350a9daf). If the bundled libhunspell is used, it has not been built yet at the point of the initial cmake command. This commit fixes an issue when the bundled Hunspell is desired. Before, the test command would still attempt to link to the system hunspell library. Even if the system library is available, there could be problems if there is a mismatch of the CXX ABI. And finally, even if the system library is available and there is no mismatch, compiling the test file with Clang and -stdlib=libc++ seems to cause a failure when linking with the system Hunspell library. --- development/cmake/ConfigureChecks.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/development/cmake/ConfigureChecks.cmake b/development/cmake/ConfigureChecks.cmake index 06c9a445ba..616bec0a10 100644 --- a/development/cmake/ConfigureChecks.cmake +++ b/development/cmake/ConfigureChecks.cmake @@ -88,6 +88,9 @@ if(HUNSPELL_FOUND) " ) +# The trick with faking the link command (see the else block) does not work +# with XCode (350a9daf). +if(APPLE OR LYX_EXTERNAL_HUNSPELL) try_compile(HAVE_HUNSPELL_CXXABI "${CMAKE_BINARY_DIR}" "${HunspellTestFile}" @@ -95,6 +98,17 @@ if(HUNSPELL_FOUND) "-DINCLUDE_DIRECTORIES:STRING=${HUNSPELL_INCLUDE_DIR}" LINK_LIBRARIES ${HUNSPELL_LIBRARY} OUTPUT_VARIABLE LOG2) +else() + try_compile(HAVE_HUNSPELL_CXXABI + "${CMAKE_BINARY_DIR}" + "${HunspellTestFile}" + CMAKE_FLAGS + "-DINCLUDE_DIRECTORIES:STRING=${HUNSPELL_INCLUDE_DIR}" + # At this point, ../lib/libhunspell.a has not been built so we + # cannot complete the linking. + "-DCMAKE_CXX_LINK_EXECUTABLE='${CMAKE_COMMAD} echo dummy (fake) link command since libhunspell.a not built yet.'" + OUTPUT_VARIABLE LOG2) +endif() message(STATUS "HAVE_HUNSPELL_CXXABI = ${HAVE_HUNSPELL_CXXABI}") #message(STATUS "LOG2 = ${LOG2}")