Simplify cross-compilation of qtwaylandscanner_kde
I am trying to cross-compile and since qtwaylandscanner_kde is used during the build, I need to build a native version of the qtwaylandscanner_kde tool first. This change allows building qtwaylandscanner_kde as a standalone CMake project which the cross-build can then be pointed at to find the host tool. If an explicit path to qwaylandscanner_kde is not passed, we will try to use ExternalProject_Add to build it. This approach was taken from ksyntaxhighlighting: https://invent.kde.org/frameworks/syntax-highlighting/-/blob/master/src/indexer/CMakeLists.txt This patch makes it significantly easier to cross-compile KWin, as we now only need a native QtCore library instead of all the dependencies.
This commit is contained in:
parent
a7d61f7bfa
commit
a264938ff3
1 changed files with 48 additions and 3 deletions
|
@ -1,6 +1,51 @@
|
|||
remove_definitions(-DQT_NO_CAST_FROM_ASCII)
|
||||
add_executable(qtwaylandscanner_kde qtwaylandscanner.cpp)
|
||||
target_link_libraries(qtwaylandscanner_kde Qt::Core)
|
||||
# Allow building just qtwaylandscanner_kde when cross-compiling since the
|
||||
# dependencies for the rest of the targets might not be installed on the host.
|
||||
if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(qtwaylandscanner_kde CXX)
|
||||
find_package(Qt5 5.15.0 CONFIG REQUIRED Core)
|
||||
find_package(ECM ${KF5_MIN_VERSION} NO_MODULE REQUIRED)
|
||||
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
|
||||
endif()
|
||||
|
||||
# when cross compiling, use either the executable offered or try to cross-compile it in place.
|
||||
if(CMAKE_CROSSCOMPILING AND QTWAYLANDSCANNER_KDE_EXECUTABLE)
|
||||
add_executable(qtwaylandscanner_kde IMPORTED GLOBAL)
|
||||
set_target_properties(qtwaylandscanner_kde PROPERTIES IMPORTED_LOCATION ${QTWAYLANDSCANNER_KDE_EXECUTABLE})
|
||||
elseif(CMAKE_CROSSCOMPILING)
|
||||
if (NOT KF5_HOST_TOOLING)
|
||||
message(FATAL_ERROR "Please provide a prefix with a native Qt build and pass -DKF5_HOST_TOOLING=path")
|
||||
endif()
|
||||
|
||||
# search native tooling prefix
|
||||
set(NATIVE_PREFIX "" CACHE STRING "CMAKE_PREFIX_PATH for native Qt libraries")
|
||||
if (NOT NATIVE_PREFIX)
|
||||
string(FIND ${KF5_HOST_TOOLING} /lib idx)
|
||||
string(SUBSTRING ${KF5_HOST_TOOLING} 0 ${idx} NATIVE_PREFIX)
|
||||
endif()
|
||||
message(STATUS "Building qtwaylandscanner_kde against ${NATIVE_PREFIX}")
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(native_qtwaylandscanner_kde
|
||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
CMAKE_ARGS -DECM_DIR=${ECM_DIR} -DCMAKE_PREFIX_PATH=${NATIVE_PREFIX}
|
||||
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}
|
||||
-DQT_MAJOR_VERSION=${QT_MAJOR_VERSION}
|
||||
INSTALL_COMMAND ""
|
||||
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/native_qtwaylandscanner_kde-prefix/src/native_qtwaylandscanner_kde-build/qtwaylandscanner_kde
|
||||
)
|
||||
add_executable(qtwaylandscanner_kde IMPORTED GLOBAL)
|
||||
add_dependencies(qtwaylandscanner_kde native_qtwaylandscanner_kde)
|
||||
set_target_properties(qtwaylandscanner_kde PROPERTIES IMPORTED_LOCATION
|
||||
${CMAKE_CURRENT_BINARY_DIR}/native_qtwaylandscanner_kde-prefix/src/native_qtwaylandscanner_kde-build/qtwaylandscanner_kde)
|
||||
else()
|
||||
# host build
|
||||
remove_definitions(-DQT_NO_CAST_FROM_ASCII)
|
||||
add_executable(qtwaylandscanner_kde qtwaylandscanner.cpp)
|
||||
target_link_libraries(qtwaylandscanner_kde Qt::Core)
|
||||
include(ECMMarkNonGuiExecutable)
|
||||
ecm_mark_nongui_executable(qtwaylandscanner_kde)
|
||||
endif()
|
||||
|
||||
function(ecm_add_qtwayland_server_protocol_kde target)
|
||||
# Parse arguments
|
||||
|
|
Loading…
Reference in a new issue