Index: Portfile
===================================================================
--- Portfile	(revision 133144)
+++ Portfile	(working copy)
@@ -118,12 +118,36 @@
     }
 }
 
-variant gui description {Qt4 based cmake-gui} {
-    PortGroup qt4 1.0
-    patchfiles-append patch-CMakeLists.txt.diff
-    configure.args-append --qt-gui --qt-qmake=${qt_qmake_cmd}
+variant gui description {Build Qt-based cmake-gui} {
+    configure.args-append --qt-gui
 }
 
+if {[variant_isset gui]} {
+
+    variant qt4 conflicts qt5 description {Build Qt GUI using Qt4} {
+        PortGroup qt4 1.0
+        patchfiles-append patch-qt4gui.diff
+        configure.args-append --qt-qmake=${qt_qmake_cmd}
+    }
+
+    variant qt5 conflicts qt4 description {Build Qt GUI using Qt5} {
+        PortGroup qt5 1.0
+        patchfiles-append patch-qt5gui.diff
+        configure.args-append --qt-qmake=${qt_qmake_cmd}
+    }
+
+    if {![variant_isset qt4] && ![variant_isset qt5]} {
+        default_variants +qt4
+    }
+
+    if {![variant_isset qt4] && ![variant_isset qt5]} {
+        ui_error "\n\nYou must select either the +qt4 or +qt5 variant when building the GUI.\n"
+        return -code error "Invalid variant selection"
+    }
+} else {
+    configure.args-append --no-qt-gui
+}
+
 variant docs description {Build documentation: HTML and manpages} {
     configure.args-append \
         --mandir=share/man \
Index: files/patch-CMakeLists.txt.diff
===================================================================
--- files/patch-CMakeLists.txt.diff	(revision 133144)
+++ files/patch-CMakeLists.txt.diff	(working copy)
@@ -1,56 +0,0 @@
---- CMakeLists.txt.orig
-+++ CMakeLists.txt
-@@ -476,7 +476,7 @@ if(BUILD_CursesDialog)
- endif()
- 
- if(BUILD_QtDialog)
--  if(APPLE)
-+  if(FALSE)
-     set(CMAKE_BUNDLE_VERSION
-       "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
-     set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
---- Source/QtDialog/CMakeLists.txt
-+++ Source/QtDialog/CMakeLists.txt
-@@ -99,7 +99,7 @@ set(SRCS ${SRCS} ${UI_SRCS} ${MOC_SRCS} ${RC_SRCS})
- if(WIN32)
-   set(SRCS ${SRCS} CMakeSetup.rc)
- endif()
--if(APPLE)
-+if(FALSE)
-   set(SRCS ${SRCS} CMakeSetup.icns)
-   set(MACOSX_BUNDLE_ICON_FILE CMakeSetup.icns)
-   set_source_files_properties(CMakeSetup.icns PROPERTIES
-@@ -115,13 +115,13 @@ endif()
- 
- set(CMAKE_INCLUDE_CURRENT_DIR ON)
- 
--add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS})
-+add_executable(cmake-gui WIN32 ${SRCS})
- target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${CMake_QT_LIBRARIES})
- if(Qt_BIN_DIR)
-   set_property(TARGET cmake-gui PROPERTY Qt_BIN_DIR ${Qt_BIN_DIR})
- endif()
- 
--if(APPLE)
-+if(FALSE)
-   file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
-     LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
- 
-@@ -153,7 +153,7 @@ if(UNIX)
-   install(FILES cmakecache.xml DESTINATION share/mime/packages )
- endif()
- 
--if(APPLE)
-+if(FALSE)
-   set(CMAKE_POSTFLIGHT_SCRIPT
-     "${CMake_BINARY_DIR}/Source/QtDialog/postflight.sh")
-   set(CMAKE_POSTUPGRADE_SCRIPT
-@@ -166,7 +166,7 @@ if(APPLE)
-                 WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)")
- endif()
- 
--if(APPLE OR WIN32)
-+if(WIN32)
-   # install rules for including 3rd party libs such as Qt
-   # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
-   set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
Index: files/patch-qt4gui.diff
===================================================================
--- files/patch-qt4gui.diff	(revision 0)
+++ files/patch-qt4gui.diff	(working copy)
@@ -0,0 +1,132 @@
+--- Source/QtDialog/CMakeLists.txt.orig
++++ Source/QtDialog/CMakeLists.txt
+@@ -14,58 +14,6 @@ project(QtDialog)
+ if(POLICY CMP0020)
+   cmake_policy(SET CMP0020 NEW) # Drop when CMake >= 2.8.11 required
+ endif()
+-find_package(Qt5Widgets QUIET)
+-if (Qt5Widgets_FOUND)
+-  include_directories(${Qt5Widgets_INCLUDE_DIRS})
+-  add_definitions(${Qt5Widgets_DEFINITONS})
+-  macro(qt4_wrap_ui)
+-    qt5_wrap_ui(${ARGN})
+-  endmacro()
+-  macro(qt4_wrap_cpp)
+-    qt5_wrap_cpp(${ARGN})
+-  endmacro()
+-  macro(qt4_add_resources)
+-    qt5_add_resources(${ARGN})
+-  endmacro()
+-  set(CMake_QT_LIBRARIES ${Qt5Widgets_LIBRARIES})
+-  set(QT_QTMAIN_LIBRARY ${Qt5Core_QTMAIN_LIBRARIES})
+-
+-  # Remove this when the minimum version of Qt is 4.6.
+-  add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
+-
+-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
+-
+-  # We need to install Cocoa platform plugin and add qt.conf for Qt5 on Mac.
+-  # FIXME: This should be part of Qt5 CMake scripts, but unfortunatelly
+-  # Qt5 Mac support is missing there.
+-  if(APPLE)
+-    macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
+-      get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
+-      if(EXISTS "${_qt_plugin_path}")
+-        get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
+-        get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
+-        get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
+-        set(_qt_plugin_dest "${CMAKE_INSTALL_PREFIX}/PlugIns/${_qt_plugin_type}")
+-        install(FILES "${_qt_plugin_path}"
+-          DESTINATION "${_qt_plugin_dest}")
+-        set(${_qt_plugins_var}
+-          "${${_qt_plugins_var}};${_qt_plugin_dest}/${_qt_plugin_file}")
+-      else()
+-        message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found")
+-      endif()
+-    endmacro()
+-    install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)
+-    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
+-      "[Paths]\nPlugins = PlugIns\n")
+-    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
+-      DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources")
+-  endif()
+-
+-  if(WIN32 AND TARGET Qt5::Core)
+-    get_property(_Qt5_Core_LOCATION TARGET Qt5::Core PROPERTY LOCATION)
+-    get_filename_component(Qt_BIN_DIR "${_Qt5_Core_LOCATION}" PATH)
+-  endif()
+-else()
+   set(QT_MIN_VERSION "4.4.0")
+   find_package(Qt4 REQUIRED)
+   if(NOT QT4_FOUND)
+@@ -83,7 +31,6 @@ else()
+       set(Qt_BIN_DIR ${_Qt_BIN_DIR})
+     endif()
+   endif()
+-endif()
+ 
+ set(SRCS
+   AddCacheEntry.cxx
+@@ -125,7 +72,7 @@ set(SRCS ${SRCS} ${UI_SRCS} ${MOC_SRCS} ${RC_SRCS})
+ if(WIN32)
+   set(SRCS ${SRCS} CMakeSetup.rc)
+ endif()
+-if(APPLE)
++if(APPLEBUNDLE)
+   set(SRCS ${SRCS} CMakeSetup.icns)
+   set(MACOSX_BUNDLE_ICON_FILE CMakeSetup.icns)
+   set_source_files_properties(CMakeSetup.icns PROPERTIES
+@@ -141,13 +88,13 @@ endif()
+ 
+ set(CMAKE_INCLUDE_CURRENT_DIR ON)
+ 
+-add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS})
++add_executable(cmake-gui WIN32 ${SRCS})
+ target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${CMake_QT_LIBRARIES})
+ if(Qt_BIN_DIR)
+   set_property(TARGET cmake-gui PROPERTY Qt_BIN_DIR ${Qt_BIN_DIR})
+ endif()
+ 
+-if(APPLE)
++if(APPLEBUNDLE)
+   file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
+     LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
+ 
+@@ -179,16 +126,16 @@ if(UNIX)
+   install(FILES cmakecache.xml DESTINATION share/mime/packages )
+ endif()
+ 
+-if(APPLE)
++if(APPLEBUNDLE)
+   install(CODE "execute_process(COMMAND ln -s \"../MacOS/CMake\" cmake-gui
+                 WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)")
+ endif()
+ 
+-if(APPLE OR WIN32)
++if(APPLEBUNDLE OR WIN32)
+   # install rules for including 3rd party libs such as Qt
+   # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
+   set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
+-  if(APPLE)
++  if(APPLEBUNDLE)
+     set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/CMake")
+   endif()
+   install(CODE "
+--- CMakeLists.txt.orig
++++ CMakeLists.txt
+@@ -505,15 +505,6 @@
+       set(CMAKE_BUNDLE_VERSION
+         "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
+       set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
+-      # make sure CMAKE_INSTALL_PREFIX ends in /
+-      string(LENGTH "${CMAKE_INSTALL_PREFIX}" LEN)
+-      math(EXPR LEN "${LEN} -1" )
+-      string(SUBSTRING "${CMAKE_INSTALL_PREFIX}" ${LEN} 1 ENDCH)
+-      if(NOT "${ENDCH}" STREQUAL "/")
+-        set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
+-      endif()
+-      set(CMAKE_INSTALL_PREFIX
+-        "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
+     endif()
+ 
+     set(QT_NEED_RPATH FALSE)
Index: files/patch-qt5gui.diff
===================================================================
--- files/patch-qt5gui.diff	(revision 0)
+++ files/patch-qt5gui.diff	(working copy)
@@ -0,0 +1,103 @@
+--- Source/QtDialog/CMakeLists.txt.orig
++++ Source/QtDialog/CMakeLists.txt
+@@ -15,7 +15,10 @@ if(POLICY CMP0020)
+   cmake_policy(SET CMP0020 NEW) # Drop when CMake >= 2.8.11 required
+ endif()
+ find_package(Qt5Widgets QUIET)
+-if (Qt5Widgets_FOUND)
++if (NOT Qt5Widgets_FOUND)
++  message(FATAL_ERROR "Qt5 required but not found")
++endif()
++
+   include_directories(${Qt5Widgets_INCLUDE_DIRS})
+   add_definitions(${Qt5Widgets_DEFINITONS})
+   macro(qt4_wrap_ui)
+@@ -65,25 +68,6 @@ if (Qt5Widgets_FOUND)
+     get_property(_Qt5_Core_LOCATION TARGET Qt5::Core PROPERTY LOCATION)
+     get_filename_component(Qt_BIN_DIR "${_Qt5_Core_LOCATION}" PATH)
+   endif()
+-else()
+-  set(QT_MIN_VERSION "4.4.0")
+-  find_package(Qt4 REQUIRED)
+-  if(NOT QT4_FOUND)
+-    message(SEND_ERROR "Failed to find Qt 4.4 or greater.")
+-    return()
+-  endif()
+-
+-  include(${QT_USE_FILE})
+-
+-  set(CMake_QT_LIBRARIES ${QT_LIBRARIES})
+-
+-  if(WIN32 AND EXISTS "${QT_QMAKE_EXECUTABLE}")
+-    get_filename_component(_Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH)
+-    if(EXISTS "${_Qt_BIN_DIR}/QtCore4.dll")
+-      set(Qt_BIN_DIR ${_Qt_BIN_DIR})
+-    endif()
+-  endif()
+-endif()
+ 
+ set(SRCS
+   AddCacheEntry.cxx
+@@ -125,7 +72,7 @@
+ if(WIN32)
+   set(SRCS ${SRCS} CMakeSetup.rc)
+ endif()
+-if(APPLE)
++if(APPLEBUNDLE)
+   set(SRCS ${SRCS} CMakeSetup.icns)
+   set(MACOSX_BUNDLE_ICON_FILE CMakeSetup.icns)
+   set_source_files_properties(CMakeSetup.icns PROPERTIES
+@@ -141,13 +88,13 @@ endif()
+ 
+ set(CMAKE_INCLUDE_CURRENT_DIR ON)
+ 
+-add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS})
++add_executable(cmake-gui WIN32 ${SRCS})
+ target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${CMake_QT_LIBRARIES})
+ if(Qt_BIN_DIR)
+   set_property(TARGET cmake-gui PROPERTY Qt_BIN_DIR ${Qt_BIN_DIR})
+ endif()
+ 
+-if(APPLE)
++if(APPLEBUNDLE)
+   file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
+     LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
+ 
+@@ -179,16 +126,16 @@
+   install(FILES cmakecache.xml DESTINATION share/mime/packages )
+ endif()
+ 
+-if(APPLE)
++if(APPLEBUNDLE)
+   install(CODE "execute_process(COMMAND ln -s \"../MacOS/CMake\" cmake-gui
+                 WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)")
+ endif()
+ 
+-if(APPLE OR WIN32)
++if(APPLEBUNDLE OR WIN32)
+   # install rules for including 3rd party libs such as Qt
+   # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
+   set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
+-  if(APPLE)
++  if(APPLEBUNDLE)
+     set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/CMake")
+   endif()
+   install(CODE "
+--- CMakeLists.txt.orig
++++ CMakeLists.txt
+@@ -505,15 +505,6 @@
+       set(CMAKE_BUNDLE_VERSION
+         "${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}.${CMake_VERSION_PATCH}")
+       set(CMAKE_BUNDLE_LOCATION "${CMAKE_INSTALL_PREFIX}")
+-      # make sure CMAKE_INSTALL_PREFIX ends in /
+-      string(LENGTH "${CMAKE_INSTALL_PREFIX}" LEN)
+-      math(EXPR LEN "${LEN} -1" )
+-      string(SUBSTRING "${CMAKE_INSTALL_PREFIX}" ${LEN} 1 ENDCH)
+-      if(NOT "${ENDCH}" STREQUAL "/")
+-        set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
+-      endif()
+-      set(CMAKE_INSTALL_PREFIX
+-        "${CMAKE_INSTALL_PREFIX}CMake.app/Contents")
+     endif()
+ 
+     set(QT_NEED_RPATH FALSE)
