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.
This commit is contained in:
Kornel Benko 2021-01-20 09:39:03 +01:00
parent 0b31fcd083
commit 53084dbfd8

View File

@ -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}")