cmake/platforms: 对 MacOS 平台构建简单支持(CPack)

This commit is contained in:
zinface 2023-12-11 03:05:49 +08:00
parent efe773a92d
commit 98a49ef22a
7 changed files with 333 additions and 8 deletions

View File

@ -46,16 +46,15 @@ option(WINDOWS_DEPLOY_QT6 "通用 Windows 平台指定 Qt6 部署 windeployqt
option(USE_LINUX_UNIVERSAL "通用 Linux 平台构建" OFF)
option(USE_LINUX_DEBIAN "通用 Debian Linux 平台构建" OFF)
option(USE_LINUX_APPIMAGE "通用 Appimage Linux 平台构建" OFF)
#
option(USE_LINUX_UOS "独立 Linux 平台的 Uos 构建" OFF)
#
option(USE_MACOS_UNIVERSAL "通用 MacOS 平台构建" OFF)
option(USE_MACOSX_UNIVERSAL "通用 MacOSX 平台构建" OFF)
# 使 windows.cmake / linux.cmake / macos.cmake .
# Windows MinGW MSVC
if(WIN32)
# Windows
if(USE_WINDOWS_UNIVERSAL)
include(cmake/platforms/windows-universal.cmake)
@ -104,10 +103,15 @@ elseif(UNIX AND NOT APPLE AND NOT WIN32 AND NOT ANDROID)
# include(cmake/platforms/linux-other.cmake)
endif(USE_LINUX_UNIVERSAL)
# MacOS 平台的构建(一个无具体实现的空构建)
# MacOSX
elseif(APPLE)
# include(cmake/platforms/macos.cmake)
# MacOSX
if(USE_MACOSX_UNIVERSAL)
include(cmake/platforms/macos-universal.cmake)
endif(USE_MACOSX_UNIVERSAL)
endif()
# ----------------- Notepad-- 线 ----------------- #

View File

@ -39,10 +39,18 @@ if(TRUE)
target_link_qt6_Core5Compat(QSci)
target_link_qt6_PrintSupport(QSci)
target_link_qt6_Concurrent(QSci)
if(APPLE)
# Is there anything missing?
# MacExtras?
endif(APPLE)
else()
target_link_qt5(QSci)
target_link_qt5_PrintSupport(QSci)
target_link_qt5_Concurrent(QSci)
if(APPLE)
find_package(Qt5 COMPONENTS MacExtras)
target_link_libraries(QSci Qt5::MacExtras)
endif(APPLE)
endif(USE_QT6)
endif(TRUE)

View File

@ -0,0 +1,78 @@
# macos-deployqt.cmake
# NOTE:
# option(MACOSX_DEPLOY_QT "为 MacOS 中构建的应用进行 macdeployqt" OFF)
# option(MACOSX_DEPLOY_QT5 "为 MacOS 中构建的 QT5 应用进行 macdeployqt" OFF)
# option(MACOSX_DEPLOY_QT6 "为 MacOS 中构建的 QT6 应用进行 macdeployqt" OFF)
# if(USE_MACOSX_DEPLOY_QT)
# if(MACOSX_DEPLOY_QT5)
# # 使 MACOSX_DEPLOY_QT5 使 Qt5
# set(MACOSX_QT_DIR "${Qt5_DIR}")
# elseif(MACOSX_DEPLOY_QT6)
# # 使 MACOSX_DEPLOY_QT6 使 Qt6
# set(MACOSX_QT_DIR "${Qt6_DIR}")
# endif()
# if (MACOSX_DEPLOY_QT5 OR MACOSX_DEPLOY_QT6)
# if(USE_QT6)
# set(MACOSX_QT_DIR "${Qt6_DIR}")
# endif(USE_QT6)
# #/opt/homebrew/Cellar/qt@5/5.15.10_1/bin/macdeployqt
# set(MACOS_APPLICATION_DEPLOY_PATH
# ${CMAKE_BINARY_DIR}/macos-deployqt)
# set(MACOS_APPLICATION_BUNDLE_PATH
# ${MACOS_APPLICATION_DEPLOY_PATH}/${PROJECT_NAME}.app)
# # set_target_properties(${PROJECT_NAME}
# # PROPERTIES
# #
# # MACOSX_BUNDLE TRUE
# # RUNTIME_OUTPUT_DIRECTORY ${MACOS_APPLICATION_DEPLOY_PATH})
# # RUNTIME_OUTPUT_DIRECTORY ${MACOS_APPLICATION_DEPLOY_PATH}/Contents/MacOS)
# message("MACOS_QT_DIR: ${MACOS_QT_DIR}")
# # install(FILES src/mac.icns
# # DESTINATION
# # ${MACOS_APPLICATION_DEPLOY_PATH}/Contents/Resources)
# # add_custom_command(TARGET ${PROJECT_NAME}
# # #
# # POST_BUILD
# # #
# # WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
# # # COMMAND ${CMAKE_COMMAND} -E make_directory
# # # ${MACOS_APPLICATION_BUNDLE_PATH}/Contents/Resources/
# # # COMMAND ${CMAKE_COMMAND} -E copy
# # # ${CMAKE_SOURCE_DIR}/src/mac.icns
# # # ${MACOS_APPLICATION_BUNDLE_PATH}/Contents/Resources/
# # # windeployqt
# # COMMAND ${MACOS_QT_DIR}/../../../bin/macdeployqt
# # #
# # ${MACOS_APPLICATION_BUNDLE_PATH}
# # # QML-
# # #--qmlimport=${MACOS_QT_DIR}/../../../qml
# # # 部署编译器运行时(仅限桌面)
# # #--compiler-runtime
# # # 详细级别(0-2)
# # #--verbose=2
# # # 使
# # # --dir ${MACOS_APPLICATION_DEPLOY_PATH}
# # )
# if(USE_MAC_DEPLOYQT)
# include(cmake/platforms/utils.cmake)
# macdeployqt_install(${PROJECT_NAME})
# endif(USE_MAC_DEPLOYQT)
# include(CPack)
# endif(MACOSX_DEPLOY_QT5 OR MACOSX_DEPLOY_QT6)
# endif(USE_MACOSX_DEPLOY_QT)

View File

@ -1,5 +1,25 @@
# macos-universal.cmake
if(USE_MACOS_UNIVERSAL)
# MacOSX
# Notepad--
#
# Contents/ MacOSX
# MacOS/
# Notepad-- MacOSX
#
# Resources/
# ...
endif(USE_MACOS_UNIVERSAL)
if(CMAKE_HOST_APPLE)
set(CPACK_GENERATOR "Bundle")
set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
set(CPACK_BUNDLE_ICON ${CMAKE_SOURCE_DIR}/src/mac.icns)
set(CPACK_BUNDLE_PLIST ${CMAKE_SOURCE_DIR}/cmake/platforms/macos/cpack/Info.plist)
#
install(TARGETS ${PROJECT_NAME} DESTINATION ../MacOS)
# themes
install(DIRECTORY src/themes DESTINATION ../MacOS)
endif(CMAKE_HOST_APPLE)

View File

@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>Notepad--</string>
<key>CFBundleGetInfoString</key>
<string>Created by zuoweiyin</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>txt</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>txt.png</string>
<key>CFBundleTypeName</key>
<string>abc file</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSTypeIsPackage</key>
<true/>
<key>NSPersistentStoreTypeKey</key>
<string>XML</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>cpp</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>cpp.png</string>
<key>CFBundleTypeName</key>
<string>cpp file</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSTypeIsPackage</key>
<true/>
<key>NSPersistentStoreTypeKey</key>
<string>xml</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>c</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>c.png</string>
<key>CFBundleTypeName</key>
<string>c file</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSTypeIsPackage</key>
<true/>
<key>NSPersistentStoreTypeKey</key>
<string>xml</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>h</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>h.png</string>
<key>CFBundleTypeName</key>
<string>h file</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSTypeIsPackage</key>
<true/>
<key>NSPersistentStoreTypeKey</key>
<string>XML</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>html</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>html.png</string>
<key>CFBundleTypeName</key>
<string>html file</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSTypeIsPackage</key>
<true/>
<key>NSPersistentStoreTypeKey</key>
<string>XML</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>ini</string>
<string>go</string>
<string>java</string>
<string>js</string>
<string>json</string>
<string>xml</string>
<string>pro</string>
<string>pri</string>
<string>php</string>
<string>asp</string>
<string>bat</string>
<string>asm</string>
<string>html</string>
<string>yml</string>
<string>js</string>
<string>sh</string>
<string>log</string>
<string>csv</string>
<string>json</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>*.png</string>
<key>CFBundleTypeName</key>
<string>* file</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSTypeIsPackage</key>
<true/>
<key>NSPersistentStoreTypeKey</key>
<string>XML</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>html</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>html.png</string>
<key>CFBundleTypeName</key>
<string>html file</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSTypeIsPackage</key>
<true/>
<key>NSPersistentStoreTypeKey</key>
<string>XML</string>
</dict>
</array>
<key>CFBundleIconFile</key>
<string>Notepad--.icns</string>
<key>CFBundleIdentifier</key>
<string>www.itdp.cn.Notepad--</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>LSMinimumSystemVersion</key>
<string>14.1</string>
<key>NOTE</key>
<string>This file was generated by Qt/QMake.</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>NSRequiresAquaSystemAppearance</key>
<true/>
</dict>
</plist>

View File

@ -5,7 +5,7 @@
# _VAR
# _IS_IS_SHREAD
# _LIB
function(get_current_platform_lib_name _VAR _IS_SHREAD _LIB)
function(get_current_platform_lib_name _VAR _IS_SHREAD _LIB)
set(_LIB_NAME "")
if(WIN32)
set(_LIB_NAME ${_LIB}.lib)
@ -101,3 +101,37 @@ function(windeployqt_install TARGET)
"
)
endfunction(windeployqt_install TARGET)
#
# [UnTested]macdeployqt_install
# MacOSX install macdeployqt
#
function(macdeployqt_install _target)
set(MACDEPLOYQT_EXECUTABLE "${MACOS_QT_DIR}/../../../bin/macdeployqt")
#
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/${_target}_PATH"
# CONTENT "$<TARGET_FILE:${_target}>"
CONTENT "${CMAKE_BINARY_DIR}/_CPack_Packages/Darwin/Bundle/${_target}-${PROJECT_VERSION}-Darwin/${_target}.app"
)
install(CODE
"
file(READ \"${CMAKE_BINARY_DIR}/${_target}_PATH\" _file)
execute_process(
COMMAND \"${MACDEPLOYQT_EXECUTABLE}\"
# macdeployqt
--dry-run
# QML-
#--qmlimport=${MACOS_QT_DIR}/../../../qml
# 部署编译器运行时(仅限桌面)
#--compiler-runtime
# 便
#--list mapping
#-no-plugins
#-timestamp
\${_file}
OUTPUT_VARIABLE _output
OUTPUT_STRIP_TRAILING_WHITESPACE
)
"
)
endfunction(macdeployqt_install _target)

View File

@ -1,4 +1,24 @@
Msg := 'Build with the following configuration:'
One := '1. make macosx-universal'
Two := '1. make macosx-universal-release'
all:
@echo $(Msg)
@echo $(One) "\n\t默认的通用 MacOSX 平台构建(Debug)."
@echo $(Two) "\n\t默认的通用 MacOSX 平台构建(Release)."
builddir := build/macosx-universal
sourcedir := .
CMAKE_DEBUG := -DCMAKE_BUILD_TYPE=Debug
CMAKE_RELEASE := -DCMAKE_BUILD_TYPE=Release
CMAKE_OPTIONS := -DUSE_MACOSX_UNIVERSAL=ON
CPUS=8
macosx-universal:
cmake -B$(builddir) $(CMAKE_OPTIONS) $(CMAKE_DEBUG)
cmake --build $(builddir) -- -j$(CPUS)
macosx-universal-release:
cmake -B$(builddir) $(CMAKE_OPTIONS) $(CMAKE_RELEASE)
cmake --build $(builddir) -- -j$(CPUS)