Skip to content

Commit

Permalink
Docker: Create MacOS script
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Jan 8, 2025
1 parent 7288f7b commit e568fbd
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 18 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
37 changes: 26 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -186,6 +195,7 @@ find_package(Qt6
LinguistTools
MultimediaQuickPrivate
Quick3D
Quick3DTools
SerialPort
WaylandClient
HINTS
Expand All @@ -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
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmake/Qt6QGCConfiguration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
36 changes: 36 additions & 0 deletions deploy/docker/Dockerfile-build-macos
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions deploy/docker/Dockerfile-build-ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions deploy/docker/run-docker-macos.sh
Original file line number Diff line number Diff line change
@@ -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
23 changes: 19 additions & 4 deletions deploy/docker/run-docker-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit e568fbd

Please sign in to comment.