cmake-gui: Fix build rules for Qt5 on Windows

Set policy CMP0020 to NEW to get WinMain from Qt.  Fix the documentation
custom command PATH for cmake-gui to find the Qt5 DLLs.
This commit is contained in:
Brad King 2013-08-07 09:59:33 -04:00
parent 7c9f0c664f
commit 8120e13f40
2 changed files with 23 additions and 5 deletions

View File

@ -11,6 +11,9 @@
#============================================================================= #=============================================================================
project(QtDialog) project(QtDialog)
if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW) # Drop when CMake >= 2.8.11 required
endif()
find_package(Qt5Widgets QUIET) find_package(Qt5Widgets QUIET)
if (Qt5Widgets_FOUND) if (Qt5Widgets_FOUND)
include_directories(${Qt5Widgets_INCLUDE_DIRS}) include_directories(${Qt5Widgets_INCLUDE_DIRS})
@ -29,6 +32,11 @@ if (Qt5Widgets_FOUND)
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
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() else()
set(QT_MIN_VERSION "4.4.0") set(QT_MIN_VERSION "4.4.0")
find_package(Qt4 REQUIRED) find_package(Qt4 REQUIRED)
@ -38,6 +46,13 @@ else()
endif() endif()
include(${QT_USE_FILE}) include(${QT_USE_FILE})
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() endif()
set(SRCS set(SRCS
@ -91,6 +106,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS}) add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS})
target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES}) target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})
if(Qt_BIN_DIR)
set_property(TARGET cmake-gui PROPERTY Qt_BIN_DIR ${Qt_BIN_DIR})
endif()
if(APPLE) if(APPLE)
set_target_properties(cmake-gui PROPERTIES set_target_properties(cmake-gui PROPERTIES

View File

@ -72,11 +72,11 @@ macro(ADD_DOCS target dependency)
endmacro() endmacro()
# Help cmake-gui find the Qt DLLs on Windows. # Help cmake-gui find the Qt DLLs on Windows.
set(WIN_SHELL_GENS "Visual Studio|NMake|MinGW|Watcom|Borland") if(TARGET cmake-gui)
if(BUILD_QtDialog AND "${CMAKE_GENERATOR}" MATCHES "${WIN_SHELL_GENS}" get_property(Qt_BIN_DIR TARGET cmake-gui PROPERTY Qt_BIN_DIR)
AND EXISTS "${QT_QMAKE_EXECUTABLE}" AND NOT CMAKE_NO_AUTO_QT_ENV) set(WIN_SHELL_GENS "Visual Studio|NMake|MinGW|Watcom|Borland")
get_filename_component(Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH) if(Qt_BIN_DIR AND "${CMAKE_GENERATOR}" MATCHES "${WIN_SHELL_GENS}"
if(EXISTS "${Qt_BIN_DIR}/QtCore4.dll") AND NOT CMAKE_NO_AUTO_QT_ENV)
# Tell the macro to set the path before running cmake-gui. # Tell the macro to set the path before running cmake-gui.
string(REPLACE ";" "\\;" _PATH "PATH=${Qt_BIN_DIR};%PATH%") string(REPLACE ";" "\\;" _PATH "PATH=${Qt_BIN_DIR};%PATH%")
set(cmake-gui-PATH COMMAND set "${_PATH}") set(cmake-gui-PATH COMMAND set "${_PATH}")