From f5e769ff450b592bc645473e11f9258aec241f0e Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Sat, 1 Jun 2019 09:48:02 +0000 Subject: [PATCH] cmake: fix build on MSYS2 Some minor changes to allow building easily on MSYS2: - don't check for snorenotify on MSYS2 because it segfaults on startup - don't use -fstack-protector-strong (libssp) on MinGW because it currently causes segfaults during static initialization https://sourceforge.net/p/mingw-w64/bugs/755/ - use the `cat` command to read files when using the 'MSYS Makefiles' generator, and not the cmd.exe `type` command - update doc for the quassel_add_module function wrt. 7d0879ab Tested to build correctly on MSYS2 with both the 'MSYS Makefiles' generator and the Ninja generator using a native ninja. Signed-off-by: Rafael Kitover --- CMakeLists.txt | 22 +++++++++++++--------- cmake/QuasselCompileSettings.cmake | 6 +++++- cmake/QuasselMacros.cmake | 8 ++++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b42534f3..78df95ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,19 +207,23 @@ if (BUILD_GUI) PURPOSE "Required for audio notifications" ) - find_package(LibsnoreQt5 0.7.0 QUIET) - set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL - URL "https://projects.kde.org/projects/playground/libs/snorenotify" - DESCRIPTION "a cross-platform notification framework" - PURPOSE "Enable support for the snorenotify framework" - ) - if (LibsnoreQt5_FOUND) - find_package(LibsnoreSettingsQt5 QUIET) - set_package_properties(LibsnoreSettingsQt5 PROPERTIES TYPE OPTIONAL + # snorenotify segfaults on startup on msys2 + # we don't check for just MSYS to support the Ninja generator + if(NOT (WIN32 AND (NOT $ENV{MSYSTEM} STREQUAL ""))) + find_package(LibsnoreQt5 0.7.0 QUIET) + set_package_properties(LibsnoreQt5 PROPERTIES TYPE OPTIONAL URL "https://projects.kde.org/projects/playground/libs/snorenotify" DESCRIPTION "a cross-platform notification framework" PURPOSE "Enable support for the snorenotify framework" ) + if (LibsnoreQt5_FOUND) + find_package(LibsnoreSettingsQt5 QUIET) + set_package_properties(LibsnoreSettingsQt5 PROPERTIES TYPE OPTIONAL + URL "https://projects.kde.org/projects/playground/libs/snorenotify" + DESCRIPTION "a cross-platform notification framework" + PURPOSE "Enable support for the snorenotify framework" + ) + endif() endif() if (WITH_WEBENGINE) diff --git a/cmake/QuasselCompileSettings.cmake b/cmake/QuasselCompileSettings.cmake index 9de75dca..eb38958a 100644 --- a/cmake/QuasselCompileSettings.cmake +++ b/cmake/QuasselCompileSettings.cmake @@ -34,7 +34,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") -fdiagnostics-color=always -fexceptions -fno-common - -fstack-protector-strong -Wall -Wextra -Wcast-align @@ -50,6 +49,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") "$<$>:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>" ) + # ssp is currently very broken on MinGW + if(NOT MINGW) + add_compile_options(-fstack-protector-strong) + endif() + # Check for and set linker flags check_and_set_linker_flag("-Wl,-z,relro" RELRO LINKER_FLAGS) check_and_set_linker_flag("-Wl,-z,now" NOW LINKER_FLAGS) diff --git a/cmake/QuasselMacros.cmake b/cmake/QuasselMacros.cmake index 6182f704..6ad562b7 100644 --- a/cmake/QuasselMacros.cmake +++ b/cmake/QuasselMacros.cmake @@ -20,9 +20,9 @@ include(QuasselCompileFeatures) # - a library target named quassel_client with output name (lib)quassel-client(.so) # - an alias target named Quassel::Client in global scope # -# If the optional argument STATIC is given, a static library is built; otherwise, on -# platforms other than Windows, a shared library is created. For shared libraries, also -# an install rule is added. +# If the optional argument STATIC is given, or the ENABLE_SHARED option is OFF, +# a static library is built; otherwise a shared library is created. For shared +# libraries, an install rule is also added. # # To generate an export header for the library, specify EXPORT. The header will be named # ${module}-export.h (where ${module} is the lower-case name of the module). @@ -143,7 +143,7 @@ function(quassel_add_resource _name) # # On Windows, input redirection apparently doesn't work, however piping does. Use this for all platforms for # consistency, accommodating for the fact that the 'cat' equivalent on Windows is 'type'. - if (WIN32) + if (WIN32 AND NOT MSYS) set(cat_cmd type) else() set(cat_cmd cat) -- 2.20.1