From 99d8bdca81bc4f407ae3f447c1a14fa80a925d5d Mon Sep 17 00:00:00 2001 From: Holden Date: Tue, 7 Jan 2025 21:47:38 -0500 Subject: [PATCH] Docker: Create MacOS script --- .dockerignore | 15 +++++++++++ CMakeLists.txt | 37 +++++++++++++++++++-------- cmake/Qt6QGCConfiguration.cmake | 2 +- deploy/docker/Dockerfile-build-macos | 36 ++++++++++++++++++++++++++ deploy/docker/Dockerfile-build-ubuntu | 4 +-- deploy/docker/run-docker-macos.sh | 16 ++++++++++++ deploy/docker/run-docker-ubuntu.sh | 23 ++++++++++++++--- 7 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 .dockerignore create mode 100644 deploy/docker/Dockerfile-build-macos create mode 100755 deploy/docker/run-docker-macos.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000000..e2a1739156b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +# Ignore Git repository files +.git +.gitignore + +# Ignore node_modules or other build artifacts +node_modules +build + +# Ignore Docker-related files +Dockerfile* +docker-compose.yml + +# Ignore OS-specific files +.DS_Store +*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt index 80f6b72d036..ecff69c16d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,8 +118,8 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) include(Qt6QGCConfiguration) set(QT_QML_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/qml" CACHE PATH "Install path for QML" FORCE) -# set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports CACHE STRING "Extra QML Import Paths" FORCE) -add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x060600) +set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports CACHE STRING "Extra QML Import Paths" FORCE) +add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x060700) if(CMAKE_BUILD_TYPE STREQUAL "Release") add_compile_definitions( @@ -156,8 +156,17 @@ if(ANDROID) endif() set(QT_SILENCE_MISSING_DEPENDENCY_TARGET_WARNING ON) +set(QT_MINIMUM_VERSION 6.8.1) + +find_program(QMAKE_EXECUTABLE NAMES qmake HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin) +execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION) +if(QT_VERSION LESS QT_MINIMUM_VERSION) + MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}. + Installed version: ${QT_VERSION}") +endif() find_package(Qt6 + ${QT_MINIMUM_VERSION} REQUIRED COMPONENTS Concurrent @@ -186,6 +195,7 @@ find_package(Qt6 LinguistTools MultimediaQuickPrivate Quick3D + Quick3DTools SerialPort WaylandClient HINTS @@ -197,8 +207,8 @@ if(NOT Qt6LinguistTools_DIR) endif() qt_standard_project_setup( - REQUIRES 6.8.1 - SUPPORTS_UP_TO 6.8.1 + REQUIRES ${QT_MINIMUM_VERSION} + SUPPORTS_UP_TO ${QT_MINIMUM_VERSION} I18N_SOURCE_LANGUAGE en ) @@ -302,6 +312,8 @@ if(Qt6LinguistTools_FOUND) file(GLOB TS_SOURCES ${CMAKE_SOURCE_DIR}/translations/qgc_*.ts) set_source_files_properties(${TS_SOURCES} PROPERTIES OUTPUT_LOCATION "${CMAKE_BINARY_DIR}/i18n") qt_add_translations(${CMAKE_PROJECT_NAME} + # TS_FILE_BASE ${CMAKE_PROJECT_NAME} + # TS_FILE_DIR ${CMAKE_SOURCE_DIR}/translations/ TS_FILES ${TS_SOURCES} RESOURCE_PREFIX "/" LUPDATE_OPTIONS -no-obsolete @@ -413,7 +425,7 @@ elseif(ANDROID) ) FetchContent_MakeAvailable(android_openssl) include(${android_openssl_SOURCE_DIR}/android_openssl.cmake) - add_android_openssl_libraries(${PROJECT_NAME}) + add_android_openssl_libraries(${CMAKE_PROJECT_NAME}) set(ANDROID_PLATFORM_ARCHITECTURE_CODE) if(${ANDROID_ABI} STREQUAL "armeabi-v7a") @@ -462,14 +474,12 @@ elseif(ANDROID) QT_ANDROID_PACKAGE_SOURCE_DIR "${QGC_ANDROID_PACKAGE_SOURCE_DIR}" QT_ANDROID_VERSION_NAME ${CMAKE_PROJECT_VERSION} QT_ANDROID_VERSION_CODE ${ANDROID_VERSION_CODE} - # QT_QML_ROOT_PATH ${CMAKE_SOURCE_DIR} + QT_QML_ROOT_PATH ${CMAKE_SOURCE_DIR}/src # QT_ANDROID_SDK_BUILD_TOOLS_REVISION # QT_ANDROID_SYSTEM_LIBS_PREFIX ) - # get_target_property(QGC_ANDROID_DEPLOY_FILE ${PROJECT_NAME} QT_ANDROID_DEPLOYMENT_SETTINGS_FILE) - # QT_ANDROID_DEPLOYMENT_DEPENDENCIES - - cmake_print_variables(QGC_ANDROID_PACKAGE_NAME) + get_target_property(QGC_ANDROID_DEPLOY_FILE ${CMAKE_PROJECT_NAME} QT_ANDROID_DEPLOYMENT_SETTINGS_FILE) + cmake_print_variables(QGC_ANDROID_DEPLOY_FILE) elseif(LINUX) endif() @@ -517,10 +527,15 @@ install( BUNDLE DESTINATION . ) +set(deploy_tool_options_arg "") +if(APPLE) + set(deploy_tool_options_arg -qmldir=${CMAKE_SOURCE_DIR}/src -hardened-runtime -timestamp -appstore-compliant) +endif() + qt_generate_deploy_qml_app_script( TARGET ${PROJECT_NAME} OUTPUT_SCRIPT deploy_script - # DEPLOY_TOOL_OPTIONS + DEPLOY_TOOL_OPTIONS ${deploy_tool_options_arg} MACOS_BUNDLE_POST_BUILD NO_UNSUPPORTED_PLATFORM_ERROR DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM diff --git a/cmake/Qt6QGCConfiguration.cmake b/cmake/Qt6QGCConfiguration.cmake index a8a95ec5b58..6c9332dafa8 100644 --- a/cmake/Qt6QGCConfiguration.cmake +++ b/cmake/Qt6QGCConfiguration.cmake @@ -6,7 +6,7 @@ if(NOT QT_VERSION) # if QT version not specified then use any available version file(GLOB FOUND_QT_VERSIONS LIST_DIRECTORIES true - $ENV{HOME}/Qt/6.6.* + $ENV{HOME}/Qt/6.8.* ) if(NOT FOUND_QT_VERSIONS) return() diff --git a/deploy/docker/Dockerfile-build-macos b/deploy/docker/Dockerfile-build-macos new file mode 100644 index 00000000000..c857ef28d77 --- /dev/null +++ b/deploy/docker/Dockerfile-build-macos @@ -0,0 +1,36 @@ +# Use a lightweight base image; Docker-OSX handles the macOS environment +FROM sickcodes/docker-osx:latest + +# Set environment variables +ENV QT_VERSION=6.8.1 +ENV QT_PATH=/opt/Qt +ENV QT_DESKTOP=$QT_PATH/${QT_VERSION}/clang_64 + +ENV PATH=$QT_DESKTOP/bin:/usr/local/bin:$PATH + +# Install Homebrew (if not already installed) +RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" \ + && eval "$(/usr/local/bin/brew shellenv)" \ + && brew update + +# Install necessary dependencies via Homebrew +RUN brew install cmake ninja git + +# Install Qt using Homebrew +RUN brew install qt@${QT_VERSION} \ + && brew link --force qt@${QT_VERSION} + +# Set up Qt environment +RUN mkdir -p $QT_PATH \ + && ln -s /usr/local/opt/qt@${QT_VERSION} $QT_PATH/Qt + +# Configure Git to trust the project directory +RUN git config --global --add safe.directory /project/source + +# Set the working directory +WORKDIR /project/build + +# Define the build command +CMD cmake -S /project/source -B . -G Ninja -DCMAKE_BUILD_TYPE=Release && \ + cmake --build . --target all --config Release && \ + cmake --install . --config Release diff --git a/deploy/docker/Dockerfile-build-ubuntu b/deploy/docker/Dockerfile-build-ubuntu index 90eeda85a8b..76343d28684 100644 --- a/deploy/docker/Dockerfile-build-ubuntu +++ b/deploy/docker/Dockerfile-build-ubuntu @@ -24,5 +24,5 @@ RUN git config --global --add safe.directory /project/source WORKDIR /project/build CMD cmake -S /project/source -B . -G Ninja -DCMAKE_BUILD_TYPE=Release ; \ - cmake --build . --target all --config Release ; \ - cmake --install . --config Release + cmake --build . --target all --config Release ; \ + cmake --install . --config Release diff --git a/deploy/docker/run-docker-macos.sh b/deploy/docker/run-docker-macos.sh new file mode 100755 index 00000000000..22300981341 --- /dev/null +++ b/deploy/docker/run-docker-macos.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# Exit immediately if a command exits with a non-zero status +set -e + +# Build the macOS Docker-OSX image +docker build --file ./deploy/docker/Dockerfile-build-macos -t qgc-macos-docker . + +# Run the Docker-OSX container with necessary volume mounts +docker run --rm \ + --cap-add SYS_ADMIN \ + --device /dev/fuse \ + --security-opt apparmor:unconfined \ + -v "${PWD}:/project/source" \ + -v "${PWD}/build:/project/build" \ + qgc-macos-docker diff --git a/deploy/docker/run-docker-ubuntu.sh b/deploy/docker/run-docker-ubuntu.sh index 456cddcefad..d0e0e20c08e 100755 --- a/deploy/docker/run-docker-ubuntu.sh +++ b/deploy/docker/run-docker-ubuntu.sh @@ -1,8 +1,23 @@ #!/usr/bin/env bash -# Run this from root directory - +# Exit immediately if a command exits with a non-zero status set -e -docker build --file ./deploy/docker/Dockerfile-build-ubuntu -t qgc-ubuntu-docker . -docker run --cap-add SYS_ADMIN --device /dev/fuse --security-opt apparmor:unconfined --rm -v ${PWD}:/project/source -v ${PWD}/build:/project/build qgc-ubuntu-docker +# Define variables for better maintainability +DOCKERFILE_PATH="./deploy/docker/Dockerfile-build-ubuntu" +IMAGE_NAME="qgc-ubuntu-docker" +SOURCE_DIR="$(pwd)" +BUILD_DIR="${SOURCE_DIR}/build" + +# Build the Docker image +docker build --file "${DOCKERFILE_PATH}" -t "${IMAGE_NAME}" "${SOURCE_DIR}" + +# Run the Docker container with necessary permissions and volume mounts +docker run \ + --rm \ + --cap-add SYS_ADMIN \ + --device /dev/fuse \ + --security-opt apparmor:unconfined \ + -v "${SOURCE_DIR}:/project/source" \ + -v "${BUILD_DIR}:/project/build" \ + "${IMAGE_NAME}"