Skip to content

Commit

Permalink
Enhance: modifications to get CMake working on Windows
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
SlySven committed Jul 5, 2020
1 parent bd5346d commit 88ad45f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 33 deletions.
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,22 @@ include_optional_module(ENVIRONMENT_VARIABLE WITH_UPDATER
"Windows"
"Darwin")

include_optional_module(ENVIRONMENT_VARIABLE WITH_FONTS OPTION_VARIABLE
USE_FONTS READABLE_NAME "fonts")
include_optional_module(ENVIRONMENT_VARIABLE WITH_3DMAPPER OPTION_VARIABLE
USE_3DMAPPER READABLE_NAME "3D mapper")
include_optional_module(ENVIRONMENT_VARIABLE WITH_FONTS
OPTION_VARIABLE USE_FONTS
READABLE_NAME "fonts")
include_optional_module(ENVIRONMENT_VARIABLE WITH_3DMAPPER
OPTION_VARIABLE USE_3DMAPPER
READABLE_NAME "3D mapper")
include_optional_module(ENVIRONMENT_VARIABLE WITH_VARIABLE_SPLASH_SCREEN
OPTION_VARIABLE USE_VARIABLE_SPLASH_SCREEN
READABLE_NAME "build-type splash screen")
include_optional_module(ENVIRONMENT_VARIABLE WITH_OWN_QTKEYCHAIN
OPTION_VARIABLE USE_OWN_QT5KEYCHAIN
READABLE_NAME "own QKeychain (Qt5) library")
include_optional_module(ENVIRONMENT_VARIABLE WITH_MAIN_BUILD_SYSTEM
OPTION_VARIABLE USE_MAIN_BUILD_SYSTEM
READABLE_NAME "original CI (setup-windows-sdk.ps1) windows build system"
SUPPORTED_SYSTEMS "Windows")

include(InitGitSubmodule)

Expand Down
2 changes: 1 addition & 1 deletion cmake/FindPUGIXML.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ endif()

include(FindPackageHandleStandardArgs)
# Support the REQUIRED and QUIET arguments, and set PUGIXML_FOUND if found.
find_package_handle_standard_args(PugiXML REQUIRED_VARS PUGIXML_LIBRARY
find_package_handle_standard_args(PUGIXML REQUIRED_VARS PUGIXML_LIBRARY
PUGIXML_INCLUDE_DIR VERSION_VAR PUGIXML_VER)

if(PUGIXML_FOUND AND NOT TARGET PUGIXML::PUGIXML)
Expand Down
10 changes: 5 additions & 5 deletions cmake/IncludeOptionalModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,34 @@ macro(include_optional_module)
set(OPTIONAL_MODULE_OPTION_VALUE OFF)
message(
STATUS
"Excluding optional ${OPTIONAL_MODULE_READABLE_NAME} module explicitly"
"Excluding optional ${OPTIONAL_MODULE_READABLE_NAME} explicitly"
)
else()
# Any other value was seen so ignore it and set "yes, include the
# module"
set(OPTIONAL_MODULE_OPTION_VALUE ON)
message(
STATUS
"Including optional ${OPTIONAL_MODULE_READABLE_NAME} module explicitly"
"Including optional ${OPTIONAL_MODULE_READABLE_NAME} explicitly"
)
endif()
else()
# An environmental variable not detected, apply platform default of "yes,
# include the module"
set(OPTIONAL_MODULE_OPTION_VALUE ON)
message(
STATUS "Including optional ${OPTIONAL_MODULE_READABLE_NAME} module")
STATUS "Including optional ${OPTIONAL_MODULE_READABLE_NAME}")
endif()
option(${OPTIONAL_MODULE_OPTION_VARIABLE}
"Include optional ${OPTIONAL_MODULE_READABLE_NAME} module"
"Include optional ${OPTIONAL_MODULE_READABLE_NAME}"
${OPTIONAL_MODULE_OPTION_VALUE})
else()
# Don't offer option to enable the module since it's not supported on this
# platform
set(${OPTIONAL_MODULE_OPTION_VARIABLE} OFF)
message(
STATUS
"Excluding optional ${OPTIONAL_MODULE_READABLE_NAME} module as it is not supported on this platform"
"Excluding optional ${OPTIONAL_MODULE_READABLE_NAME} as it is not supported on this platform"
)
endif()

Expand Down
90 changes: 68 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,30 +358,66 @@ target_compile_definitions(mudlet

if(USE_OWN_QT5KEYCHAIN)
# An extra definition is needed if we are using our own QtKeyChain to not
# export symbols from our self-built library:
target_compile_definitions(mudlet PRIVATE INCLUDE_OWN_QT5_KEYCHAIN QTKEYCHAIN_NO_EXPORT)
# export symbols from our self-built library and we are NOT on Windows;
# if we ARE on Windows this is not to be defined so that a header file
# "qkeychain_export.h" is created and set up so that the functions are
# marked for export from the ".dll" during their compilation but not later
# on, when instead they are marked for import by the Windows dynamic linker:
target_compile_definitions(mudlet PRIVATE INCLUDE_OWN_QT5_KEYCHAIN)
if(WIN32)
target_compile_definitions(mudlet PRIVATE INCLUDE_OWN_QT5_KEYCHAIN)
else()
target_compile_definitions(mudlet PRIVATE INCLUDE_OWN_QT5_KEYCHAIN QTKEYCHAIN_NO_EXPORT)
endif()
endif()

target_link_libraries(
mudlet
communi
edbee-lib
Boost::boost
HUNSPELL::HUNSPELL
LUA51::LUA51
PCRE::PCRE
PUGIXML::PUGIXML
Qt5::Concurrent
Qt5::Core
Qt5::Network
Qt5::Multimedia
Qt5::OpenGL
Qt5::UiTools
Qt5::Widgets
YAJL::YAJL
ZIP::ZIP
ZLIB::ZLIB
qt5keychain)
if(WIN32 AND NOT USE_MAIN_BUILD_SYSTEM)
# For this combination the use of an INTERFACE definition (with the library
# name listed twice with "::" separators of some libraries causes build
# failures with an obscure error message of the form:
# "src/CMakeFiles/mudlet.dir/build.make:1954: *** target pattern contains no '%'. Stop."
target_link_libraries(
mudlet
communi
edbee-lib
Boost::boost
HUNSPELL
LUA51::LUA51
PCRE
PUGIXML::PUGIXML
Qt5::Concurrent
Qt5::Core
Qt5::Network
Qt5::Multimedia
Qt5::OpenGL
Qt5::UiTools
Qt5::Widgets
YAJL
ZIP
ZLIB::ZLIB
qt5keychain)
else()
target_link_libraries(
mudlet
communi
edbee-lib
Boost::boost
HUNSPELL::HUNSPELL
LUA51::LUA51
PCRE::PCRE
PUGIXML::PUGIXML
Qt5::Concurrent
Qt5::Core
Qt5::Network
Qt5::Multimedia
Qt5::OpenGL
Qt5::UiTools
Qt5::Widgets
YAJL::YAJL
ZIP::ZIP
ZLIB::ZLIB
qt5keychain)
endif()

if(Qt5TextToSpeech_FOUND)
target_link_libraries(mudlet Qt5::TextToSpeech)
Expand All @@ -407,6 +443,16 @@ if(USE_VARIABLE_SPLASH_SCREEN)
target_compile_definitions(mudlet PRIVATE INCLUDE_VARIABLE_SPLASH_SCREEN)
endif()

if(WIN32)
if(USE_MAIN_BUILD_SYSTEM)
# The UNICODE and _UNICODE definitions are needed to make
# (QString) mudlet::getShortPathName(const QString& name) work:
target_compile_definitions(mudlet PRIVATE INCLUDE_MAIN_BUILD_SYSTEM UNICODE _UNICODE)
else()
target_compile_definitions(mudlet PRIVATE UNICODE _UNICODE)
endif()
endif()

if(WIN32)
target_link_libraries(mudlet ws2_32)
set_target_properties(mudlet PROPERTIES WIN32_EXECUTABLE ON)
Expand Down
2 changes: 1 addition & 1 deletion src/ctelnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ cTelnet::cTelnet(Host* pH, const QString& profileName)
// than that in the initialisation list so that it is processed as a change
// to set up the initial encoder
encodingChanged("UTF-8");
termType = QStringLiteral("Mudlet %1").arg(QStringLiteral(APP_VERSION));
termType = QStringLiteral("Mudlet" APP_VERSION);
if (QByteArray(APP_BUILD).trimmed().length()) {
termType.append(QStringLiteral(APP_BUILD));
}
Expand Down

0 comments on commit 88ad45f

Please sign in to comment.