Skip to content

Commit

Permalink
Clean up how we link to Qt
Browse files Browse the repository at this point in the history
  • Loading branch information
cbjeukendrup committed Oct 3, 2024
1 parent 2376dc6 commit 22a25d3
Show file tree
Hide file tree
Showing 72 changed files with 341 additions and 281 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ if (MUE_COMPILE_MACOS_PRECOMPILED_DEPS_PATH)
set(MUE_COMPILE_USE_SYSTEM_OPUS ON)
endif()

set(QT_MIN_VERSION "6.2.4")
if (MUSE_MODULE_NETWORK_WEBSOCKET)
set(QT_ADD_WEBSOCKET ON)
endif()
Expand Down
10 changes: 5 additions & 5 deletions buildscripts/cmake/DeclareModuleSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# set(MODULE_DEF ...) - set definitions
# set(MODULE_SRC ...) - set sources and headers files
# set(MODULE_LINK ...) - set libraries for link
# set(MODULE_LINK_PUBLIC ...) - set libraries for link and transitive link
# set(MODULE_NOT_LINK_GLOBAL ON) - set for not link global lib
# set(MODULE_QRC somename.qrc) - set resource (qrc) file
# set(MODULE_BIG_QRC somename.qrc) - set big resource (qrc) file
Expand All @@ -53,6 +54,7 @@ macro(declare_module name)
unset(MODULE_DEF)
unset(MODULE_SRC)
unset(MODULE_LINK)
unset(MODULE_LINK_PUBLIC)
unset(MODULE_NOT_LINK_GLOBAL)
unset(MODULE_QRC)
unset(MODULE_BIG_QRC)
Expand All @@ -78,7 +80,6 @@ endmacro()


macro(setup_module)

if (MODULE_IS_STUB)
message(STATUS "Configuring ${MODULE} <${MODULE_ALIAS}> [stub]")
else()
Expand Down Expand Up @@ -195,8 +196,7 @@ macro(setup_module)
endif()
endif()

set(MODULE_LINK ${CMAKE_DL_LIBS} ${QT_LIBRARIES} ${MODULE_LINK})

target_link_libraries(${MODULE} PRIVATE ${MODULE_LINK} )

target_link_libraries(${MODULE}
PRIVATE ${MODULE_LINK}
PUBLIC ${MODULE_LINK_PUBLIC})
endmacro()
56 changes: 56 additions & 0 deletions buildscripts/cmake/QtInstallPaths.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# SPDX-License-Identifier: GPL-3.0-only
# MuseScore-Studio-CLA-applies
#
# MuseScore Studio
# Music Composition & Notation
#
# Copyright (C) 2024 MuseScore Limited
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# Adapted from KDQtInstallPaths.cmake, from the KDAB CMake modules

if(TARGET Qt::qmake)
get_target_property(QT_QMAKE_EXECUTABLE Qt${Qt_VERSION_MAJOR}::qmake LOCATION)
else()
message(FATAL_ERROR "No supported Qt version found. Make sure you find Qt before calling this")
endif()

execute_process(
COMMAND ${QT_QMAKE_EXECUTABLE} -query
RESULT_VARIABLE return_code
OUTPUT_VARIABLE ALL_VARS
)
if(NOT return_code EQUAL 0)
message(WARNING "Failed call: ${QMAKE_EXECUTABLE} -query")
message(FATAL_ERROR "QMake call failed: ${return_code}")
endif()

string(REPLACE "\n" ";" VARS_LIST ${ALL_VARS})
foreach(QVAL ${VARS_LIST})
if(QVAL MATCHES "QT_INSTALL_")
string(REPLACE ":" ";" QVAL_LIST ${QVAL})
list(LENGTH QVAL_LIST listlen)
list(GET QVAL_LIST 0 var)
if(WIN32 AND ${listlen} GREATER 2)
list(GET QVAL_LIST 2 path)
list(GET QVAL_LIST 1 drive)
set(path "${drive}:${path}")
else()
list(GET QVAL_LIST 1 path)
endif()
if(NOT ${var}) #if set already on the command line for example
set(${var} ${path} CACHE PATH "Qt install path for ${var}")
endif()
endif()
endforeach()
116 changes: 50 additions & 66 deletions buildscripts/cmake/SetupQt6.cmake
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
# SPDX-License-Identifier: GPL-3.0-only
# MuseScore-Studio-CLA-applies
#
# MuseScore Studio
# Music Composition & Notation
#
# Copyright (C) 2024 MuseScore Limited
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

include(GetUtilsFunctions) # library of CMake functions ("fn__" namespace)

# Print Qt version or fail the build if Qt (qmake) is not in PATH.
fn__require_program(QMAKE Qt --version "https://musescore.org/en/handbook/developers-handbook/compilation" qmake6 qmake)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(_components
set(qt_components
Core
Gui
Widgets
Network
NetworkAuth
Qml
Quick
QuickControls2
QuickTemplates2
QuickWidgets
Xml
Svg
PrintSupport
OpenGL
LinguistTools

Core5Compat
Expand All @@ -32,64 +39,41 @@ set(_components
StateMachine
)

if (NOT OS_IS_WASM)
set(_components
${_components}
Concurrent
)
endif()
set(QT_LIBRARIES
Qt::Core
Qt::Gui
Qt::Widgets
Qt::Network
Qt::NetworkAuth
Qt::Qml
Qt::Quick
Qt::QuickWidgets
Qt::Xml
Qt::Svg
Qt::PrintSupport

if (OS_IS_LIN)
set(_components
${_components}
DBus
)
endif()
Qt::Core5Compat

if (QT_ADD_WEBSOCKET)
set(_components
${_components}
WebSockets
)
Qt::StateMachine
)

if(NOT OS_IS_WASM)
list(APPEND qt_components Concurrent)
list(APPEND QT_LIBRARIES Qt::Concurrent)
endif()

foreach(_component ${_components})
find_package(Qt6${_component} REQUIRED)
list(APPEND QT_LIBRARIES ${Qt6${_component}_LIBRARIES})
list(APPEND QT_INCLUDES ${Qt6${_component}_INCLUDE_DIRS})
add_definitions(${Qt6${_component}_DEFINITIONS})
endforeach()
if(OS_IS_LIN)
list(APPEND qt_components DBus)
list(APPEND QT_LIBRARIES Qt::DBus)
endif()

include_directories(${QT_INCLUDES})
if(QT_ADD_WEBSOCKET)
list(APPEND qt_components WebSockets)
list(APPEND QT_LIBRARIES Qt::WebSockets)
endif()

find_program(QT_QMAKE_EXECUTABLE qmake)
set(_qmake_vars
QT_INSTALL_ARCHDATA
QT_INSTALL_BINS
QT_INSTALL_CONFIGURATION
QT_INSTALL_DATA
QT_INSTALL_DOCS
QT_INSTALL_EXAMPLES
QT_INSTALL_HEADERS
QT_INSTALL_IMPORTS
QT_INSTALL_LIBEXECS
QT_INSTALL_LIBS
QT_INSTALL_PLUGINS
QT_INSTALL_PREFIX
QT_INSTALL_QML
QT_INSTALL_TESTS
QT_INSTALL_TRANSLATIONS
)
foreach(_var ${_qmake_vars})
execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} "-query" ${_var}
RESULT_VARIABLE _return_val
OUTPUT_VARIABLE _out
OUTPUT_STRIP_TRAILING_WHITESPACE
)
find_package(Qt6 6.3 REQUIRED COMPONENTS ${qt_components})

if(_return_val EQUAL 0)
set(${_var} "${_out}")
endif(_return_val EQUAL 0)
endforeach(_var)
include(QtInstallPaths)

#add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
qt_standard_project_setup()
7 changes: 1 addition & 6 deletions sandbox/cpad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-g")

set(QT_MIN_VERSION "6.2.4")
find_package(Qt6Core ${QT_MIN_VERSION} REQUIRED)

include_directories(
${Qt6Core_INCLUDE_DIRS}
)
find_package(Qt6Core 6.3 REQUIRED)

add_executable(app
main.cpp
Expand Down
19 changes: 3 additions & 16 deletions sandbox/engraving/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,9 @@ set(CMAKE_MODULE_PATH
include(SetupBuildEnvironment)
include(GetPlatformInfo)

set(QT_MIN_VERSION "6.2.4")
find_package(Qt6Core ${QT_MIN_VERSION} REQUIRED)
find_package(Qt6Gui ${QT_MIN_VERSION} REQUIRED)
# find_package(Qt6Svg ${QT_MIN_VERSION} REQUIRED)
# find_package(Qt6Widgets ${QT_MIN_VERSION} REQUIRED)
set(QT_LIBRARIES
Qt6::Core
Qt6::Gui
# Qt6::Svg
# Qt6::Widgets
)
find_package(Qt6 6.3 REQUIRED COMPONENTS Core Gui)

include_directories(
${Qt6Core_INCLUDE_DIRS}
${Qt6Gui_INCLUDE_DIRS}
# ${Qt6Svg_INCLUDE_DIRS}
# ${Qt6Widgets_INCLUDE_DIRS}
${CMAKE_CURRENT_LIST_DIR}
${MU_ROOT}/thirdparty/dtl
)
Expand Down Expand Up @@ -80,7 +66,8 @@ target_include_directories(engraving_app PUBLIC
)

target_link_libraries(engraving_app
${QT_LIBRARIES}
global
engraving
Qt6::Core
Qt6::Gui
)
56 changes: 0 additions & 56 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,62 +343,6 @@ if (OS_IS_WIN)

endif(CC_IS_MINGW)

# Install Qt
foreach (QtLibrary ${QT_LIBRARIES})
#message(STATUS "Library ${QtLibrary}")
# always use release libs
set_target_properties(${QtLibrary} PROPERTIES MAP_IMPORTED_CONFIG_DEBUG "RELEASE")
get_target_property(QtSharedLibrary ${QtLibrary} LOCATION_RELEASE)
if (EXISTS ${QtSharedLibrary})
list (APPEND QtInstallLibraries ${QtSharedLibrary})
endif (EXISTS ${QtSharedLibrary})
endforeach (QtLibrary ${QT_LIBRARIES})
list(REMOVE_DUPLICATES QtInstallLibraries)

install(FILES
${QtInstallLibraries}
${QT_INSTALL_BINS}/opengl32sw.dll
${QT_INSTALL_BINS}/d3dcompiler_47.dll
${QT_INSTALL_BINS}/Qt6QmlModels.dll
${QT_INSTALL_BINS}/Qt6QmlWorkerScript.dll
${QT_INSTALL_BINS}/Qt6QuickControls2Impl.dll
${QT_INSTALL_BINS}/Qt6QuickDialogs2.dll
${QT_INSTALL_BINS}/Qt6QuickDialogs2QuickImpl.dll
${QT_INSTALL_BINS}/Qt6QuickDialogs2Utils.dll
${QT_INSTALL_BINS}/Qt6QuickLayouts.dll
DESTINATION bin)

install(FILES
${QT_INSTALL_PLUGINS}/iconengines/qsvgicon.dll
DESTINATION bin/iconengines)

install(FILES
${QT_INSTALL_PLUGINS}/imageformats/qjpeg.dll
${QT_INSTALL_PLUGINS}/imageformats/qsvg.dll
DESTINATION bin/imageformats)

install(FILES
${QT_INSTALL_PLUGINS}/platforms/qwindows.dll
${QT_INSTALL_PLUGINS}/platforms/qoffscreen.dll
DESTINATION bin/platforms)

install(FILES
${QT_INSTALL_PLUGINS}/tls/qcertonlybackend.dll
${QT_INSTALL_PLUGINS}/tls/qopensslbackend.dll
${QT_INSTALL_PLUGINS}/tls/qschannelbackend.dll
DESTINATION bin/tls)

install(DIRECTORY
${QT_INSTALL_QML}
DESTINATION .
REGEX ".*d\\.dll" EXCLUDE
REGEX ".pdb" EXCLUDE
REGEX ".*QtMultimedia.*" EXCLUDE
REGEX ".*QtSensors.*" EXCLUDE
REGEX ".*QtTest.*" EXCLUDE
REGEX ".*QtWebkit.*" EXCLUDE
)

if (SNDFILE_DLL)
install(FILES ${SNDFILE_DLL} DESTINATION bin)
endif()
Expand Down
8 changes: 4 additions & 4 deletions src/app/internal/guiapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ void GuiApp::perform()
{
GraphicsApiProvider* gApiProvider = new GraphicsApiProvider(BaseApplication::appVersion());

GraphicsApiProvider::Api required = gApiProvider->requiredGraphicsApi();
if (required != GraphicsApiProvider::Default) {
GraphicsApi required = gApiProvider->requiredGraphicsApi();
if (required != GraphicsApi::Default) {
LOGI() << "Setting required graphics api: " << GraphicsApiProvider::apiName(required);
GraphicsApiProvider::setGraphicsApi(required);
}

LOGI() << "Using graphics api: " << GraphicsApiProvider::graphicsApiName();

if (GraphicsApiProvider::graphicsApi() == GraphicsApiProvider::Software) {
if (GraphicsApiProvider::graphicsApi() == GraphicsApi::Software) {
gApiProvider->destroy();
} else {
LOGI() << "Detecting problems with graphics api";
Expand All @@ -161,7 +161,7 @@ void GuiApp::perform()
LOGI() << "No problems detected with graphics api";
gApiProvider->setGraphicsApiStatus(required, GraphicsApiProvider::Status::Checked);
} else {
GraphicsApiProvider::Api next = gApiProvider->switchToNextGraphicsApi(required);
GraphicsApi next = gApiProvider->switchToNextGraphicsApi(required);
LOGE() << "Detected problems with graphics api; switching from " << GraphicsApiProvider::apiName(required)
<< " to " << GraphicsApiProvider::apiName(next);

Expand Down
4 changes: 4 additions & 0 deletions src/appshell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,8 @@ if (NOT OS_IS_MAC)
set(MODULE_INCLUDE_PRIVATE ${Qt6Gui_PRIVATE_INCLUDE_DIRS} )
endif(NOT OS_IS_MAC)

if (QT_SUPPORT)
list(APPEND MODULE_LINK Qt::Core5Compat Qt::Quick Qt::Svg Qt::Widgets)
endif()

setup_module()
Loading

0 comments on commit 22a25d3

Please sign in to comment.