Commit 77a9d2a5 authored by Urs Fleisch's avatar Urs Fleisch
Browse files

Qt5: Automatically detect Qt5, use Qt5Core_EXECUTABLE_COMPILE_FLAGS.

parent 655b3b37
......@@ -109,15 +109,35 @@ set(CFG_DOCDIR ${CMAKE_INSTALL_PREFIX_SLASH}${WITH_DOCDIR})
set(CFG_TRANSLATIONSDIR ${CMAKE_INSTALL_PREFIX_SLASH}${WITH_TRANSLATIONSDIR})
cmake_minimum_required(VERSION 2.8)
set(QT_EXECUTABLE_COMPILE_FLAGS)
string(REGEX MATCH "^(.*[Qq]t5.*).bin.qmake.*" _qt5Dir "${QT_QMAKE_EXECUTABLE}")
if (_qt5Dir)
set(_qt5Dir ${CMAKE_MATCH_1})
endif (_qt5Dir)
if (NOT _qt5Dir)
set(_QT4_COMPONENTS QtCore QtGui QtNetwork QtXml)
if (WIN32)
set(QT_USE_QTMAIN TRUE)
endif (WIN32)
set(QT_USE_QTDBUS ${WITH_DBUS})
find_package(Qt4 COMPONENTS ${_QT4_COMPONENTS})
if (QT_QMAKE_EXECUTABLE)
include (${QT_USE_FILE})
message(STATUS "Qt4 found, explicitly set QT_QMAKE_EXECUTABLE to use a different version.")
else (QT_QMAKE_EXECUTABLE)
find_package(Qt5Core)
if (Qt5Core_QMAKE_EXECUTABLE)
set(_qt5Dir ${_qt5_corelib_install_prefix})
else (Qt5Core_QMAKE_EXECUTABLE)
message(FATAL_ERROR "Neither Qt4 nor Qt5 found.")
endif (Qt5Core_QMAKE_EXECUTABLE)
endif (QT_QMAKE_EXECUTABLE)
endif (NOT _qt5Dir)
if (_qt5Dir)
set(HAVE_QT5 1)
set(WITH_PHONON OFF)
if (NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif (NOT WIN32)
set(Qt5Core_DIR "${_qt5Dir}/lib/cmake/Qt5Core")
set(Qt5Gui_DIR "${_qt5Dir}/lib/cmake/Qt5Gui")
set(Qt5Widgets_DIR "${_qt5Dir}/lib/cmake/Qt5Widgets")
......@@ -135,6 +155,7 @@ if (_qt5Dir)
set(QT_DEFINITIONS ${QT_DEFINITIONS} ${Qt5${_qt5Component}_DEFINITIONS})
set(QT_LIBRARIES ${QT_LIBRARIES} ${Qt5${_qt5Component}_LIBRARIES})
endforeach ()
set(QT_EXECUTABLE_COMPILE_FLAGS ${Qt5Core_EXECUTABLE_COMPILE_FLAGS})
if (WITH_DBUS)
set(Qt5DBus_DIR "${_qt5Dir}/lib/cmake/Qt5DBus")
find_package("Qt5DBus")
......@@ -161,15 +182,10 @@ if (_qt5Dir)
macro(qt4_add_resources)
qt5_add_resources(${ARGV})
endmacro(qt4_add_resources)
else (_qt5Dir)
set(_QT4_COMPONENTS QtCore QtGui QtNetwork QtXml)
if (WIN32)
set(QT_USE_QTMAIN TRUE)
endif (WIN32)
set(QT_USE_QTDBUS ${WITH_DBUS})
find_package(Qt4 COMPONENTS ${_QT4_COMPONENTS} REQUIRED)
include (${QT_USE_FILE})
message(STATUS "Found Qt5: ${_qt5_corelib_install_prefix} (found version \"${Qt5Core_VERSION_STRING}\")")
endif (_qt5Dir)
include (CheckCXXSourceCompiles)
find_package(Perl REQUIRED)
......
......@@ -12,6 +12,9 @@ add_definitions(-DKID3_BUILD_CORE_LIB)
if (WIN32 AND HAVE_CHROMAPRINT)
add_definitions(-DCHROMAPRINT_NODLL)
endif (WIN32 AND HAVE_CHROMAPRINT)
if (NOT BUILD_SHARED_LIBS)
add_definitions(${QT_EXECUTABLE_COMPILE_FLAGS})
endif (NOT BUILD_SHARED_LIBS)
if (WITH_GCC_PCH)
ADD_KID3_PCH_RULE(core_SRCS)
......
......@@ -12,6 +12,9 @@ foreach (_subdir widgets dialogs forms)
endforeach()
add_definitions(-DKID3_BUILD_GUI_LIB)
if (NOT BUILD_SHARED_LIBS)
add_definitions(${QT_EXECUTABLE_COMPILE_FLAGS})
endif (NOT BUILD_SHARED_LIBS)
if (WITH_GCC_PCH)
ADD_KID3_PCH_RULE(gui_SRCS)
......
......@@ -73,7 +73,7 @@ else (WITH_KDE)
RENAME kid3-qt.png)
endif (UNIX AND NOT APPLE)
add_definitions(${QT_DEFINITIONS})
add_definitions(${QT_DEFINITIONS} ${QT_EXECUTABLE_COMPILE_FLAGS})
set(kid3_RESOURCES kid3.qrc)
qt4_add_resources(kid3_GEN_RCS ${kid3_RESOURCES})
add_executable(${KID3_EXECUTABLE} MACOSX_BUNDLE WIN32
......
......@@ -26,6 +26,6 @@ testdiscogsimportparser.h
)
qt4_wrap_cpp(test_GEN_MOC_SRCS ${test_MOC_HDRS})
add_definitions(${QT_DEFINITIONS})
add_definitions(${QT_DEFINITIONS} ${QT_EXECUTABLE_COMPILE_FLAGS})
add_executable(kid3-test ${test_SRCS} ${test_GEN_MOC_SRCS})
target_link_libraries(kid3-test kid3-core ${QT_QTTEST_LIBRARY})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment