$OpenBSD: patch-CMakeLists_txt,v 1.3 2018/04/14 10:00:05 rsadowski Exp $
Index: CMakeLists.txt
--- CMakeLists.txt.orig
+++ CMakeLists.txt
@@ -61,7 +61,9 @@ trojita_option(WITH_ZLIB "Build with zlib library" AUT
 trojita_option(WITH_SHARED_PLUGINS "Enable shared dynamic plugins" ON)
 trojita_option(WITH_TESTS "Build tests" ON)
 trojita_option(WITH_MIMETIC "Build with client-side MIME parsing" AUTO)
-trojita_option(WITH_GPGMEPP "Build with the GpgME++ library for cryptography" AUTO)
+trojita_option(WITH_GPGMEPP "Use GpgME's native C++ bindings" ON)
+trojita_option(WITH_KF5_GPGMEPP "Use legacy discontinued GpgME++ library from KDE frameworks" OFF)
+ 
 
 if(WIN32)
     trojita_option(WITH_NSIS "Build Windows NSIS installer" AUTO "WITH_DESKTOP")
@@ -94,8 +96,13 @@ trojita_plugin_option(WITH_QTKEYCHAIN_PLUGIN "Build Qt
 trojita_find_package(Git "" "" "" "")
 
 trojita_find_package(Mimetic "" "http://www.codesink.org/mimetic_mime_library.html" "C++ MIME Library" "Required for client-side MIME parsing" WITH_MIMETIC)
-trojita_find_package(KF5Gpgmepp "" "https://quickgit.kde.org/?p=gpgmepp.git" "C++ bindings for gpgme" "Needed for encrypted/signed e-mails" WITH_GPGMEPP)
-trojita_option(WITH_CRYPTO_MESSAGES "Enable support for encrypted messages" AUTO "WITH_MIMETIC;WITH_GPGMEPP")
+trojita_find_package(Gpgmepp "1.8.0" "https://gnupg.org/related_software/gpgme/index.html" "C++/Qt bindings for gpgme" "Needed for encrypted/signed e-mails" WITH_GPGMEPP)
+if(NOT WITH_GPGMEPP)
+    trojita_find_package(KF5Gpgmepp "" "https://commits.kde.org/gpgmepp?path=/" "C++ bindings for gpgme" "Needed for encrypted/signed e-mails" WITH_KF5_GPGMEPP)
+    trojita_option(WITH_CRYPTO_MESSAGES "Enable support for encrypted messages" AUTO "WITH_MIMETIC;WITH_KF5_GPGMEPP")
+else()
+    trojita_option(WITH_CRYPTO_MESSAGES "Enable support for encrypted messages" AUTO "WITH_MIMETIC;WITH_GPGMEPP")
+endif()
 
 if(WIN32)
     trojita_find_package(MakeNSIS "" "http://nsis.sourceforge.net" "Nullsoft Scriptable Install System" "Needed for building Windows installer" WITH_NSIS)
@@ -154,14 +161,6 @@ else()
     set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
     # Also see CMP0043...
 
-    # Optimizations are enabled unconditionally because they make a big difference in the speed of the
-    # resulting binaries, and that it is better to allow an opt-out from them by adjusting CXXFLAGS through
-    # an env var at cmake time if needed.
-    # The reason for not manipulating just CMAKE_CXX_FLAGS_DEBUG is that unrecognized build types ("DebugFull")
-    # should still benefit from these optimizations. Yup, it would be even better if CMake did a sane thing
-    # and warned when users set an unrecognized and unused build type, but that just isn't the case.
-    set(CMAKE_CXX_FLAGS "-O2 ${CMAKE_CXX_FLAGS}")
-
     # Build warnings are useful tools (and Trojita should be warning-free anyway), enable them on all
     # configurations. They are warnings, not errors.
     set(CMAKE_CXX_FLAGS "-Wall -Wsign-compare ${CMAKE_CXX_FLAGS}")
@@ -207,7 +206,7 @@ else()
   set(TROJITA_HAVE_MIMETIC False)
 endif()
 
-if(WITH_GPGMEPP)
+if(WITH_GPGMEPP OR WITH_KF5_GPGMEPP)
   set(TROJITA_HAVE_GPGMEPP True)
 else()
   set(TROJITA_HAVE_GPGMEPP False)
@@ -321,12 +320,10 @@ if(WITH_MIMETIC)
     )
 endif()
 if(WITH_CRYPTO_MESSAGES)
-  if(WITH_GPGMEPP)
     set(libCryptography_SOURCES
         ${libCryptography_SOURCES}
         ${path_Cryptography}/GpgMe++.cpp
     )
-  endif()
 endif()
 
 if(WITH_ZLIB)
@@ -622,16 +619,20 @@ set_property(TARGET Cryptography APPEND PROPERTY COMPI
 target_link_libraries(Cryptography Common Imap)
 if(WITH_MIMETIC)
     target_link_libraries(Cryptography ${MIMETIC_LIBRARIES})
-    set_property(TARGET Cryptography APPEND PROPERTY INCLUDE_DIRECTORIES ${MIMETIC_INCLUDE_DIRS})
+    set_property(TARGET Cryptography APPEND PROPERTY INCLUDE_DIRECTORIES /usr/local/include)
 endif()
 if(WITH_CRYPTO_MESSAGES)
-  if(WITH_GPGMEPP)
-    if (WIN32)
-      target_link_libraries(Cryptography KF5::Gpgmepp KF5::QGpgme)
-    else()
-      target_link_libraries(Cryptography KF5::Gpgmepp-pthread KF5::QGpgme)
+    if(WITH_GPGMEPP)
+	target_link_libraries(Cryptography gpgmepp qgpgme gpgme)
+	set_property(TARGET Cryptography APPEND PROPERTY INCLUDE_DIRECTORIES /usr/local/include/gpgme++)
+	set_property(TARGET Cryptography APPEND PROPERTY INCLUDE_DIRECTORIES /usr/local/include/qgpgme)
+    elseif(WITH_KF5_GPGMEPP)
+        if(WIN32)
+            target_link_libraries(Cryptography KF5::Gpgmepp KF5::QGpgme)
+        else()
+            target_link_libraries(Cryptography KF5::Gpgmepp-pthread KF5::QGpgme)
+        endif()
     endif()
-  endif()
 endif()
 
 ## ClearText password plugin
@@ -786,32 +787,6 @@ if(WITH_TESTS)
     trojita_test(Imap Imap_Offline)
     trojita_test(Imap Imap_CopyAndFlagOperations)
     trojita_test(Cryptography Cryptography_MessageModel)
-
-    if(WITH_CRYPTO_MESSAGES)
-      find_program(GPGCONF_BINARY NAMES gpgconf)
-      if(GPGCONF_BINARY_NOTFOUND)
-        message(SEND_ERROR "The `gpgconf` binary from GnuPG not found, this is needed for crypto tests.")
-      endif()
-
-      if(NOT UNIX)
-        message(SEND_ERROR "The Cryptography unit tests really need Unix. Patches welcome.")
-      endif()
-
-      add_library(fake-dev-random SHARED ${CMAKE_CURRENT_SOURCE_DIR}/tests/Utils/fake-dev-random.c)
-      target_link_libraries(fake-dev-random dl)
-
-      # FIXME: it would be nice to depend on the contents of keys/, but in my testing it produces Makefiles
-      # which suffer from races (the keygen.sh is run multiple times in parallel within the CI environment).
-      # I wasn't able to track down the root cause behind this; it affected all cmake versions within the CI
-      # as of Feb 2016, which is 3.1.something up to 3.3.something.
-      add_custom_command(OUTPUT crypto_test_data.h
-        COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/tests/Cryptography/keygen.sh ${CMAKE_CURRENT_SOURCE_DIR}
-        DEPENDS fake-dev-random tests/Cryptography/keygen.sh tests/Cryptography/batch-keygen)
-      add_custom_target(crypto_test_data DEPENDS crypto_test_data.h)
-
-      trojita_test(Cryptography Cryptography_PGP)
-      add_dependencies(test_Cryptography_PGP crypto_test_data)
-    endif()
 
     trojita_test(Misc Rfc5322)
     trojita_test(Misc RingBuffer)
