From 572c44bc2ebdb0846f15fb96c99098009f13fec4 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 13 May 2025 16:51:20 -0400 Subject: [PATCH] cmake: win: Remove cef_sandbox.lib linking (see #3824) - Repurpose USE_SANDBOX config to enable the bootstrap. - Build appname.dll instead of appname.exe. - Copy bootstrap[c].exe to appname.exe as a post-build step. --- cmake/cef_macros.cmake.in | 6 +--- cmake/cef_variables.cmake.in | 55 ++++++++----------------------- tests/cefclient/CMakeLists.txt.in | 49 ++++++++++++++++++++------- tests/cefsimple/CMakeLists.txt.in | 33 ++++++++++++------- tests/ceftests/CMakeLists.txt.in | 41 ++++++++++++++--------- 5 files changed, 98 insertions(+), 86 deletions(-) diff --git a/cmake/cef_macros.cmake.in b/cmake/cef_macros.cmake.in index ed8f5aa34..143c4562a 100644 --- a/cmake/cef_macros.cmake.in +++ b/cmake/cef_macros.cmake.in @@ -36,11 +36,7 @@ macro(PRINT_CEF_CONFIG) message(STATUS "CEF sandbox: ${USE_SANDBOX}") - set(_libraries ${CEF_STANDARD_LIBS}) - if(OS_WINDOWS AND USE_SANDBOX) - list(APPEND _libraries ${CEF_SANDBOX_STANDARD_LIBS}) - endif() - message(STATUS "Standard libraries: ${_libraries}") + message(STATUS "Standard libraries: ${CEF_STANDARD_LIBS}") message(STATUS "Compile defines: ${CEF_COMPILER_DEFINES}") message(STATUS "Compile defines (Debug): ${CEF_COMPILER_DEFINES_DEBUG}") diff --git a/cmake/cef_variables.cmake.in b/cmake/cef_variables.cmake.in index 0a051189e..b3910747a 100644 --- a/cmake/cef_variables.cmake.in +++ b/cmake/cef_variables.cmake.in @@ -396,15 +396,6 @@ if(OS_WINDOWS) set(CMAKE_CXX_FLAGS_RELEASE "") endif() - if(USE_SANDBOX) - # Check if the current MSVC version is compatible with the cef_sandbox.lib - # static library. We require VS2015 or newer. - if(MSVC_VERSION LESS 1900) - message(WARNING "CEF sandbox is not compatible with the current MSVC version (${MSVC_VERSION})") - set(USE_SANDBOX OFF) - endif() - endif() - # Consumers who run into LNK4099 warnings can pass /Z7 instead (see issue #385). set(CEF_DEBUG_INFO_FLAG "/Zi" CACHE STRING "Optional flag specifying specific /Z flag to use") @@ -449,10 +440,7 @@ if(OS_WINDOWS) list(APPEND CEF_LINKER_FLAGS_DEBUG /DEBUG # Generate debug information ) - list(APPEND CEF_EXE_LINKER_FLAGS - /MANIFEST:NO # No default manifest (see ADD_WINDOWS_MANIFEST macro usage) - /LARGEADDRESSAWARE # Allow 32-bit processes to access 3GB of RAM - + set(CEF_DELAYLOAD_FLAGS # Delayload most libraries as the dlls are simply not required at startup (or # at all, depending on the process type). Some dlls open handles when they are # loaded, and we may not want them to be loaded in renderers or other sandboxed @@ -503,6 +491,16 @@ if(OS_WINDOWS) /DELAYLOAD:wsock32.dll /DELAYLOAD:wtsapi32.dll ) + list(APPEND CEF_EXE_LINKER_FLAGS + # For executable targets. + /MANIFEST:NO # No default manifest (see ADD_WINDOWS_MANIFEST macro usage) + /LARGEADDRESSAWARE # Allow 32-bit processes to access 3GB of RAM + ${CEF_DELAYLOAD_FLAGS} + ) + list(APPEND CEF_SHARED_LINKER_FLAGS + # For shared library targets. + ${CEF_DELAYLOAD_FLAGS} + ) list(APPEND CEF_COMPILER_DEFINES WIN32 _WIN32 _WINDOWS # Windows platform UNICODE _UNICODE # Unicode build @@ -540,6 +538,7 @@ if(OS_WINDOWS) # Standard libraries. set(CEF_STANDARD_LIBS comctl32.lib + delayimp.lib gdi32.lib rpcrt4.lib shlwapi.lib @@ -587,36 +586,8 @@ if(OS_WINDOWS) if(USE_SANDBOX) list(APPEND CEF_COMPILER_DEFINES - PSAPI_VERSION=1 # Required by cef_sandbox.lib - CEF_USE_SANDBOX # Used by apps to test if the sandbox is enabled + CEF_USE_BOOTSTRAP # Used by apps to test if the bootstrap is enabled ) - list(APPEND CEF_COMPILER_DEFINES_DEBUG - _HAS_ITERATOR_DEBUGGING=0 # Disable iterator debugging - ) - - # Libraries required by cef_sandbox.lib. - set(CEF_SANDBOX_STANDARD_LIBS - Advapi32.lib - dbghelp.lib - Delayimp.lib - ntdll.lib - OleAut32.lib - PowrProf.lib - Propsys.lib - psapi.lib - SetupAPI.lib - Shell32.lib - Shcore.lib - Userenv.lib - version.lib - wbemuuid.lib - WindowsApp.lib - winmm.lib - ) - - # CEF sandbox library paths. - set(CEF_SANDBOX_LIB_DEBUG "${CEF_BINARY_DIR_DEBUG}/cef_sandbox.lib") - set(CEF_SANDBOX_LIB_RELEASE "${CEF_BINARY_DIR_RELEASE}/cef_sandbox.lib") endif() # Configure use of ATL. diff --git a/tests/cefclient/CMakeLists.txt.in b/tests/cefclient/CMakeLists.txt.in index 6c4e19382..75951296c 100644 --- a/tests/cefclient/CMakeLists.txt.in +++ b/tests/cefclient/CMakeLists.txt.in @@ -292,11 +292,45 @@ if(OS_WINDOWS) ${CEFCLIENT_WINDOWS_SRCS} ) - # Executable target. - add_executable(${CEF_TARGET} WIN32 ${CEFCLIENT_SRCS}) - SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) + # Additional flags not listed in CEF_DELAYLOAD_FLAGS. + set(ADDITIONAL_DELAYLOAD_FLAGS + /DELAYLOAD:glu32.dll + /DELAYLOAD:oleaut32.dll + /DELAYLOAD:opengl32.dll + ) + + if(USE_SANDBOX) + # Shared library (DLL) target. + list(APPEND CEF_SHARED_LINKER_FLAGS + ${ADDITIONAL_DELAYLOAD_FLAGS} + ) + add_library(${CEF_TARGET} SHARED ${CEFCLIENT_SRCS}) + SET_LIBRARY_TARGET_PROPERTIES(${CEF_TARGET}) + + # Copy and rename the bootstrap binary. + COPY_SINGLE_FILE(${CEF_TARGET} ${CEF_BINARY_DIR}/bootstrap.exe ${CEF_TARGET_OUT_DIR}/${CEF_TARGET}.exe) + + if (CMAKE_GENERATOR MATCHES "Visual Studio") + # Make the bootstrap binary the default command for the Visual Studio debugger. + set_target_properties(${CEF_TARGET} PROPERTIES + VS_DEBUGGER_COMMAND "$/${CEF_TARGET}.exe" + ) + endif() + else() + # Executable target. + list(APPEND CEF_EXE_LINKER_FLAGS + ${ADDITIONAL_DELAYLOAD_FLAGS} + ) + add_executable(${CEF_TARGET} WIN32 ${CEFCLIENT_SRCS}) + SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) + + # Add the custom manifest files to the executable. + ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}/win" "${CEF_TARGET}" "exe") + endif() + add_dependencies(${CEF_TARGET} libcef_dll_wrapper) target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS} d3d11.lib glu32.lib imm32.lib opengl32.lib) + # Add additional /DELAYLOADs that are missing from CEF_EXE_LINKER_FLAGS. set_property(TARGET ${CEF_TARGET} PROPERTY LINK_FLAGS "/DELAYLOAD:glu32.dll /DELAYLOAD:oleaut32.dll /DELAYLOAD:opengl32.dll") @@ -305,15 +339,6 @@ if(OS_WINDOWS) target_link_libraries(${CEF_TARGET} oleacc.lib) endif() - if(USE_SANDBOX) - # Logical target used to link the cef_sandbox library. - ADD_LOGICAL_TARGET("cef_sandbox_lib" "${CEF_SANDBOX_LIB_DEBUG}" "${CEF_SANDBOX_LIB_RELEASE}") - target_link_libraries(${CEF_TARGET} cef_sandbox_lib ${CEF_SANDBOX_STANDARD_LIBS}) - endif() - - # Add the custom manifest files to the executable. - ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}/win" "${CEF_TARGET}" "exe") - # Copy CEF binary and resource files to the target output directory. COPY_FILES("${CEF_TARGET}" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}") COPY_FILES("${CEF_TARGET}" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${CEF_TARGET_OUT_DIR}") diff --git a/tests/cefsimple/CMakeLists.txt.in b/tests/cefsimple/CMakeLists.txt.in index 234ec33fc..623b50c72 100644 --- a/tests/cefsimple/CMakeLists.txt.in +++ b/tests/cefsimple/CMakeLists.txt.in @@ -194,20 +194,31 @@ endif() # if(OS_WINDOWS) - # Executable target. - add_executable(${CEF_TARGET} WIN32 ${CEFSIMPLE_SRCS}) - add_dependencies(${CEF_TARGET} libcef_dll_wrapper) - SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) - target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS}) - if(USE_SANDBOX) - # Logical target used to link the cef_sandbox library. - ADD_LOGICAL_TARGET("cef_sandbox_lib" "${CEF_SANDBOX_LIB_DEBUG}" "${CEF_SANDBOX_LIB_RELEASE}") - target_link_libraries(${CEF_TARGET} cef_sandbox_lib ${CEF_SANDBOX_STANDARD_LIBS}) + # Shared library (DLL) target. + add_library(${CEF_TARGET} SHARED ${CEFSIMPLE_SRCS}) + SET_LIBRARY_TARGET_PROPERTIES(${CEF_TARGET}) + + # Copy and rename the bootstrap binary. + COPY_SINGLE_FILE(${CEF_TARGET} ${CEF_BINARY_DIR}/bootstrap.exe ${CEF_TARGET_OUT_DIR}/${CEF_TARGET}.exe) + + if (CMAKE_GENERATOR MATCHES "Visual Studio") + # Make the bootstrap binary the default command for the Visual Studio debugger. + set_target_properties(${CEF_TARGET} PROPERTIES + VS_DEBUGGER_COMMAND "$/${CEF_TARGET}.exe" + ) + endif() + else() + # Executable target. + add_executable(${CEF_TARGET} WIN32 ${CEFSIMPLE_SRCS}) + SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) + + # Add the custom manifest files to the executable. + ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}/win" "${CEF_TARGET}" "exe") endif() - # Add the custom manifest files to the executable. - ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}/win" "${CEF_TARGET}" "exe") + add_dependencies(${CEF_TARGET} libcef_dll_wrapper) + target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS}) # Copy binary and resource files to the target output directory. COPY_FILES("${CEF_TARGET}" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}") diff --git a/tests/ceftests/CMakeLists.txt.in b/tests/ceftests/CMakeLists.txt.in index 8f1da7947..5609ce071 100644 --- a/tests/ceftests/CMakeLists.txt.in +++ b/tests/ceftests/CMakeLists.txt.in @@ -230,25 +230,34 @@ endif() # if(OS_WINDOWS) - # Executable target. - add_executable(${CEF_TARGET} WIN32 ${UNITTESTS_SRCS} ${UNITTESTS_RESOURCES_SRCS}) - add_dependencies(${CEF_TARGET} libcef_dll_wrapper cef_gtest) - - list(APPEND CEF_EXE_LINKER_FLAGS - /SUBSYSTEM:CONSOLE # Configure as a console application. - ) - - SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) - target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper cef_gtest ${CEF_STANDARD_LIBS}) - if(USE_SANDBOX) - # Logical target used to link the cef_sandbox library. - ADD_LOGICAL_TARGET("cef_sandbox_lib" "${CEF_SANDBOX_LIB_DEBUG}" "${CEF_SANDBOX_LIB_RELEASE}") - target_link_libraries(${CEF_TARGET} cef_sandbox_lib ${CEF_SANDBOX_STANDARD_LIBS}) + # Shared library (DLL) target. + add_library(${CEF_TARGET} SHARED ${UNITTESTS_SRCS} ${UNITTESTS_RESOURCES_SRCS}) + SET_LIBRARY_TARGET_PROPERTIES(${CEF_TARGET}) + + # Copy and rename the bootstrap binary. + COPY_SINGLE_FILE(${CEF_TARGET} ${CEF_BINARY_DIR}/bootstrapc.exe ${CEF_TARGET_OUT_DIR}/${CEF_TARGET}.exe) + + if (CMAKE_GENERATOR MATCHES "Visual Studio") + # Make the bootstrap binary the default command for the Visual Studio debugger. + set_target_properties(${CEF_TARGET} PROPERTIES + VS_DEBUGGER_COMMAND "$/${CEF_TARGET}.exe" + ) + endif() + else() + # Executable target. + list(APPEND CEF_EXE_LINKER_FLAGS + /SUBSYSTEM:CONSOLE # Configure as a console application. + ) + add_executable(${CEF_TARGET} WIN32 ${UNITTESTS_SRCS} ${UNITTESTS_RESOURCES_SRCS}) + SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) + + # Add the custom manifest files to the executable. + ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}/win" "${CEF_TARGET}" "exe") endif() - # Add the custom manifest files to the executable. - ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}/win" "${CEF_TARGET}" "exe") + add_dependencies(${CEF_TARGET} libcef_dll_wrapper cef_gtest) + target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper cef_gtest ${CEF_STANDARD_LIBS}) # Copy CEF binary and resource files to the target output directory. COPY_FILES("${CEF_TARGET}" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}")