diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-11-20 17:07:03 -0800 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-11-20 17:07:03 -0800 |
| commit | eec26f68fc0f380118b2de7670c98f7a639d9d4b (patch) | |
| tree | 8cf88593e0db892f0e2b14b275264a21c0fcf619 /ports/qt5modularscripts | |
| parent | 875bb9a6611d51c0cd6b476983e0f220203a603d (diff) | |
| download | vcpkg-eec26f68fc0f380118b2de7670c98f7a639d9d4b.tar.gz vcpkg-eec26f68fc0f380118b2de7670c98f7a639d9d4b.zip | |
[qt5] Reduce duplication in modular build by extracting qt5modularscripts
Diffstat (limited to 'ports/qt5modularscripts')
| -rw-r--r-- | ports/qt5modularscripts/CONTROL | 3 | ||||
| -rw-r--r-- | ports/qt5modularscripts/fixcmake.py | 57 | ||||
| -rw-r--r-- | ports/qt5modularscripts/portfile.cmake | 9 | ||||
| -rw-r--r-- | ports/qt5modularscripts/qt_modular_library.cmake | 174 |
4 files changed, 243 insertions, 0 deletions
diff --git a/ports/qt5modularscripts/CONTROL b/ports/qt5modularscripts/CONTROL new file mode 100644 index 000000000..88c0379af --- /dev/null +++ b/ports/qt5modularscripts/CONTROL @@ -0,0 +1,3 @@ +Source: qt5modularscripts +Version: 0 +Description: Vcpkg helpers to package qt5 modules diff --git a/ports/qt5modularscripts/fixcmake.py b/ports/qt5modularscripts/fixcmake.py new file mode 100644 index 000000000..923e600bc --- /dev/null +++ b/ports/qt5modularscripts/fixcmake.py @@ -0,0 +1,57 @@ +import os +import re +from glob import glob + +files = [y for x in os.walk('.') for y in glob(os.path.join(x[0], '*.cmake'))] + +for f in files: + openedfile = open(f, "r") + builder = "" + dllpattern = re.compile("_install_prefix}/bin/Qt5.*d.dll") + libpattern = re.compile("_install_prefix}/lib/Qt5.*d.lib") + exepattern = re.compile("_install_prefix}/bin/[a-z]+.exe") + tooldllpattern = re.compile("_install_prefix}/tools/qt5/Qt5.*d.dll") + for line in openedfile: + if "_install_prefix}/tools/qt5/${LIB_LOCATION}" in line: + builder += " if (${Configuration} STREQUAL \"RELEASE\")" + builder += "\n " + line.replace("/tools/qt5/", "/bin/") + builder += " else()" + builder += "\n " + line.replace("/tools/qt5/", "/debug/bin/") + builder += " endif()\n" + elif "_install_prefix}/bin/${LIB_LOCATION}" in line: + builder += " if (${Configuration} STREQUAL \"RELEASE\")" + builder += "\n " + line + builder += " else()" + builder += "\n " + line.replace("/bin/", "/debug/bin/") + builder += " endif()\n" + elif "_install_prefix}/lib/${LIB_LOCATION}" in line: + builder += " if (${Configuration} STREQUAL \"RELEASE\")" + builder += "\n " + line + builder += " else()" + builder += "\n " + line.replace("/lib/", "/debug/lib/") + builder += " endif()\n" + elif "_install_prefix}/lib/${IMPLIB_LOCATION}" in line: + builder += " if (${Configuration} STREQUAL \"RELEASE\")" + builder += "\n " + line + builder += " else()" + builder += "\n " + line.replace("/lib/", "/debug/lib/") + builder += " endif()\n" + elif "_install_prefix}/plugins/${PLUGIN_LOCATION}" in line: + builder += " if (${Configuration} STREQUAL \"RELEASE\")" + builder += "\n " + line + builder += " else()" + builder += "\n " + line.replace("/plugins/", "/debug/plugins/") + builder += " endif()\n" + elif dllpattern.search(line) != None: + builder += line.replace("/bin/", "/debug/bin/") + elif libpattern.search(line) != None: + builder += line.replace("/lib/", "/debug/lib/") + elif tooldllpattern.search(line) != None: + builder += line.replace("/tools/qt5/", "/debug/bin/") + elif exepattern.search(line) != None: + builder += line.replace("/bin/", "/tools/qt5/") + else: + builder += line + new_file = open(f, "w") + new_file.write(builder) + new_file.close()
\ No newline at end of file diff --git a/ports/qt5modularscripts/portfile.cmake b/ports/qt5modularscripts/portfile.cmake new file mode 100644 index 000000000..e7149adfc --- /dev/null +++ b/ports/qt5modularscripts/portfile.cmake @@ -0,0 +1,9 @@ +file(COPY + ${CMAKE_CURRENT_LIST_DIR}/fixcmake.py + ${CMAKE_CURRENT_LIST_DIR}/qt_modular_library.cmake + DESTINATION + ${CURRENT_PACKAGES_DIR}/share/qt5modularscripts +) +file(WRITE ${CURRENT_PACKAGES_DIR}/share/qt5modularscripts/copyright "") + +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) diff --git a/ports/qt5modularscripts/qt_modular_library.cmake b/ports/qt5modularscripts/qt_modular_library.cmake new file mode 100644 index 000000000..6fa4c20c8 --- /dev/null +++ b/ports/qt5modularscripts/qt_modular_library.cmake @@ -0,0 +1,174 @@ +set(_qt5base_port_dir "${CMAKE_CURRENT_LIST_DIR}")
+
+function(qt_modular_library NAME HASH)
+ string(LENGTH "${CURRENT_BUILDTREES_DIR}" BUILDTREES_PATH_LENGTH)
+ if(BUILDTREES_PATH_LENGTH GREATER 45)
+ message(WARNING "Qt5's buildsystem uses very long paths and may fail on your system.\n"
+ "We recommend moving vcpkg to a short path such as 'C:\\src\\vcpkg' or using the subst command."
+ )
+ endif()
+
+ if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
+ message(FATAL_ERROR "Qt5 doesn't currently support static builds. Please use a dynamic triplet instead.")
+ endif()
+
+ set(SRCDIR_NAME "${NAME}-5.9.2")
+ set(ARCHIVE_NAME "${NAME}-opensource-src-5.9.2")
+ set(ARCHIVE_EXTENSION ".tar.xz")
+
+ set(SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/${SRCDIR_NAME})
+ vcpkg_download_distfile(ARCHIVE_FILE
+ URLS "http://download.qt.io/official_releases/qt/5.9/5.9.2/submodules/${ARCHIVE_NAME}${ARCHIVE_EXTENSION}"
+ FILENAME ${SRCDIR_NAME}${ARCHIVE_EXTENSION}
+ SHA512 ${HASH}
+ )
+ vcpkg_extract_source_archive(${ARCHIVE_FILE})
+ if (EXISTS ${CURRENT_BUILDTREES_DIR}/src/${ARCHIVE_NAME})
+ file(RENAME ${CURRENT_BUILDTREES_DIR}/src/${ARCHIVE_NAME} ${CURRENT_BUILDTREES_DIR}/src/${SRCDIR_NAME})
+ endif()
+
+ # This fixes issues on machines with default codepages that are not ASCII compatible, such as some CJK encodings
+ set(ENV{_CL_} "/utf-8")
+
+ #Store build paths
+ set(DEBUG_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
+ set(RELEASE_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
+
+ file(REMOVE_RECURSE "${DEBUG_DIR}" "${RELEASE_DIR}")
+
+ #Find Python and add it to the path
+ vcpkg_find_acquire_program(PYTHON3)
+ get_filename_component(PYTHON3_EXE_PATH ${PYTHON3} DIRECTORY)
+ set(ENV{PATH} "${PYTHON3_EXE_PATH};$ENV{PATH}")
+
+ #Configure debug
+ vcpkg_configure_qmake_debug(
+ SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/${SRCDIR_NAME}
+ )
+
+ #First generate the makefiles so we can modify them
+ vcpkg_build_qmake_debug(TARGETS qmake_all)
+
+ #Store debug makefiles path
+ file(GLOB_RECURSE DEBUG_MAKEFILES ${DEBUG_DIR}/*Makefile*)
+
+ foreach(DEBUG_MAKEFILE ${DEBUG_MAKEFILES})
+ file(READ "${DEBUG_MAKEFILE}" _contents)
+ string(REPLACE "zlib.lib" "zlibd.lib" _contents "${_contents}")
+ string(REPLACE "vcpkg\\installed\\${TARGET_TRIPLET}\\lib" "vcpkg\\installed\\${TARGET_TRIPLET}\\debug\\lib" _contents "${_contents}")
+ file(WRITE "${DEBUG_MAKEFILE}" "${_contents}")
+ endforeach()
+
+ #Build debug
+ vcpkg_build_qmake_debug()
+
+ #Configure release
+ vcpkg_configure_qmake_release(
+ SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/${SRCDIR_NAME}
+ )
+
+ #First generate the makefiles so we can modify them
+ vcpkg_build_qmake_release(TARGETS qmake_all)
+
+ #Store release makefile path
+ file(GLOB_RECURSE RELEASE_MAKEFILES ${RELEASE_DIR}/*Makefile*)
+
+ #Build release
+ vcpkg_build_qmake_release()
+
+ #Fix the cmake files if they exist
+ if(EXISTS ${RELEASE_DIR}/lib/cmake)
+ vcpkg_execute_required_process(
+ COMMAND ${PYTHON3} ${_qt5base_port_dir}/fixcmake.py
+ WORKING_DIRECTORY ${RELEASE_DIR}/lib/cmake
+ LOGNAME fix-cmake
+ )
+ endif()
+
+ file(TO_NATIVE_PATH "${CURRENT_INSTALLED_DIR}" NATIVE_INSTALLED_DIR)
+ file(TO_NATIVE_PATH "${CURRENT_PACKAGES_DIR}" NATIVE_PACKAGES_DIR)
+
+ string(SUBSTRING "${NATIVE_INSTALLED_DIR}" 2 -1 INSTALLED_DIR_WITHOUT_DRIVE)
+ string(SUBSTRING "${NATIVE_PACKAGES_DIR}" 2 -1 PACKAGES_DIR_WITHOUT_DRIVE)
+
+ #Set the correct install directory to packages
+ foreach(MAKEFILE ${RELEASE_MAKEFILES} ${DEBUG_MAKEFILES})
+ vcpkg_replace_string(${MAKEFILE} "(INSTALL_ROOT)${INSTALLED_DIR_WITHOUT_DRIVE}" "(INSTALL_ROOT)${PACKAGES_DIR_WITHOUT_DRIVE}")
+ endforeach()
+
+ #Install the module files
+ vcpkg_build_qmake_debug(TARGETS install)
+ vcpkg_build_qmake_release(TARGETS install)
+
+ #Remove extra cmake files
+ if(EXISTS ${CURRENT_PACKAGES_DIR}/lib/cmake)
+ file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/share)
+ file(RENAME ${CURRENT_PACKAGES_DIR}/lib/cmake ${CURRENT_PACKAGES_DIR}/share/cmake)
+ endif()
+ if(EXISTS ${CURRENT_PACKAGES_DIR}/debug/lib/cmake)
+ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/lib/cmake)
+ endif()
+
+ file(GLOB RELEASE_LIBS "${CURRENT_PACKAGES_DIR}/lib/*")
+ if(NOT RELEASE_LIBS)
+ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/lib)
+ endif()
+ file(GLOB DEBUG_FILES "${CURRENT_PACKAGES_DIR}/debug/lib/*")
+ if(NOT DEBUG_FILES)
+ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/lib)
+ endif()
+
+ #Move release and debug dlls to the correct directory
+ if(EXISTS ${CURRENT_PACKAGES_DIR}/tools/qt5)
+ file(RENAME ${CURRENT_PACKAGES_DIR}/tools/qt5 ${CURRENT_PACKAGES_DIR}/tools/${PORT})
+ file(RENAME ${CURRENT_PACKAGES_DIR}/debug/tools/qt5 ${CURRENT_PACKAGES_DIR}/debug/tools/${PORT})
+ endif()
+
+ file(GLOB RELEASE_DLLS ${CURRENT_PACKAGES_DIR}/tools/${PORT}/*.dll)
+ file(GLOB DEBUG_DLLS ${CURRENT_PACKAGES_DIR}/debug/tools/${PORT}/*.dll)
+ if (RELEASE_DLLS)
+ file(INSTALL ${RELEASE_DLLS} DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
+ file(REMOVE ${RELEASE_DLLS})
+ #Check if there are any binaries left over; if not - delete the directory
+ file(GLOB RELEASE_BINS ${CURRENT_PACKAGES_DIR}/tools/${PORT}/*)
+ if(NOT RELEASE_BINS)
+ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/tools)
+ endif()
+ endif()
+ if(DEBUG_DLLS)
+ file(INSTALL ${DEBUG_DLLS} DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
+ #file(REMOVE ${DEBUG_DLLS})
+ #Check if there are any binaries left over; if not - delete the directory
+ # file(GLOB DEBUG_BINS ${CURRENT_PACKAGES_DIR}/debug/tools/qt5/*)
+ # if(NOT DEBUG_BINS)
+ # file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/tools)
+ # endif()
+ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/tools)
+ endif()
+
+ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/share/qt5/debug/include)
+
+ # file(GLOB DEBUG_LIBS "${CURRENT_PACKAGES_DIR}/debug/lib/*.lib")
+ # if(EXISTS ${CURRENT_PACKAGES_DIR}/bin)
+ # make_directory(${CURRENT_PACKAGES_DIR}/debug/bin)
+ # foreach(DEBUG_LIB ${DEBUG_LIBS})
+ # get_filename_component(DEBUG_STEM "${DEBUG_LIB}" NAME_WE)
+ # file(RENAME ${CURRENT_PACKAGES_DIR}/bin/${DEBUG_STEM}.dll ${CURRENT_PACKAGES_DIR}/debug/bin/${DEBUG_STEM}.dll)
+ # endforeach()
+ # endif()
+
+ vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT})
+
+ #Find the relevant license file and install it
+ if(EXISTS "${SOURCE_PATH}/LICENSE.LGPLv3")
+ set(LICENSE_PATH "${SOURCE_PATH}/LICENSE.LGPLv3")
+ elseif(EXISTS "${SOURCE_PATH}/LICENSE.LGPL3")
+ set(LICENSE_PATH "${SOURCE_PATH}/LICENSE.LGPL3")
+ elseif(EXISTS "${SOURCE_PATH}/LICENSE.GPLv3")
+ set(LICENSE_PATH "${SOURCE_PATH}/LICENSE.GPLv3")
+ elseif(EXISTS "${SOURCE_PATH}/LICENSE.GPL3")
+ set(LICENSE_PATH "${SOURCE_PATH}/LICENSE.GPL3")
+ endif()
+ file(INSTALL ${LICENSE_PATH} DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
+
+endfunction()
\ No newline at end of file |
