Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macos adjust cef folder #107

Merged
merged 8 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# The main config file for QCefView
#
cmake_minimum_required(VERSION 3.4.1)
cmake_minimum_required(VERSION 3.9.1)
project(QCefView)

option(BUILD_DEMO "Build the demo" OFF)
Expand Down Expand Up @@ -75,7 +75,11 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
endif()

if (BUILD_STATIC)
set(QCEFVIEW_LIB_TYPE STATIC)
add_definitions(-DQCEFVIEW_STATIC=1)
else()
set(QCEFVIEW_LIB_TYPE SHARED)
add_definitions(-DQCEFVIEW_STATIC=0)
endif ()

# Config the QT package
Expand Down Expand Up @@ -115,7 +119,9 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/$<CONFIG>/lib)
# Include CefViewCore
add_subdirectory(CefViewCore)
set_target_properties(CefViewCore PROPERTIES FOLDER core)
set_target_properties(CefViewWing PROPERTIES FOLDER core)
foreach(CefViewWingTarget ${CefViewCore_HELPER_APP_TARGETS})
set_target_properties(${CefViewWingTarget} PROPERTIES FOLDER core)
endforeach(CefViewWingTarget)
set_target_properties(libcef_dll_wrapper PROPERTIES FOLDER core)

# Config QCefView target
Expand Down
72 changes: 43 additions & 29 deletions example/QCefViewTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ if (OS_WINDOWS)

target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
QCefView
)

Expand Down Expand Up @@ -146,6 +149,9 @@ if (OS_LINUX)
# Thus, here we do a trick to make sure the load order
"-Wl,--no-as-needed $<TARGET_FILE_DIR:QCefView>/$<TARGET_FILE_NAME:libcef_lib>"

Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
QCefView
)

Expand Down Expand Up @@ -197,46 +203,61 @@ if (OS_MACOS)
${_WEB_FILES}
)

add_library(QCefViewFramework ${QCEFVIEW_LIB_TYPE} IMPORTED)
set_target_properties(QCefViewFramework
PROPERTIES
FRAMEWORK TRUE
IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/output/Release/bin/QCefView.framework"
IMPORTED_LOCATION_DEBUG "${CMAKE_BINARY_DIR}/output/Debug/bin/QCefView.framework"
IMPORTED_LOCATION_RELEASE "${CMAKE_BINARY_DIR}/output/Release/bin/QCefView.framework"
)

set_target_properties(${PROJECT_NAME}
PROPERTIES
CLANG_ENABLE_OBJC_ARC "YES"
MACOSX_BUNDLE_INFO_PLIST "${QCefViewTest_INFO_PLIST_FILE}"
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.cefview.qcefviewtest"
XCODE_LINK_BUILD_PHASE_MODE KNOWN_LOCATION
CLANG_ENABLE_OBJC_ARC "YES"
MACOSX_BUNDLE_INFO_PLIST "${QCefViewTest_INFO_PLIST_FILE}"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.cefview.qcefviewtest"
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks"

# the below two properties need CMake >= 3.20.0, we just copy the framework by post build command
# XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY "YES"
# XCODE_EMBED_FRAMEWORKS "${CMAKE_BINARY_DIR}/output/${CMAKE_BUILD_TYPE}/bin/QCefView.framework"
)

add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD

# remove the old framework from the bundle if exists
COMMAND rm -fr "$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/QCefView.framework"

# copy the latest framework to the bundle
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_BUNDLE_DIR:QCefView>"
"$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/QCefView.framework"
# remove the old framework from the bundle if exists then copy the new one
# the below tow commands can be removed if you use CMake >= 3.20.0 and set the
# following target propertis XCODE_EMBED_FRAMEWORKS, XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY
COMMAND rm -fr "$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/QCefView.framework"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_FILE:QCefViewFramework>"
"$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/QCefView.framework"

# copy the webres to the bundle
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_BINARY_DIR}/webres"
"$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Resources/webres"
# copy the webres to the bundle
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_BINARY_DIR}/webres"
"$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Resources/webres"

# deploy the Qt Application
COMMAND ${DEPLOYQT_EXECUTABLE}
"$<TARGET_BUNDLE_DIR:${PROJECT_NAME}>"
"-codesign=-"
# deploy the Qt Application, this command line will re-sign the app bundle
COMMAND ${DEPLOYQT_EXECUTABLE}
"$<TARGET_BUNDLE_DIR:${PROJECT_NAME}>"
"-codesign=-"

VERBATIM
VERBATIM
)

find_library(COCOA_FRAMEWORK Cocoa)
find_library(APPKIT_FRAMEWORK Appkit)
target_link_libraries(${PROJECT_NAME}
PRIVATE
$<TARGET_FILE:QCefView>
${COCOA_FRAMEWORK}
${APPKIT_FRAMEWORK}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
QCefViewFramework
)
endif()

Expand All @@ -248,13 +269,6 @@ set_target_properties(${PROJECT_NAME}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/$<CONFIG>/lib
)

target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
)

if (OS_MACOS)
# Copy the app to a subfoler named QCefViewTest under install dir
install(DIRECTORY "$<TARGET_BUNDLE_DIR:${PROJECT_NAME}>/" DESTINATION "${PROJECT_NAME}$<$<CONFIG:Debug>:/Debug>/${PROJECT_NAME}.app")
Expand Down
4 changes: 2 additions & 2 deletions example/QCefViewTest/mac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.cefview.qcefviewtest</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand All @@ -23,7 +23,7 @@
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2020 QCefView. All rights reserved.</string>
<string>Copyright © 2022 QCefView. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
Expand Down
Empty file modified generate-linux-x86.sh
100644 → 100755
Empty file.
Empty file modified generate-linux-x86_64.sh
100644 → 100755
Empty file.
Empty file modified generate-mac-arm64.sh
100644 → 100755
Empty file.
Empty file modified generate-mac-x86_64.sh
100644 → 100755
Empty file.
102 changes: 42 additions & 60 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,13 @@ if (OS_WINDOWS)
FILES ${QCefView_Windows_SRC_FILES}
)

if (BUILD_STATIC)
add_library(QCefView STATIC
${QCefView_INCLUDE_FILES}
${QCefView_SRC_FILES}
${QCefView_details_SRC_FILES}
${QCefView_Windows_SRC_FILES}
)
else ()
add_library(QCefView SHARED
${QCefView_INCLUDE_FILES}
${QCefView_SRC_FILES}
${QCefView_details_SRC_FILES}
${QCefView_Windows_SRC_FILES}
)
endif ()

add_library(QCefView ${QCEFVIEW_LIB_TYPE}
${QCefView_INCLUDE_FILES}
${QCefView_SRC_FILES}
${QCefView_details_SRC_FILES}
${QCefView_Windows_SRC_FILES}
)

target_compile_definitions(QCefView PRIVATE
UNICODE
Expand All @@ -77,7 +69,7 @@ if (OS_WINDOWS)
"$<TARGET_FILE_DIR:CefViewWing>"
"$<TARGET_FILE_DIR:QCefView>"

# gnerate a file contain timestamp
# gnerate a file contains timestamp
COMMAND ${CMAKE_COMMAND}
-E echo "/* Auto Build Trigger */" > "${CMAKE_BINARY_DIR}/auto_rebuild.cpp"
)
Expand All @@ -96,21 +88,12 @@ if (OS_LINUX)
FILES ${QCefView_Linux_SRC_FILES}
)

if (BUILD_STATIC)
add_library(QCefView STATIC
${QCefView_INCLUDE_FILES}
${QCefView_SRC_FILES}
${QCefView_details_SRC_FILES}
${QCefView_Linux_SRC_FILES}
)
else ()
add_library(QCefView SHARED
${QCefView_INCLUDE_FILES}
${QCefView_SRC_FILES}
${QCefView_details_SRC_FILES}
${QCefView_Linux_SRC_FILES}
)
endif ()
add_library(QCefView ${QCEFVIEW_LIB_TYPE}
${QCefView_INCLUDE_FILES}
${QCefView_SRC_FILES}
${QCefView_details_SRC_FILES}
${QCefView_Linux_SRC_FILES}
)

target_compile_definitions(QCefView
PRIVATE
Expand Down Expand Up @@ -161,53 +144,52 @@ if (OS_MACOS)
)
set(QCefView_INFO_PLIST_FILE "${CMAKE_CURRENT_LIST_DIR}/mac/Info.plist")

if (BUILD_STATIC)
add_library(QCefView STATIC
${QCefView_INCLUDE_FILES}
${QCefView_SRC_FILES}
${QCefView_details_SRC_FILES}
${QCefView_macOS_SRC_FILES}
${QCefView_INFO_PLIST_FILE}
)
else ()
add_library(QCefView SHARED
${QCefView_INCLUDE_FILES}
${QCefView_SRC_FILES}
${QCefView_details_SRC_FILES}
${QCefView_macOS_SRC_FILES}
${QCefView_INFO_PLIST_FILE}
)
endif ()

add_library(QCefView ${QCEFVIEW_LIB_TYPE}
${QCefView_INCLUDE_FILES}
${QCefView_SRC_FILES}
${QCefView_details_SRC_FILES}
${QCefView_macOS_SRC_FILES}
${QCefView_INFO_PLIST_FILE}
)

set_target_properties(QCefView
PROPERTIES
FRAMEWORK TRUE
FRAMEWORK TRUE

# compiler settings
COMPILE_FLAGS "-fobjc-arc"
CLANG_ENABLE_OBJC_ARC "YES"

# xcode settings
PUBLIC_HEADER "${QCefView_INCLUDE_HEADERS}"
MACOSX_FRAMEWORK_INFO_PLIST "${QCefView_INFO_PLIST_FILE}"
MACOSX_FRAMEWORK_IDENTIFIER "com.cefview.qcefview"
CLANG_ENABLE_OBJC_ARC "YES"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.cefview.qcefview"
XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "gnu++11" # -std=gnu++11
XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME "NO" # -fno-objc-link-runtime
XCODE_ATTRIBUTE_COPY_PHASE_STRIP "NO"
XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING[variant=Release] "YES" # -Wl,-dead_strip
XCODE_ATTRIBUTE_GCC_C_LANGUAGE_STANDARD "c99" # -std=c99
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks @loader_path/Frameworks"
)

add_custom_command(TARGET QCefView
PRE_BUILD
POST_BUILD

#copy the CefViewWing*.app to resource directory
COMMAND cp
-a
"$<TARGET_BUNDLE_DIR:CefViewWing>/../"
"$<TARGET_FILE_DIR:QCefView>/Resources/"
# create plugins directory
COMMAND mkdir -p
"$<TARGET_BUNDLE_DIR:QCefView>/PlugIns/"

#copy the CefViewCore binaries to resource directory
COMMAND cp -a
"$<TARGET_BUNDLE_DIR:CefViewWing>/../"
"$<TARGET_BUNDLE_DIR:QCefView>/PlugIns/"

#sign the cef framework
COMMAND codesign
--force
--sign -
"$<TARGET_BUNDLE_DIR:QCefView>/Resources/Chromium Embedded Framework.framework"
"$<TARGET_BUNDLE_DIR:QCefView>/PlugIns/Chromium Embedded Framework.framework"
)
endif() # OS_MACOS

Expand All @@ -227,12 +209,12 @@ add_dependencies(QCefView
)

target_link_libraries(QCefView
PRIVATE
CefViewCore
PUBLIC
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
PRIVATE
CefViewCore
)

# install QCefView files
Expand Down
4 changes: 2 additions & 2 deletions src/mac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.cefview.qcefview</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand All @@ -23,7 +23,7 @@
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2020 CefView. All rights reserved.</string>
<string>Copyright © 2022 CefView. All rights reserved.</string>
<key>LSUIElement</key>
<string>1</string>
<key>LSFileQuarantineEnabled</key>
Expand Down
4 changes: 2 additions & 2 deletions src/mac/details/QCefContextPrivate_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ + (NSString*) AppMainBundlePath {
}

+ (NSString*) CefFrameworkPath {
NSString* path = [[NSBundle bundleForClass:[PathFactory class]] resourcePath];
NSString* path = [[NSBundle bundleForClass:[PathFactory class]] builtInPlugInsPath];
path = [path stringByAppendingPathComponent:@CEF_FRAMEWORK_NAME];
return path;
}

+ (NSString*) CefSubprocessPath {
NSString* path = [[NSBundle bundleForClass:[PathFactory class]] resourcePath];
NSString* path = [[NSBundle bundleForClass:[PathFactory class]] builtInPlugInsPath];
path = [path stringByAppendingPathComponent:@HELPER_BUNDLE_NAME];
path = [path stringByAppendingPathComponent:@"Contents"];
path = [path stringByAppendingPathComponent:@"MacOS"];
Expand Down