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.
This commit is contained in:
Marshall Greenblatt
2025-05-13 16:51:20 -04:00
parent c302f285c7
commit 572c44bc2e
5 changed files with 98 additions and 86 deletions

View File

@ -36,11 +36,7 @@ macro(PRINT_CEF_CONFIG)
message(STATUS "CEF sandbox: ${USE_SANDBOX}") message(STATUS "CEF sandbox: ${USE_SANDBOX}")
set(_libraries ${CEF_STANDARD_LIBS}) message(STATUS "Standard 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 "Compile defines: ${CEF_COMPILER_DEFINES}") message(STATUS "Compile defines: ${CEF_COMPILER_DEFINES}")
message(STATUS "Compile defines (Debug): ${CEF_COMPILER_DEFINES_DEBUG}") message(STATUS "Compile defines (Debug): ${CEF_COMPILER_DEFINES_DEBUG}")

View File

@ -396,15 +396,6 @@ if(OS_WINDOWS)
set(CMAKE_CXX_FLAGS_RELEASE "") set(CMAKE_CXX_FLAGS_RELEASE "")
endif() 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). # 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") 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 list(APPEND CEF_LINKER_FLAGS_DEBUG
/DEBUG # Generate debug information /DEBUG # Generate debug information
) )
list(APPEND CEF_EXE_LINKER_FLAGS set(CEF_DELAYLOAD_FLAGS
/MANIFEST:NO # No default manifest (see ADD_WINDOWS_MANIFEST macro usage)
/LARGEADDRESSAWARE # Allow 32-bit processes to access 3GB of RAM
# Delayload most libraries as the dlls are simply not required at startup (or # 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 # 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 # 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:wsock32.dll
/DELAYLOAD:wtsapi32.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 list(APPEND CEF_COMPILER_DEFINES
WIN32 _WIN32 _WINDOWS # Windows platform WIN32 _WIN32 _WINDOWS # Windows platform
UNICODE _UNICODE # Unicode build UNICODE _UNICODE # Unicode build
@ -540,6 +538,7 @@ if(OS_WINDOWS)
# Standard libraries. # Standard libraries.
set(CEF_STANDARD_LIBS set(CEF_STANDARD_LIBS
comctl32.lib comctl32.lib
delayimp.lib
gdi32.lib gdi32.lib
rpcrt4.lib rpcrt4.lib
shlwapi.lib shlwapi.lib
@ -587,36 +586,8 @@ if(OS_WINDOWS)
if(USE_SANDBOX) if(USE_SANDBOX)
list(APPEND CEF_COMPILER_DEFINES list(APPEND CEF_COMPILER_DEFINES
PSAPI_VERSION=1 # Required by cef_sandbox.lib CEF_USE_BOOTSTRAP # Used by apps to test if the bootstrap is enabled
CEF_USE_SANDBOX # Used by apps to test if the sandbox 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() endif()
# Configure use of ATL. # Configure use of ATL.

View File

@ -292,11 +292,45 @@ if(OS_WINDOWS)
${CEFCLIENT_WINDOWS_SRCS} ${CEFCLIENT_WINDOWS_SRCS}
) )
# Executable target. # Additional flags not listed in CEF_DELAYLOAD_FLAGS.
add_executable(${CEF_TARGET} WIN32 ${CEFCLIENT_SRCS}) set(ADDITIONAL_DELAYLOAD_FLAGS
SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) /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 "$<TARGET_FILE_DIR:${CEF_TARGET}>/${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) 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) 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. # 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") 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) target_link_libraries(${CEF_TARGET} oleacc.lib)
endif() 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 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_BINARY_FILES}" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}")
COPY_FILES("${CEF_TARGET}" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${CEF_TARGET_OUT_DIR}") COPY_FILES("${CEF_TARGET}" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${CEF_TARGET_OUT_DIR}")

View File

@ -194,20 +194,31 @@ endif()
# #
if(OS_WINDOWS) 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) if(USE_SANDBOX)
# Logical target used to link the cef_sandbox library. # Shared library (DLL) target.
ADD_LOGICAL_TARGET("cef_sandbox_lib" "${CEF_SANDBOX_LIB_DEBUG}" "${CEF_SANDBOX_LIB_RELEASE}") add_library(${CEF_TARGET} SHARED ${CEFSIMPLE_SRCS})
target_link_libraries(${CEF_TARGET} cef_sandbox_lib ${CEF_SANDBOX_STANDARD_LIBS}) 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 "$<TARGET_FILE_DIR:${CEF_TARGET}>/${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() endif()
# Add the custom manifest files to the executable. add_dependencies(${CEF_TARGET} libcef_dll_wrapper)
ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}/win" "${CEF_TARGET}" "exe") target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS})
# Copy binary and resource files to the target output directory. # Copy 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_BINARY_FILES}" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}")

View File

@ -230,25 +230,34 @@ endif()
# #
if(OS_WINDOWS) 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) if(USE_SANDBOX)
# Logical target used to link the cef_sandbox library. # Shared library (DLL) target.
ADD_LOGICAL_TARGET("cef_sandbox_lib" "${CEF_SANDBOX_LIB_DEBUG}" "${CEF_SANDBOX_LIB_RELEASE}") add_library(${CEF_TARGET} SHARED ${UNITTESTS_SRCS} ${UNITTESTS_RESOURCES_SRCS})
target_link_libraries(${CEF_TARGET} cef_sandbox_lib ${CEF_SANDBOX_STANDARD_LIBS}) 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 "$<TARGET_FILE_DIR:${CEF_TARGET}>/${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() endif()
# Add the custom manifest files to the executable. add_dependencies(${CEF_TARGET} libcef_dll_wrapper cef_gtest)
ADD_WINDOWS_MANIFEST("${CMAKE_CURRENT_SOURCE_DIR}/win" "${CEF_TARGET}" "exe") 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 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_BINARY_FILES}" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}")