cmake -D VCPKG_BUILD_TYPE could be set to either release debug or release in order to build vcpkg in a specific build type, otherwise it will build with debug and release

This commit is contained in:
Thijs Wenker 2020-02-08 15:43:39 +01:00
parent 997eb14ddc
commit 48ee437c00
7 changed files with 79 additions and 18 deletions

View file

@ -79,7 +79,7 @@ jobs:
- name: Configure CMake
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_EXTRA
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DVCPKG_BUILD_TYPE=release $CMAKE_EXTRA
- name: Build Application
working-directory: ${{runner.workspace}}/build
shell: bash
@ -126,7 +126,7 @@ jobs:
- name: Configure CMake
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_TOOLS:BOOLEAN=FALSE
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DVCPKG_BUILD_TYPE=release -DBUILD_TOOLS:BOOLEAN=FALSE
- name:
shell: bash
working-directory: ${{runner.workspace}}/build

View file

@ -67,8 +67,12 @@ if (HIFI_ANDROID)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
else()
set(VCPKG_BUILD_TYPE_PARAM "")
if (VCPKG_BUILD_TYPE)
set(VCPKG_BUILD_TYPE_PARAM --vcpkg-build-type ${VCPKG_BUILD_TYPE})
endif()
execute_process(
COMMAND ${HIFI_PYTHON_EXEC} ${CMAKE_CURRENT_SOURCE_DIR}/prebuild.py --release-type ${RELEASE_TYPE} --build-root ${CMAKE_BINARY_DIR}
COMMAND ${HIFI_PYTHON_EXEC} ${CMAKE_CURRENT_SOURCE_DIR}/prebuild.py --release-type ${RELEASE_TYPE} --build-root ${CMAKE_BINARY_DIR} ${VCPKG_BUILD_TYPE_PARAM}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# squelch the Policy CMP0074 warning without requiring an update to cmake 3.12.

View file

@ -1,6 +1,5 @@
macro(TARGET_DRACO)
set(LIBS draco dracodec dracoenc)
find_library(LIBPATH ${LIB} PATHS )
if (ANDROID)
set(INSTALL_DIR ${HIFI_ANDROID_PRECOMPILED}/draco)
set(DRACO_INCLUDE_DIRS "${INSTALL_DIR}/include" CACHE STRING INTERNAL)
@ -12,6 +11,8 @@ macro(TARGET_DRACO)
else()
set(LIB_SEARCH_PATH_RELEASE ${VCPKG_INSTALL_ROOT}/lib/)
set(LIB_SEARCH_PATH_DEBUG ${VCPKG_INSTALL_ROOT}/debug/lib/)
set(DRACO_LIBRARY_RELEASE "")
set(DRACO_LIBRARY_DEBUG "")
foreach(LIB ${LIBS})
find_library(${LIB}_LIBPATH ${LIB} PATHS ${LIB_SEARCH_PATH_RELEASE} NO_DEFAULT_PATH)
list(APPEND DRACO_LIBRARY_RELEASE ${${LIB}_LIBPATH})

View file

@ -28,6 +28,8 @@ macro(TARGET_OPENEXR)
string(REGEX MATCHALL "[0-9]" OPENEXR_MINOR_VERSION ${TMP})
endif()
set(OPENEXR_LIBRARY_RELEASE "")
set(OPENEXR_LIBRARY_DEBUG "")
foreach(OPENEXR_LIB
IlmImf
IlmImfUtil

View file

@ -24,10 +24,14 @@ vcpkg_configure_cmake(
vcpkg_install_cmake()
if (WIN32)
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/bin)
file(RENAME ${CURRENT_PACKAGES_DIR}/lib/quazip5.dll ${CURRENT_PACKAGES_DIR}/bin/quazip5.dll)
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/debug/bin)
file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/quazip5d.dll ${CURRENT_PACKAGES_DIR}/debug/bin/quazip5.dll)
if (NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/bin)
file(RENAME ${CURRENT_PACKAGES_DIR}/lib/quazip5.dll ${CURRENT_PACKAGES_DIR}/bin/quazip5.dll)
endif()
if (NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/debug/bin)
file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/quazip5d.dll ${CURRENT_PACKAGES_DIR}/debug/bin/quazip5.dll)
endif()
elseif(DEFINED VCPKG_TARGET_IS_LINUX)
# We only want static libs.
file(GLOB QUAZIP5_DYNAMIC_LIBS ${CURRENT_PACKAGES_DIR}/lib/libquazip5.so* ${CURRENT_PACKAGES_DIR}/debug/lib/libquazip5d.so*)

View file

@ -21,6 +21,7 @@ get_filename_component(CMAKE_TOOLCHAIN_FILE "{}" ABSOLUTE CACHE)
get_filename_component(CMAKE_TOOLCHAIN_FILE_UNCACHED "{}" ABSOLUTE)
set(VCPKG_INSTALL_ROOT "{}")
set(VCPKG_TOOLS_DIR "{}")
set(VCPKG_TARGET_TRIPLET "{}")
"""
CMAKE_TEMPLATE_NON_ANDROID = """
@ -34,7 +35,11 @@ endif()
self.args = args
# our custom ports, relative to the script location
self.sourcePortsPath = args.ports_path
self.id = hifi_utils.hashFolder(self.sourcePortsPath)[:8]
self.vcpkgBuildType = args.vcpkg_build_type
if (self.vcpkgBuildType):
self.id = hifi_utils.hashFolder(self.sourcePortsPath)[:8] + "-" + self.vcpkgBuildType
else:
self.id = hifi_utils.hashFolder(self.sourcePortsPath)[:8]
self.configFilePath = os.path.join(args.build_root, 'vcpkg.cmake')
self.assets_url = self.readVar('EXTERNAL_BUILD_ASSETS')
@ -82,15 +87,15 @@ endif()
if 'Windows' == system:
self.exe = os.path.join(self.path, 'vcpkg.exe')
self.bootstrapCmds = [ os.path.join(self.path, 'bootstrap-vcpkg.bat') ]
self.bootstrapCmds = [ os.path.join(self.path, 'bootstrap-vcpkg.bat'), '-disableMetrics' ]
self.vcpkgUrl = self.assets_url + '/dependencies/vcpkg/builds/vcpkg-win32-client.zip%3FversionId=tSFzbw01VkkVFeRQ6YuAY4dro2HxJR9U'
self.vcpkgHash = 'a650db47a63ccdc9904b68ddd16af74772e7e78170b513ea8de5a3b47d032751a3b73dcc7526d88bcb500753ea3dd9880639ca842bb176e2bddb1710f9a58cd3'
self.hostTriplet = 'x64-windows'
if usePrebuilt:
self.prebuiltArchive = self.assets_url + "/dependencies/vcpkg/builds/vcpkg-win32.zip%3FversionId=3SF3mDC8dkQH1JP041m88xnYmWNzZflx"
self.prebuiltArchive = "https://ipfs.io/ipfs/QmcBggttJQb1vYeyz29FXfaxnJ5c1HfZW72xNQepnENude/vcpkg-win32-a2623c6a-release.zip"
elif 'Darwin' == system:
self.exe = os.path.join(self.path, 'vcpkg')
self.bootstrapCmds = [ os.path.join(self.path, 'bootstrap-vcpkg.sh'), '--allowAppleClang' ]
self.bootstrapCmds = [ os.path.join(self.path, 'bootstrap-vcpkg.sh'), '--allowAppleClang', '-disableMetrics' ]
self.vcpkgUrl = self.assets_url + '/dependencies/vcpkg/builds/vcpkg-osx-client.tgz%3FversionId=j0b4azo_zTlH_Q9DElEWOz1UMYZ2nqQw'
self.vcpkgHash = '519d666d02ef22b87c793f016ca412e70f92e1d55953c8f9bd4ee40f6d9f78c1df01a6ee293907718f3bbf24075cc35492fb216326dfc50712a95858e9cbcb4d'
self.hostTriplet = 'x64-osx'
@ -98,7 +103,7 @@ endif()
self.prebuiltArchive = self.assets_url + "/dependencies/vcpkg/builds/vcpkg-osx.tgz%3FversionId=6JrIMTdvpBF3MAsjA92BMkO79Psjzs6Z"
else:
self.exe = os.path.join(self.path, 'vcpkg')
self.bootstrapCmds = [ os.path.join(self.path, 'bootstrap-vcpkg.sh') ]
self.bootstrapCmds = [ os.path.join(self.path, 'bootstrap-vcpkg.sh'), '-disableMetrics' ]
self.vcpkgUrl = self.assets_url + '/dependencies/vcpkg/builds/vcpkg-linux-client.tgz%3FversionId=y7mct0gFicEXz5hJy3KROBugcLR56YWf'
self.vcpkgHash = '6a1ce47ef6621e699a4627e8821ad32528c82fce62a6939d35b205da2d299aaa405b5f392df4a9e5343dd6a296516e341105fbb2dd8b48864781d129d7fba10d'
self.hostTriplet = 'x64-linux'
@ -206,6 +211,19 @@ endif()
print(actualCommands)
hifi_utils.executeSubprocess(actualCommands, folder=self.path, env=self.buildEnv)
def copyTripletForBuildType(self, triplet):
print('Copying triplet ' + triplet + ' to have build type ' + self.vcpkgBuildType)
tripletPath = os.path.join(self.path, 'triplets', triplet + '.cmake')
tripletForBuildTypePath = os.path.join(self.path, 'triplets', self.getTripletWithBuildType(triplet) + '.cmake')
shutil.copy(tripletPath, tripletForBuildTypePath)
with open(tripletForBuildTypePath, "a") as tripletForBuildTypeFile:
tripletForBuildTypeFile.write("set(VCPKG_BUILD_TYPE " + self.vcpkgBuildType + ")\n")
def getTripletWithBuildType(self, triplet):
if (not self.vcpkgBuildType):
return triplet
return triplet + '-' + self.vcpkgBuildType
def setupDependencies(self, qt=None):
if self.prebuiltArchive:
if not os.path.isfile(self.prebuildTagFile):
@ -224,12 +242,16 @@ endif()
self.setupAndroidDependencies()
print("Installing host tools")
self.run(['install', '--triplet', self.hostTriplet, 'hifi-host-tools'])
if (self.vcpkgBuildType):
self.copyTripletForBuildType(self.hostTriplet)
self.run(['install', '--triplet', self.getTripletWithBuildType(self.hostTriplet), 'hifi-host-tools'])
# If not android, install the hifi-client-deps libraries
if not self.args.android:
print("Installing build dependencies")
self.run(['install', '--triplet', self.triplet, 'hifi-client-deps'])
if (self.vcpkgBuildType):
self.copyTripletForBuildType(self.triplet)
self.run(['install', '--triplet', self.getTripletWithBuildType(self.triplet), 'hifi-client-deps'])
def cleanBuilds(self):
if self.noClean:
@ -276,12 +298,32 @@ endif()
with open(self.prebuildTagFile, 'w') as f:
f.write(self.tagContents)
def fixupCmakeScript(self):
cmakeScript = os.path.join(self.path, 'scripts/buildsystems/vcpkg.cmake')
newCmakeScript = cmakeScript + '.new'
isFileChanged = False
removalPrefix = "set(VCPKG_TARGET_TRIPLET "
# Open original file in read only mode and dummy file in write mode
with open(cmakeScript, 'r') as read_obj, open(newCmakeScript, 'w') as write_obj:
# Line by line copy data from original file to dummy file
for line in read_obj:
if not line.startswith(removalPrefix):
write_obj.write(line)
else:
isFileChanged = True
if isFileChanged:
shutil.move(newCmakeScript, cmakeScript)
else:
os.remove(newCmakeScript)
def writeConfig(self):
print("Writing cmake config to {}".format(self.configFilePath))
# Write out the configuration for use by CMake
cmakeScript = os.path.join(self.path, 'scripts/buildsystems/vcpkg.cmake')
installPath = os.path.join(self.path, 'installed', self.triplet)
toolsPath = os.path.join(self.path, 'installed', self.hostTriplet, 'tools')
installPath = os.path.join(self.path, 'installed', self.getTripletWithBuildType(self.triplet))
toolsPath = os.path.join(self.path, 'installed', self.getTripletWithBuildType(self.hostTriplet), 'tools')
cmakeTemplate = VcpkgRepo.CMAKE_TEMPLATE
if self.args.android:
@ -289,7 +331,7 @@ endif()
cmakeTemplate += 'set(HIFI_ANDROID_PRECOMPILED "{}")\n'.format(precompiled)
else:
cmakeTemplate += VcpkgRepo.CMAKE_TEMPLATE_NON_ANDROID
cmakeConfig = cmakeTemplate.format(cmakeScript, cmakeScript, installPath, toolsPath).replace('\\', '/')
cmakeConfig = cmakeTemplate.format(cmakeScript, cmakeScript, installPath, toolsPath, self.getTripletWithBuildType(self.hostTriplet)).replace('\\', '/')
with open(self.configFilePath, 'w') as f:
f.write(cmakeConfig)

View file

@ -94,6 +94,7 @@ def parse_args():
parser.add_argument('--force-build', action='store_true')
parser.add_argument('--release-type', type=str, default="DEV", help="DEV, PR, or PRODUCTION")
parser.add_argument('--vcpkg-root', type=str, help='The location of the vcpkg distribution')
parser.add_argument('--vcpkg-build-type', type=str, help='Could be `release` or `debug`. By default it doesn`t set the build-type')
parser.add_argument('--build-root', required=True, type=str, help='The location of the cmake build')
parser.add_argument('--ports-path', type=str, default=defaultPortsPath)
parser.add_argument('--ci-build', action='store_true', default=os.getenv('CI_BUILD') is not None)
@ -142,6 +143,10 @@ def main():
pm.writeVar('QT_CMAKE_PREFIX_PATH', qtInstallPath)
# Only allow one instance of the program to run at a time
if qtInstallPath != '':
pm.writeVar('QT_CMAKE_PREFIX_PATH', qtInstallPath)
with hifi_singleton.Singleton(pm.lockFile) as lock:
with timer('Bootstraping'):
@ -175,6 +180,9 @@ def main():
qtPath = os.path.join(pm.androidPackagePath, 'qt')
hifi_android.QtPackager(appPath, qtPath).bundle()
# Fixup the vcpkg cmake to not reset VCPKG_TARGET_TRIPLET
pm.fixupCmakeScript()
# Write the vcpkg config to the build directory last
with timer('Writing configuration'):
pm.writeConfig()