mudlet/cmake/FindHUNSPELL.cmake
Stephen Lyons 2a90a8afc7
Enhance: enable builds in a full Windows MSYS2 environment (#3889)
* Enhance: enable builds in a full Windows MSYS2 environment (QMake only)

By defining `WITH_MAIN_BUILD_SYSTEM` to the value `NO` this PR makes enough
changes to the qmake project file to enable Mudlet to be compiled in a full
MSYS2 development environment (in the MSYS2 Qt Creator) - this will enable
easier development by Windows users (particularly those who also have some
familiarity with *nix systems) as I have documented at:
"Compiling on Windows 7+ (MSYS2_Alternative)" but it seems that the URL is
causing GitHub to forget about the PR as it seems to push and is recorded
in my local repository but never actually lands there!

It also makes some changes to the setting up of the LUA package paths for
the lua code formatter so that the paths are all entered with Unix style
directory separators but converted to whatever the Lua package handler is
set to use. In a Windows environment it is not unheard of to get both '\'
and '/' being used within the same path as different parts get generated
in stages - and using the backslash one can produce surprising error
messages if the back slash is not properly escaped when displaying those
messages in the main console or elsewhere (they dissappear entirely or
end up escaping following characters producing misleading information).

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Update src/mudlet.pro

BugFix: fix a typo in qmake project file.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Revise: reduce almost duplicate comments

Fix an addition to the `package.cpath` which would not have worked as it
did not specify the file extension which is OS dependent.

Also remove LuaJIT remenent, which we dropped support for a long time back.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Apply suggestions from code review

Revise: fix an error in a comment.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Revise: take out some pre-processor stuff as run-time code works without it

I was a bit sceptical at first but it *seems* to work.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Enhance: modifications to get CMake working on Windows

Revise a Mudlet specific CMake macro to not include the word "module" as
that is not appropriate for all usages now.

Fix an obscure CMake build error caused by the use of:
`LIBRARYNAME::LIBRARYNAME` in `target_link_libraries(...)` which is the
form for an interface usage of a library - this causes a failure of the
build with an error message of the form:
`src/CMakeFiles/mudlet.dir/build.make:1954: *** target pattern contains
no '%'.  Stop.` that line is actually one about one of the libraries
concerned - and it is the first one which shows up in that file with a
LIBRARYNAME-NOTFOUND entry. The fix seems to be to use only a LIBRARYNAME
form.

Fix a problem in `(static QString) mudlet::getShortPathName(const QString&
name)` which is cause by a Windows specific function that takes.returns
template/typedef type arguments which only work if the symbols
`UNICODE` and `_UNICODE` to be defined and which aren't in an MSYS2/
Mingw-w64 environment.

Revise some usages of the APP_BUILD defined value so that they are
handled correctly (using `QStringLiteral`/`QByteArray` wrapppers).

Change the CMake find module for Pugixml so that it uses a variable name in
ALL_UPPER_CASE to remove a developer warning about using a mixed case one.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Edit: fix copy paste issue

I thought something needed to be more conditional than it was but didn't
get it undone in last commit.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Refactor: simplify the code to set up the Lua/C additional paths for LCF

Peer-review suggested I needed to shrink the code.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Revise: shrink some comments

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Revise: implement some changes requested by peer-review

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Revise: shorten multi-line comment in initIndenterGlobals()

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Revise: further change suggested in peer-review

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

* Fix recognition of static libraries in own Find modules

Co-authored-by: keneanung <keneanung@googlemail.com>
2020-08-25 21:01:41 +02:00

115 lines
3.3 KiB
CMake

# Locate HUNSPELL library
# This module exports the following targets
#
# HUNSPELL::HUNSPELL
#
# This module defines
# HUNSPELL_FOUND, if false, do not try to link to HUNSPELL
# HUNSPELL_LIBRARY
# HUNSPELL_INCLUDE_DIR, where to find hunspell/*.h
find_package(PkgConfig)
pkg_search_module(PC_HUNSPELL hunspell libhunspell)
find_path(
HUNSPELL_INCLUDE_DIR hunspell/hunspell.h
HINTS ${HUNSPELL_DIR} $ENV{HUNSPELL_DIR} ${PC_HUNSPELL_INCLUDE_DIRS}
PATH_SUFFIXES include
PATHS ~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt)
find_library(
HUNSPELL_LIBRARY_RELEASE
NAMES hunspell
libhunspell
hunspell-1.7
hunspell-1.6
hunspell-1.5
hunspell-1.4
hunspell-1.3
HINTS ${HUNSPELL_DIR} $ENV{HUNSPELL_DIR} ${PC_HUNSPELL_LIBRARY_DIRS}
${PC_HUNSPELL_LIBRARY_DIR}
PATH_SUFFIXES lib64 lib
PATHS ~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt)
find_library(
HUNSPELL_LIBRARY_DEBUG
NAMES hunspelld
libhunspelld
hunspelld-1.7
hunspelld-1.6
hunspelld-1.5
hunspelld-1.4
hunspelld-1.3
HINTS ${HUNSPELL_DIR} $ENV{HUNSPELL_DIR} ${PC_HUNSPELL_LIBRARY_DIRS}
${PC_HUNSPELL_LIBRARY_DIR}
PATH_SUFFIXES lib64 lib
PATHS ~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt)
if(HUNSPELL_LIBRARY_DEBUG AND HUNSPELL_LIBRARY_RELEASE)
set(HUNSPELL_LIBRARY optimized ${HUNSPELL_LIBRARY_RELEASE} debug
${HUNSPELL_LIBRARY_DEBUG})
elseif(HUNSPELL_LIBRARY_RELEASE)
set(HUNSPELL_LIBRARY ${HUNSPELL_LIBRARY_RELEASE})
elseif(HUNSPELL_LIBRARY_DEBUG)
set(HUNSPELL_LIBRARY ${HUNSPELL_LIBRARY_DEBUG})
endif()
if(PC_HUNSPELL_hunspell_FOUND)
set(HUNSPELL_VERSION ${PC_HUNSPELL_hunspell_VERSION})
elseif(PC_HUNSPELL_libhunspell_FOUND)
set(HUNSPELL_VERSION ${PC_HUNSPELL_libhunspell_VERSION})
else()
set(HUNSPELL_VERSION ${PC_HUNSPELL_VERSION})
endif()
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set HUNSPELL_FOUND to TRUE if
# all listed variables are TRUE
find_package_handle_standard_args(
HUNSPELL REQUIRED_VARS HUNSPELL_LIBRARY HUNSPELL_INCLUDE_DIR VERSION_VAR
HUNSPELL_VERSION)
mark_as_advanced(HUNSPELL_INCLUDE_DIR HUNSPELL_LIBRARY HUNSPELL_LIBRARY_RELEASE
HUNSPELL_LIBRARY_DEBUG)
get_filename_component(HUNSPELL_FILENAME ${HUNSPELL_LIBRARY} NAME)
string(FIND ${HUNSPELL_FILENAME} .a HUNSPELL_STATIC)
if(HUNSPELL_FOUND AND NOT TARGET HUNSPELL::HUNSPELL)
if(HUNSPELL_STATIC EQUAL -1)
add_library(HUNSPELL::HUNSPELL SHARED IMPORTED)
set_target_properties(
HUNSPELL::HUNSPELL
PROPERTIES IMPORTED_LOCATION "${HUNSPELL_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${HUNSPELL_INCLUDE_DIR}")
else()
add_library(HUNSPELL::HUNSPELL STATIC IMPORTED)
set_target_properties(
HUNSPELL::HUNSPELL
PROPERTIES INTERFACE_COMPILE_DEFINITIONS HUNSPELL_STATIC
IMPORTED_LOCATION "${HUNSPELL_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${HUNSPELL_INCLUDE_DIR}")
endif()
endif()