diff --git a/CMakeLists.txt b/CMakeLists.txt index 0196c8b..6165e94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,21 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/$/ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/$/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/$/lib) +# set CefView Helper Process Name +if(NOT CEFVIEW_WING_NAME) + set(DEFAULT_CEFVIEW_WING_NAME "CefViewWing") + message(STATUS + "CEFVIEW_WING_NAME is empty, use default version ${DEFAULT_CEFVIEW_WING_NAME}\n" + "You can change the name by adding -DCEFVIEW_WING_NAME=xxx to commandline for generation") + set(CEFVIEW_WING_NAME ${DEFAULT_CEFVIEW_WING_NAME} CACHE STRING "CefViewWing Helper Process Name" FORCE) +endif() + +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/include/CefViewWingProcessName.h.in" + "${CMAKE_CURRENT_SOURCE_DIR}/include/CefViewWingProcessName.h" + @ONLY +) + # Config the CEF # ############################################################## message(STATUS "Detecting CEF_SDK_VERSION: ${CEF_SDK_VERSION}") @@ -96,7 +111,7 @@ if(NOT CEF_SDK_VERSION) message(STATUS "CEF_SDK_VERSION is empty, use default version ${DEFAULT_CEF_SDK_VER}\n" "You can change the version by adding -DCEF_SDK_VERSION=xxx to commandline for generation") - set(CEF_SDK_VERSION ${DEFAULT_CEF_SDK_VER} CACHE STRING " Cef binary SDK version " FORCE) + set(CEF_SDK_VERSION ${DEFAULT_CEF_SDK_VER} CACHE STRING "Cef binary SDK version" FORCE) endif() include(DownloadCef) @@ -171,14 +186,15 @@ endif() add_subdirectory(src) if(OS_MACOS) - set(CefViewCore_HELPER_TARGETS "CefViewWing;CefViewWing_gpu;CefViewWing_plugin;CefViewWing_renderer") + set(CefViewCore_HELPER_TARGETS "${CEFVIEW_WING_NAME};${CEFVIEW_WING_NAME}_gpu;${CEFVIEW_WING_NAME}_plugin;${CEFVIEW_WING_NAME}_renderer") else() - set(CefViewCore_HELPER_TARGETS "CefViewWing") + set(CefViewCore_HELPER_TARGETS "${CEFVIEW_WING_NAME}") endif() get_directory_property(IS_CURRENT_IN_SUBDIRECTORY PARENT_DIRECTORY) if(IS_CURRENT_IN_SUBDIRECTORY) + set(CEFVIEW_WING_NAME ${CEFVIEW_WING_NAME} PARENT_SCOPE) set(CefViewCore_EXPORT_INCLUDE_PATH ${CefViewCore_INCLUDE_PATH} PARENT_SCOPE) set(CefViewCore_HELPER_APP_TARGETS ${CefViewCore_HELPER_TARGETS} PARENT_SCOPE) set(CefViewCore_CEF_BINARY_DIR ${CEF_BINARY_DIR} PARENT_SCOPE) diff --git a/include/CefViewCoreProtocol.h b/include/CefViewCoreProtocol.h index e25f9b6..73a9d24 100644 --- a/include/CefViewCoreProtocol.h +++ b/include/CefViewCoreProtocol.h @@ -84,11 +84,6 @@ /// #define kCefViewReportJSResultFunctionName "__cefview_report_js_result__" -/// -/// -/// -#define kCefViewRenderProcessName "CefViewWing" - /// /// /// diff --git a/include/CefViewWingProcessName.h b/include/CefViewWingProcessName.h new file mode 100644 index 0000000..aece6ef --- /dev/null +++ b/include/CefViewWingProcessName.h @@ -0,0 +1,12 @@ +#ifndef CefViewWingProcessName_h +#define CefViewWingProcessName_h +#pragma once + +/* clang-format off */ +/// +/// CefView Helper Process Name +/// +#define kCefViewRenderProcessName "XXXefHelper" +/* clang-format on */ + +#endif diff --git a/include/CefViewWingProcessName.h.in b/include/CefViewWingProcessName.h.in new file mode 100644 index 0000000..f0bddfe --- /dev/null +++ b/include/CefViewWingProcessName.h.in @@ -0,0 +1,19 @@ +/* + * File: CefViewWingProcessName.h.in + * Project: include + * Created: 23rd November 2023 + * Author: Sheen Tian + * This file was generated by CMake, do not modify this manually + */ +#ifndef CefViewWingProcessName_h +#define CefViewWingProcessName_h +#pragma once + +/* clang-format off */ +/// +/// CefView Helper Process Name +/// +#define kCefViewRenderProcessName "@CEFVIEW_WING_NAME@" +/* clang-format on */ + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3150cdf..24704c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,13 +3,13 @@ file(GLOB_RECURSE CefViewCore_SHARED_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Shared/*.h" ) source_group( - TREE "${CMAKE_CURRENT_SOURCE_DIR}/Shared" + TREE "${CMAKE_CURRENT_SOURCE_DIR}/Shared" PREFIX Shared FILES ${CefViewCore_SHARED_SRC_FILES} ) -### CefViewCore -################################################################################################ +# ## CefViewCore +# ############################################################################################### # header files file(GLOB_RECURSE CefViewCore_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/../include/*.h" @@ -41,22 +41,21 @@ target_include_directories(CefViewCore PRIVATE ${CefViewCore_INCLUDE_PATH} ) -# ADD_LOGICAL_TARGET(libcef_lib -# "${CEF_LIB_DEBUG}" -# "${CEF_LIB_RELEASE}" +# ADD_LOGICAL_TARGET(libcef_lib +# "${CEF_LIB_DEBUG}" +# "${CEF_LIB_RELEASE}" # ) - add_library(libcef_lib ${CEF_LIBTYPE} IMPORTED GLOBAL) -set_target_properties(libcef_lib +set_target_properties(libcef_lib PROPERTIES - IMPORTED_LOCATION "${CEF_LIB_RELEASE}" - IMPORTED_LOCATION_DEBUG "${CEF_LIB_DEBUG}" - IMPORTED_LOCATION_RELEASE "${CEF_LIB_RELEASE}" + IMPORTED_LOCATION "${CEF_LIB_RELEASE}" + IMPORTED_LOCATION_DEBUG "${CEF_LIB_DEBUG}" + IMPORTED_LOCATION_RELEASE "${CEF_LIB_RELEASE}" ) -if (OS_WINDOWS) +if(OS_WINDOWS) SET_LIBRARY_TARGET_PROPERTIES(CefViewCore) - + add_dependencies(CefViewCore libcef_lib libcef_dll_wrapper @@ -64,7 +63,7 @@ if (OS_WINDOWS) set(CefViewCore_LIBS libcef_lib - libcef_dll_wrapper + libcef_dll_wrapper ${CEF_STANDARD_LIBS} ) @@ -72,13 +71,13 @@ if (OS_WINDOWS) list(APPEND CefViewCore_LIBS cef_sandbox_lib) endif() - target_link_libraries(CefViewCore + target_link_libraries(CefViewCore PUBLIC - ${CefViewCore_LIBS} + ${CefViewCore_LIBS} ) endif() # OS_WINDOWS -if (OS_LINUX) +if(OS_LINUX) SET_LIBRARY_TARGET_PROPERTIES(CefViewCore) add_dependencies(CefViewCore @@ -88,40 +87,40 @@ if (OS_LINUX) set(CefViewCore_LIBS libcef_lib - libcef_dll_wrapper + libcef_dll_wrapper ${CEF_STANDARD_LIBS} ) - - target_link_libraries(CefViewCore + + target_link_libraries(CefViewCore PUBLIC - ${CefViewCore_LIBS} + ${CefViewCore_LIBS} ) endif() # OS_LINUX -if (OS_MACOS) +if(OS_MACOS) file(GLOB_RECURSE CefViewCore_PUBLIC_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/../include/*.h" ) target_compile_options(CefViewCore PRIVATE - "-fobjc-arc" + "-fobjc-arc" ) - + SET_LIBRARY_TARGET_PROPERTIES(CefViewCore) set_target_properties(CefViewCore PROPERTIES - FRAMEWORK TRUE - PUBLIC_HEADER "${CefViewCore_PUBLIC_HEADERS}" - CLANG_ENABLE_OBJC_ARC "YES" - APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc" - 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_PRODUCT_BUNDLE_IDENTIFIER "com.cefview.cefview" + FRAMEWORK TRUE + PUBLIC_HEADER "${CefViewCore_PUBLIC_HEADERS}" + CLANG_ENABLE_OBJC_ARC "YES" + APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc" + 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_PRODUCT_BUNDLE_IDENTIFIER "com.cefview.cefview" ) add_dependencies(CefViewCore @@ -129,7 +128,7 @@ if (OS_MACOS) ) set(CefViewCore_LIBS - libcef_dll_wrapper + libcef_dll_wrapper ${CEF_STANDARD_LIBS} ) @@ -139,12 +138,12 @@ if (OS_MACOS) target_link_libraries(CefViewCore PUBLIC - ${CefViewCore_LIBS} + ${CefViewCore_LIBS} ) endif() # OS_MACOS -### CefViewWing -################################################################################################ +# ## CefViewWing +# ############################################################################################### # soruce code for all platforms file(GLOB_RECURSE CefViewWing_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/CefRenderApp/*.h" @@ -152,11 +151,11 @@ file(GLOB_RECURSE CefViewWing_SRC_FILES ) source_group( TREE "${CMAKE_CURRENT_SOURCE_DIR}/CefWing" - PREFIX Source + PREFIX Source FILES ${CefViewWing_SRC_FILES} ) -if (OS_WINDOWS) +if(OS_WINDOWS) file(GLOB_RECURSE CefViewWing_PLATFORM_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/win/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/win/*.cpp" @@ -168,36 +167,36 @@ if (OS_WINDOWS) ) # Create Helper executable target. - add_executable(CefViewWing WIN32 + add_executable(${CEFVIEW_WING_NAME} WIN32 ${CefViewCore_SHARED_SRC_FILES} ${CefViewWing_SRC_FILES} ${CefViewWing_PLATFORM_SRC_FILES} ) - SET_EXECUTABLE_TARGET_PROPERTIES(CefViewWing) - target_link_options(CefViewWing + SET_EXECUTABLE_TARGET_PROPERTIES(${CEFVIEW_WING_NAME}) + target_link_options(${CEFVIEW_WING_NAME} PRIVATE - "/MANIFEST" + "/MANIFEST" ) - target_include_directories(CefViewWing + target_include_directories(${CEFVIEW_WING_NAME} PRIVATE - ${CefViewCore_INCLUDE_PATH} + ${CefViewCore_INCLUDE_PATH} ) - add_dependencies(CefViewWing + add_dependencies(${CEFVIEW_WING_NAME} libcef_lib libcef_dll_wrapper ) set(_helper_libs d3d11.lib - glu32.lib - imm32.lib + glu32.lib + imm32.lib opengl32.lib libcef_lib - libcef_dll_wrapper + libcef_dll_wrapper ${CEF_STANDARD_LIBS} ${CEF_SANDBOX_STANDARD_LIBS} ) @@ -206,40 +205,40 @@ if (OS_WINDOWS) list(APPEND _helper_libs cef_sandbox_lib) endif() - target_link_libraries(CefViewWing + target_link_libraries(${CEFVIEW_WING_NAME} ${_helper_libs} ) # Add the Helper as a dependency of the main executable target. - add_dependencies(CefViewCore CefViewWing) + add_dependencies(CefViewCore ${CEFVIEW_WING_NAME}) - add_custom_command(TARGET CefViewWing + add_custom_command(TARGET ${CEFVIEW_WING_NAME} POST_BUILD # embed the manifest file - COMMAND mt.exe - -manifest \"${CMAKE_CURRENT_SOURCE_DIR}\\CefWing\\win\\CefViewWing.manifest\" - -outputresource:\"$\" + COMMAND mt.exe + -manifest \"${CMAKE_CURRENT_SOURCE_DIR}\\CefWing\\win\\CefViewWing.manifest\" + -outputresource:\"$\" # copy cef binary files - #.1 copy the cef resources to output dir - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${CEF_RESOURCE_DIR}" - "$/resources" - - #.2 move the icudtl.dat to root of output dir - COMMAND ${CMAKE_COMMAND} -E rename - "$/resources/icudtl.dat" - "$/icudtl.dat" - - #.3 copy all cef binary files to output dir - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${CEF_BINARY_DIR}" - "$" - ) -endif() # OS_WINDOWS - -if (OS_LINUX) + # .1 copy the cef resources to output dir + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CEF_RESOURCE_DIR}" + "$/resources" + + # .2 move the icudtl.dat to root of output dir + COMMAND ${CMAKE_COMMAND} -E rename + "$/resources/icudtl.dat" + "$/icudtl.dat" + + # .3 copy all cef binary files to output dir + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CEF_BINARY_DIR}" + "$" + ) +endif() # OS_WINDOWS + +if(OS_LINUX) file(GLOB_RECURSE CefViewWing_PLATFORM_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/linux/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/linux/*.cpp" @@ -251,67 +250,67 @@ if (OS_LINUX) ) # Create Helper executable target. - add_executable(CefViewWing + add_executable(${CEFVIEW_WING_NAME} ${CefViewCore_SHARED_SRC_FILES} ${CefViewWing_SRC_FILES} ${CefViewWing_PLATFORM_SRC_FILES} ) - SET_EXECUTABLE_TARGET_PROPERTIES(CefViewWing) + SET_EXECUTABLE_TARGET_PROPERTIES(${CEFVIEW_WING_NAME}) - set_target_properties(CefViewWing - PROPERTIES - INSTALL_RPATH "$ORIGIN" - BUILD_WITH_INSTALL_RPATH TRUE + set_target_properties(${CEFVIEW_WING_NAME} + PROPERTIES + INSTALL_RPATH "$ORIGIN" + BUILD_WITH_INSTALL_RPATH TRUE ) - target_include_directories(CefViewWing PRIVATE + target_include_directories(${CEFVIEW_WING_NAME} PRIVATE ${CefViewCore_INCLUDE_PATH} ) - add_dependencies(CefViewWing + add_dependencies(${CEFVIEW_WING_NAME} libcef_lib libcef_dll_wrapper ) set(_helper_libs libcef_lib - libcef_dll_wrapper + libcef_dll_wrapper ${CEF_STANDARD_LIBS} ) - target_link_libraries(CefViewWing + target_link_libraries(${CEFVIEW_WING_NAME} ${_helper_libs} ) # Add the Helper as a dependency of the main executable target. - add_dependencies(CefViewCore CefViewWing) + add_dependencies(CefViewCore ${CEFVIEW_WING_NAME}) # copy cef binary files - add_custom_command(TARGET CefViewWing + add_custom_command(TARGET ${CEFVIEW_WING_NAME} POST_BUILD # copy cef binary files - #.1 copy the cef resources to output dir - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${CEF_RESOURCE_DIR}" - "$/resources" - - #.2 move the icudtl.dat to root of output dir - COMMAND ${CMAKE_COMMAND} -E rename - "$/resources/icudtl.dat" - "$/icudtl.dat" - - #.3 copy all cef binary files to output dir - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${CEF_BINARY_DIR}" - "$" - ) - - SET_LINUX_SUID_PERMISSIONS(CefViewWing "$/chrome-sandbox") -endif() # OS_LINUX - -if (OS_MACOS) + # .1 copy the cef resources to output dir + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CEF_RESOURCE_DIR}" + "$/resources" + + # .2 move the icudtl.dat to root of output dir + COMMAND ${CMAKE_COMMAND} -E rename + "$/resources/icudtl.dat" + "$/icudtl.dat" + + # .3 copy all cef binary files to output dir + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CEF_BINARY_DIR}" + "$" + ) + + SET_LINUX_SUID_PERMISSIONS(${CEFVIEW_WING_NAME} "$/chrome-sandbox") +endif() # OS_LINUX + +if(OS_MACOS) file(GLOB_RECURSE CefViewWing_PLATFORM_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/mac/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/mac/*.m" @@ -325,10 +324,10 @@ if (OS_MACOS) ) set(CefViewWing_LIBS - libcef_dll_wrapper + libcef_dll_wrapper ${CEF_STANDARD_LIBS} ) - + if(USE_SANDBOX) list(APPEND CefViewWing_LIBS cef_sandbox_lib) endif() @@ -342,16 +341,16 @@ if (OS_MACOS) list(GET _suffix_list 2 _plist_suffix) # Define Helper target and output names. - set(_helper_target "CefViewWing${_target_suffix}") - set(_helper_output_name "CefViewWing${_name_suffix}") + set(_helper_target "${CEFVIEW_WING_NAME}${_target_suffix}") + set(_helper_output_name "${CEFVIEW_WING_NAME}${_name_suffix}") # Create Helper executable target. - add_executable(${_helper_target} MACOSX_BUNDLE + add_executable(${_helper_target} MACOSX_BUNDLE ${CefViewCore_SHARED_SRC_FILES} ${CefViewWing_SRC_FILES} ${CefViewWing_PLATFORM_SRC_FILES} ) - SET_EXECUTABLE_TARGET_PROPERTIES(${_helper_target} ) + SET_EXECUTABLE_TARGET_PROPERTIES(${_helper_target}) set(_helper_info_plist "${CMAKE_CURRENT_BINARY_DIR}/helper-Info${_target_suffix}.plist") file(READ "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/mac/info.plist" _plist_contents) @@ -359,23 +358,23 @@ if (OS_MACOS) set_target_properties(${_helper_target} PROPERTIES - CLANG_ENABLE_OBJC_ARC "YES" - OUTPUT_NAME "${_helper_output_name}" - MACOSX_BUNDLE_INFO_PLIST "${_helper_info_plist}" - XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.cefview.cefviewwing${_plist_suffix}" - XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES" - XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/mac/CefViewWing.entitlements" + CLANG_ENABLE_OBJC_ARC "YES" + OUTPUT_NAME "${_helper_output_name}" + MACOSX_BUNDLE_INFO_PLIST "${_helper_info_plist}" + XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.cefview.${CEFVIEW_WING_NAME}${_plist_suffix}" + XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES" + XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/CefWing/mac/CefViewWing.entitlements" ) - target_include_directories(${_helper_target} PRIVATE + target_include_directories(${_helper_target} PRIVATE ${CefViewCore_INCLUDE_PATH} ) - add_dependencies(${_helper_target} + add_dependencies(${_helper_target} libcef_dll_wrapper ) - target_link_libraries(${_helper_target} + target_link_libraries(${_helper_target} ${CefViewWing_LIBS} ) @@ -384,13 +383,13 @@ if (OS_MACOS) endforeach() # copy cef binary files to the output folder - add_custom_command(TARGET CefViewWing + add_custom_command(TARGET ${CEFVIEW_WING_NAME} POST_BUILD - #copy the cef framework to output directory - COMMAND ${CMAKE_COMMAND} -E copy_directory - "${CEF_BINARY_DIR}/Chromium Embedded Framework.framework" - "$/../Chromium Embedded Framework.framework" + # copy the cef framework to output directory + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CEF_BINARY_DIR}/Chromium Embedded Framework.framework" + "$/../Chromium Embedded Framework.framework" VERBATIM ) endif() # OS_MACOS