diff --git a/CMakeLists.txt b/CMakeLists.txt index 061a303e..e28eadd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 @@ -115,7 +119,9 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/$/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 diff --git a/example/QCefViewTest/CMakeLists.txt b/example/QCefViewTest/CMakeLists.txt index 42272dc5..ddd6c506 100644 --- a/example/QCefViewTest/CMakeLists.txt +++ b/example/QCefViewTest/CMakeLists.txt @@ -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 ) @@ -146,6 +149,9 @@ if (OS_LINUX) # Thus, here we do a trick to make sure the load order "-Wl,--no-as-needed $/$" + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Widgets QCefView ) @@ -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 "$/Frameworks/QCefView.framework" - - # copy the latest framework to the bundle - COMMAND ${CMAKE_COMMAND} -E copy_directory - "$" - "$/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 "$/Frameworks/QCefView.framework" + COMMAND ${CMAKE_COMMAND} -E copy_directory + "$" + "$/Frameworks/QCefView.framework" - # copy the webres to the bundle - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${CMAKE_CURRENT_BINARY_DIR}/webres" - "$/Resources/webres" + # copy the webres to the bundle + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_BINARY_DIR}/webres" + "$/Resources/webres" - # deploy the Qt Application - COMMAND ${DEPLOYQT_EXECUTABLE} - "$" - "-codesign=-" + # deploy the Qt Application, this command line will re-sign the app bundle + COMMAND ${DEPLOYQT_EXECUTABLE} + "$" + "-codesign=-" - VERBATIM + VERBATIM ) find_library(COCOA_FRAMEWORK Cocoa) find_library(APPKIT_FRAMEWORK Appkit) target_link_libraries(${PROJECT_NAME} PRIVATE - $ ${COCOA_FRAMEWORK} ${APPKIT_FRAMEWORK} + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Widgets + QCefViewFramework ) endif() @@ -248,13 +269,6 @@ set_target_properties(${PROJECT_NAME} LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/$/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 "$/" DESTINATION "${PROJECT_NAME}$<$:/Debug>/${PROJECT_NAME}.app") diff --git a/example/QCefViewTest/mac/Info.plist b/example/QCefViewTest/mac/Info.plist index a81dac8d..32fc3017 100644 --- a/example/QCefViewTest/mac/Info.plist +++ b/example/QCefViewTest/mac/Info.plist @@ -9,7 +9,7 @@ CFBundleIconFile CFBundleIdentifier - com.cefview.qcefviewtest + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName @@ -23,7 +23,7 @@ LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright - Copyright © 2020 QCefView. All rights reserved. + Copyright © 2022 QCefView. All rights reserved. NSMainNibFile MainMenu NSPrincipalClass diff --git a/generate-linux-x86.sh b/generate-linux-x86.sh old mode 100644 new mode 100755 diff --git a/generate-linux-x86_64.sh b/generate-linux-x86_64.sh old mode 100644 new mode 100755 diff --git a/generate-mac-arm64.sh b/generate-mac-arm64.sh old mode 100644 new mode 100755 diff --git a/generate-mac-x86_64.sh b/generate-mac-x86_64.sh old mode 100644 new mode 100755 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f7085138..91cd45df 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 @@ -77,7 +69,7 @@ if (OS_WINDOWS) "$" "$" - # gnerate a file contain timestamp + # gnerate a file contains timestamp COMMAND ${CMAKE_COMMAND} -E echo "/* Auto Build Trigger */" > "${CMAKE_BINARY_DIR}/auto_rebuild.cpp" ) @@ -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 @@ -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 - "$/../" - "$/Resources/" + # create plugins directory + COMMAND mkdir -p + "$/PlugIns/" + #copy the CefViewCore binaries to resource directory + COMMAND cp -a + "$/../" + "$/PlugIns/" + #sign the cef framework COMMAND codesign --force --sign - - "$/Resources/Chromium Embedded Framework.framework" + "$/PlugIns/Chromium Embedded Framework.framework" ) endif() # OS_MACOS @@ -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 diff --git a/src/mac/Info.plist b/src/mac/Info.plist index 58cb8f7a..3df001e6 100644 --- a/src/mac/Info.plist +++ b/src/mac/Info.plist @@ -9,7 +9,7 @@ CFBundleIconFile CFBundleIdentifier - com.cefview.qcefview + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName @@ -23,7 +23,7 @@ LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright - Copyright © 2020 CefView. All rights reserved. + Copyright © 2022 CefView. All rights reserved. LSUIElement 1 LSFileQuarantineEnabled diff --git a/src/mac/details/QCefContextPrivate_mac.mm b/src/mac/details/QCefContextPrivate_mac.mm index f70483cd..62a93099 100644 --- a/src/mac/details/QCefContextPrivate_mac.mm +++ b/src/mac/details/QCefContextPrivate_mac.mm @@ -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"];