mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-17 18:40:35 +02:00
more correct QT_VERSION detection
This commit is contained in:
parent
a4d43bbff9
commit
595edb9f6e
3 changed files with 66 additions and 21 deletions
|
@ -36,8 +36,8 @@ endif()
|
||||||
if(NOT EXISTS "${CMAKE_BINARY_DIR}/vcpkg.cmake")
|
if(NOT EXISTS "${CMAKE_BINARY_DIR}/vcpkg.cmake")
|
||||||
message(FATAL_ERROR "vcpkg configuration missing.")
|
message(FATAL_ERROR "vcpkg configuration missing.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include("${CMAKE_BINARY_DIR}/vcpkg.cmake")
|
include("${CMAKE_BINARY_DIR}/vcpkg.cmake")
|
||||||
|
|
||||||
project(hifi)
|
project(hifi)
|
||||||
include("cmake/init.cmake")
|
include("cmake/init.cmake")
|
||||||
include("cmake/compiler.cmake")
|
include("cmake/compiler.cmake")
|
||||||
|
@ -196,7 +196,9 @@ unset(JS_SRC)
|
||||||
|
|
||||||
set_packaging_parameters()
|
set_packaging_parameters()
|
||||||
|
|
||||||
if (PRODUCTION_BUILD)
|
if (NOT DEV_BUILD)
|
||||||
|
# add options to strip symbols for PRODUCTION and PR builds
|
||||||
|
# TODO?: call set_packaging_parameters() earlier and move this symbol stripping into compiler.cmake
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s")
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
|
|
|
@ -5,34 +5,76 @@
|
||||||
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
#
|
#
|
||||||
|
|
||||||
|
function(get_sub_directories result curdir)
|
||||||
|
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
||||||
|
set(dirlist "")
|
||||||
|
foreach(child ${children})
|
||||||
|
if(IS_DIRECTORY ${curdir}/${child})
|
||||||
|
LIST(APPEND dirlist ${child})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
set(${result} ${dirlist} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(calculate_qt5_version result _QT_DIR)
|
||||||
|
# All Qt5 packages have little "private" include directories named with the actual Qt version such as:
|
||||||
|
# .../include/QtCore/5.12.3/QtCore/private
|
||||||
|
# Sometimes we need to include these private headers for debug hackery.
|
||||||
|
# Hence we find one of these directories and pick apart its path to determine the actual QT_VERSION.
|
||||||
|
set(_QT_CORE_DIR "${_QT_DIR}/include/QtCore")
|
||||||
|
if(NOT EXISTS "${_QT_CORE_DIR}")
|
||||||
|
message(FATAL_ERROR "Could not find 'include/QtCore' in '${_QT_DIR}'")
|
||||||
|
endif()
|
||||||
|
set(subdirs "")
|
||||||
|
get_sub_directories(subdirs ${_QT_CORE_DIR})
|
||||||
|
|
||||||
|
foreach(subdir ${subdirs})
|
||||||
|
string(REGEX MATCH "5.[0-9]+.[0-9]+$" _QT_VERSION ${subdir})
|
||||||
|
if (NOT "${_QT_VERSION}" STREQUAL "")
|
||||||
|
# found it!
|
||||||
|
set(${result} "${_QT_VERSION}" PARENT_SCOPE)
|
||||||
|
break()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Sets the QT_CMAKE_PREFIX_PATH and QT_DIR variables
|
# Sets the QT_CMAKE_PREFIX_PATH and QT_DIR variables
|
||||||
# Also enables CMAKE_AUTOMOC and CMAKE_AUTORCC
|
# Also enables CMAKE_AUTOMOC and CMAKE_AUTORCC
|
||||||
macro(setup_qt)
|
macro(setup_qt)
|
||||||
# if we are in a development build and QT_CMAKE_PREFIX_PATH is specified
|
# if we are in a development build and QT_CMAKE_PREFIX_PATH is specified
|
||||||
# then use it,
|
# then use it,
|
||||||
# otherwise, use the vcpkg'ed version
|
# otherwise, use the vcpkg'ed version
|
||||||
if (RELEASE_TYPE STREQUAL "DEV" AND DEFINED ENV{QT_CMAKE_PREFIX_PATH})
|
if(NOT DEFINED VCPKG_QT_CMAKE_PREFIX_PATH)
|
||||||
message("Development build and QT_CMAKE_PREFIX_PATH is defined in environment - using this path for Qt")
|
message(FATAL_ERROR "VCPKG_QT_CMAKE_PREFIX_PATH should have been set by hifi_vcpkg.py")
|
||||||
set(QT_CMAKE_PREFIX_PATH $ENV{QT_CMAKE_PREFIX_PATH})
|
endif()
|
||||||
|
if (NOT DEFINED ENV{QT_CMAKE_PREFIX_PATH} OR NOT DEV_BUILD)
|
||||||
|
# HACK we ignore QT_CMAKE_PREFIX_PATH for PRODUCTION and PR builds
|
||||||
|
# so we can punt updating the automated build OS images while switching to vcpkg for Qt
|
||||||
|
set(QT_CMAKE_PREFIX_PATH ${VCPKG_QT_CMAKE_PREFIX_PATH})
|
||||||
else()
|
else()
|
||||||
message(" Using vcpkg'ed version of Qt")
|
set(QT_CMAKE_PREFIX_PATH $ENV{QT_CMAKE_PREFIX_PATH})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# figure out where the qt dir is
|
# figure out where the qt dir is
|
||||||
get_filename_component(QT_DIR "${QT_CMAKE_PREFIX_PATH}/../../" ABSOLUTE)
|
get_filename_component(QT_DIR "${QT_CMAKE_PREFIX_PATH}/../../" ABSOLUTE)
|
||||||
|
set(QT_VERSION "unknown")
|
||||||
|
calculate_qt5_version(QT_VERSION "${QT_DIR}")
|
||||||
|
if (QT_VERSION STREQUAL "unknown")
|
||||||
|
message(FATAL_ERROR "Could not determine QT_VERSION")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (WIN32)
|
if(WIN32)
|
||||||
# windows shell does not like backslashes expanded on the command line,
|
# windows shell does not like backslashes expanded on the command line,
|
||||||
# so convert all backslashes in the QT path to forward slashes
|
# so convert all backslashes in the QT path to forward slashes
|
||||||
string(REPLACE \\ / QT_CMAKE_PREFIX_PATH ${QT_CMAKE_PREFIX_PATH})
|
string(REPLACE \\ / QT_CMAKE_PREFIX_PATH ${QT_CMAKE_PREFIX_PATH})
|
||||||
string(REPLACE \\ / QT_DIR ${QT_DIR})
|
string(REPLACE \\ / QT_DIR ${QT_DIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT EXISTS "${QT_CMAKE_PREFIX_PATH}/Qt5Core/Qt5CoreConfig.cmake")
|
if(NOT EXISTS "${QT_CMAKE_PREFIX_PATH}/Qt5Core/Qt5CoreConfig.cmake")
|
||||||
message(FATAL_ERROR "Unable to locate Qt cmake config in ${QT_CMAKE_PREFIX_PATH}")
|
message(FATAL_ERROR "Unable to locate Qt5CoreConfig.cmake in '${QT_CMAKE_PREFIX_PATH}'")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message(STATUS "The Qt build in use is: \"${QT_DIR}\"")
|
message(STATUS "Using Qt build in : '${QT_DIR}' with version ${QT_VERSION}")
|
||||||
|
|
||||||
# Instruct CMake to run moc automatically when needed.
|
# Instruct CMake to run moc automatically when needed.
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
|
@ -15,11 +15,12 @@ print = functools.partial(print, flush=True)
|
||||||
# Encapsulates the vcpkg system
|
# Encapsulates the vcpkg system
|
||||||
class VcpkgRepo:
|
class VcpkgRepo:
|
||||||
CMAKE_TEMPLATE = """
|
CMAKE_TEMPLATE = """
|
||||||
|
# this file auto-generated by hifi_vcpkg.py
|
||||||
get_filename_component(CMAKE_TOOLCHAIN_FILE "{}" ABSOLUTE CACHE)
|
get_filename_component(CMAKE_TOOLCHAIN_FILE "{}" ABSOLUTE CACHE)
|
||||||
get_filename_component(CMAKE_TOOLCHAIN_FILE_UNCACHED "{}" ABSOLUTE)
|
get_filename_component(CMAKE_TOOLCHAIN_FILE_UNCACHED "{}" ABSOLUTE)
|
||||||
set(VCPKG_INSTALL_ROOT "{}")
|
set(VCPKG_INSTALL_ROOT "{}")
|
||||||
set(VCPKG_TOOLS_DIR "{}")
|
set(VCPKG_TOOLS_DIR "{}")
|
||||||
set(QT_CMAKE_PREFIX_PATH "{}")
|
set(VCPKG_QT_CMAKE_PREFIX_PATH "{}")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CMAKE_TEMPLATE_NON_ANDROID = """
|
CMAKE_TEMPLATE_NON_ANDROID = """
|
||||||
|
@ -218,17 +219,17 @@ endif()
|
||||||
cmakeScript = os.path.join(self.path, 'scripts/buildsystems/vcpkg.cmake')
|
cmakeScript = os.path.join(self.path, 'scripts/buildsystems/vcpkg.cmake')
|
||||||
installPath = os.path.join(self.path, 'installed', self.triplet)
|
installPath = os.path.join(self.path, 'installed', self.triplet)
|
||||||
toolsPath = os.path.join(self.path, 'installed', self.hostTriplet, 'tools')
|
toolsPath = os.path.join(self.path, 'installed', self.hostTriplet, 'tools')
|
||||||
cmakePrefixPath = os.path.join(self.path, 'installed', 'qt5-install/lib/cmake')
|
|
||||||
cmakeTemplate = VcpkgRepo.CMAKE_TEMPLATE
|
|
||||||
if not self.args.android:
|
|
||||||
cmakeTemplate += VcpkgRepo.CMAKE_TEMPLATE_NON_ANDROID
|
|
||||||
else:
|
|
||||||
precompiled = os.path.realpath(self.androidPackagePath)
|
|
||||||
qtCmakePrefix = os.path.realpath(os.path.join(precompiled, 'qt/lib/cmake'))
|
|
||||||
cmakeTemplate += 'set(HIFI_ANDROID_PRECOMPILED "{}")\n'.format(precompiled)
|
|
||||||
cmakeTemplate += 'set(QT_CMAKE_PREFIX_PATH "{}")\n'.format(qtCmakePrefix)
|
|
||||||
|
|
||||||
cmakeConfig = cmakeTemplate.format(cmakeScript, cmakeScript, installPath, toolsPath, cmakePrefixPath).replace('\\', '/')
|
cmakeTemplate = VcpkgRepo.CMAKE_TEMPLATE
|
||||||
|
qtCmakePrefixPath = os.path.join(self.path, 'installed', 'qt5-install/lib/cmake')
|
||||||
|
if self.args.android:
|
||||||
|
precompiled = os.path.realpath(self.androidPackagePath)
|
||||||
|
cmakeTemplate += 'set(HIFI_ANDROID_PRECOMPILED "{}")\n'.format(precompiled)
|
||||||
|
qtCmakePrefixPath = os.path.realpath(os.path.join(precompiled, 'qt/lib/cmake'))
|
||||||
|
else:
|
||||||
|
cmakeTemplate += VcpkgRepo.CMAKE_TEMPLATE_NON_ANDROID
|
||||||
|
|
||||||
|
cmakeConfig = cmakeTemplate.format(cmakeScript, cmakeScript, installPath, toolsPath, qtCmakePrefixPath).replace('\\', '/')
|
||||||
with open(self.configFilePath, 'w') as f:
|
with open(self.configFilePath, 'w') as f:
|
||||||
f.write(cmakeConfig)
|
f.write(cmakeConfig)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue