Skip to content
Permalink
Browse files

Convert CEF CMake to library.

  • Loading branch information...
andreduvoisin committed Mar 20, 2019
1 parent cadd303 commit c0f74d898d89a57416cb08551e6e0537c808fd35
Showing with 127 additions and 126 deletions.
  1. +115 −108 cmake/CEF.cmake
  2. +1 −9 engine/CMakeLists.txt
  3. +1 −1 engine/main/Main.cpp
  4. +0 −2 extern/CMakeLists.txt
  5. +10 −6 ui/CMakeLists.txt
@@ -1,3 +1,5 @@
include(ExternalProject)

cmake_policy(SET CMP0074 NEW)
if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
@@ -35,119 +37,124 @@ endif()
# CMake Reference:
# https://bitbucket.org/chromiumembedded/cef-project/src/master/CMakeLists.txt
# https://bitbucket.org/chromiumembedded/cef/src/master/CMakeLists.txt.in
function(BuildCEF)
if(OS_WINDOWS)
set(BUILD_BYPRODUCTS
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.dll"
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.lib"
"${CEF_ROOT}/${CEF_CONFIGURATION}/libcef.lib"
)
elseif(OS_MACOSX)
set(BUILD_BYPRODUCTS
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.a"
"${CEF_ROOT}/${CEF_CONFIGURATION}/Chromium Embedded Framework.framework"
)
endif()

ExternalProject_Add(
CEF
PREFIX ${CEF_DISTRIBUTION}

DOWNLOAD_DIR ${EXTERN_DIR}
URL "http://opensource.spotify.com/cefbuilds/${CEF_DISTRIBUTION}.tar.bz2"

SOURCE_DIR ${CEF_ROOT}
BINARY_DIR ${CEF_ROOT}

# Custom configuration for Composite Engine.
#
# Linking Reference: https://bitbucket.org/chromiumembedded/cef/wiki/LinkingDifferentRunTimeLibraries.md
# opengl32.lib (and glu32.lib) link with /MD, so we can't link with /MT.
# /MD[d] is included in CMAKE_CXX_FLAGS[_*] by default.
# Also, to maintain our sanity, we would like to avoid having to build Chromium and CEF.
#
# Sandbox Reference: https://magpcss.org/ceforum/viewtopic.php?f=6&t=15482
CMAKE_ARGS
-DCMAKE_MAKE_PROGRAM=ninja
-DCEF_RUNTIME_LIBRARY_FLAG=/MD
-DUSE_SANDBOX=OFF

BUILD_COMMAND ninja
INSTALL_COMMAND ""

BUILD_BYPRODUCTS ${BUILD_BYPRODUCTS}
if(OS_WINDOWS)
set(BUILD_BYPRODUCTS
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.dll"
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.lib"
"${CEF_ROOT}/${CEF_CONFIGURATION}/libcef.lib"
)
endfunction()
elseif(OS_MACOSX)
set(BUILD_BYPRODUCTS
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.a"
"${CEF_ROOT}/${CEF_CONFIGURATION}/Chromium Embedded Framework.framework"
)
endif()

ExternalProject_Add(
CEFExternal
PREFIX ${CEF_DISTRIBUTION}

function(BootstrapCEF TARGET_NAME EXECUTABLE_SUBDIR)
IncludeCEF()
LinkCEF(${TARGET_NAME})
CopyCEFFiles(${TARGET_NAME} ${EXECUTABLE_SUBDIR})
endfunction()
DOWNLOAD_DIR ${EXTERN_DIR}
URL "http://opensource.spotify.com/cefbuilds/${CEF_DISTRIBUTION}.tar.bz2"

function(IncludeCEF)
include_directories(${CEF_ROOT})
endfunction()
SOURCE_DIR ${CEF_ROOT}
BINARY_DIR ${CEF_ROOT}

# Custom configuration for Composite Engine.
#
# Linking Reference: https://bitbucket.org/chromiumembedded/cef/wiki/LinkingDifferentRunTimeLibraries.md
# opengl32.lib (and glu32.lib) link with /MD, so we can't link with /MT.
# /MD[d] is included in CMAKE_CXX_FLAGS[_*] by default.
# Also, to maintain our sanity, we would like to avoid having to build Chromium and CEF.
#
# Sandbox Reference: https://magpcss.org/ceforum/viewtopic.php?f=6&t=15482
CMAKE_ARGS
-DCMAKE_MAKE_PROGRAM=ninja
-DCEF_RUNTIME_LIBRARY_FLAG=/MD
-DUSE_SANDBOX=OFF

BUILD_COMMAND ninja
INSTALL_COMMAND ""

BUILD_BYPRODUCTS ${BUILD_BYPRODUCTS}
)

add_library(CEF INTERFACE)
add_dependencies(CEF CEFExternal)

target_include_directories(CEF INTERFACE ${CEF_ROOT})

# Reference: https://bitbucket.org/chromiumembedded/cef/wiki/LinkingDifferentRunTimeLibraries.md
# Sandbox support (linking cef_sandbox.lib) is only possible when your application is built with the /MT flag.
function(LinkCEF TARGET_NAME)
if(OS_WINDOWS)
set(LIBRARIES
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.lib"
"${CEF_ROOT}/${CEF_CONFIGURATION}/libcef.lib"
)
#set(LIBRARIES ${LIBRARIES} "${CEF_ROOT}/${CEF_CONFIGURATION}/cef_sandbox.lib")
elseif(OS_MACOSX)
set(LIBRARIES
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.a"
"${CEF_ROOT}/${CEF_CONFIGURATION}/Chromium Embedded Framework.framework"
)
#set(LIBRARIES ${LIBRARIES} "${CEF_ROOT}/${CEF_CONFIGURATION}/cef_sandbox.a")
endif()
if(OS_WINDOWS)
set(LIBRARIES
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.lib"
"${CEF_ROOT}/${CEF_CONFIGURATION}/libcef.lib"
)
#set(LIBRARIES ${LIBRARIES} "${CEF_ROOT}/${CEF_CONFIGURATION}/cef_sandbox.lib")
elseif(OS_MACOSX)
set(LIBRARIES
"${CEF_ROOT}/libcef_dll_wrapper/libcef_dll_wrapper.a"
"${CEF_ROOT}/${CEF_CONFIGURATION}/Chromium Embedded Framework.framework"
)
#set(LIBRARIES ${LIBRARIES} "${CEF_ROOT}/${CEF_CONFIGURATION}/cef_sandbox.a")
endif()

target_link_libraries(CEF INTERFACE ${LIBRARIES})

target_link_libraries(${TARGET_NAME} PRIVATE ${LIBRARIES})
endfunction()

function(CopyCEFFiles TARGET_NAME EXECUTABLE_SUBDIR)
if(OS_WINDOWS)
# TODO: As far as I know, the *.lib files from this copy are unnecessary,
# which means this should be changed to only copy *.dll and *.bin files.
# However, the CEF README.txt implies that the whole directory should be copied.
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CEF_ROOT}/${CEF_CONFIGURATION}"
"${PROJECT_BINARY_DIR}/${EXECUTABLE_SUBDIR}/${CE_CONFIGURATION}"
VERBATIM
)
if(OS_WINDOWS)
# TODO: As far as I know, the *.lib files from this copy are unnecessary,
# which means this should be changed to only copy *.dll and *.bin files.
# However, the CEF README.txt implies that the whole directory should be copied.
#add_custom_command(
# TARGET ${TARGET_NAME}
# POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# "${CEF_ROOT}/${CEF_CONFIGURATION}"
# "${PROJECT_BINARY_DIR}/${EXECUTABLE_SUBDIR}/${CE_CONFIGURATION}"
# VERBATIM
#)

add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CEF_ROOT}/Resources"
"${PROJECT_BINARY_DIR}/${EXECUTABLE_SUBDIR}/${CE_CONFIGURATION}"
VERBATIM
)
elseif(OS_MACOSX)
# TODO: This should use EXECUTABLE_SUBDIR, and only one of these two should exist.
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CEF_ROOT}/${CEF_CONFIGURATION}/Chromium Embedded Framework.framework"
"${PROJECT_BINARY_DIR}/engine/${CE_CONFIGURATION}/CompositeEngine.app/Contents/Frameworks/Chromium Embedded Framework.framework"
VERBATIM
)
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CEF_ROOT}/${CEF_CONFIGURATION}/Chromium Embedded Framework.framework"
"${PROJECT_BINARY_DIR}/ui/${CE_CONFIGURATION}/CompositeCefSubprocess.app/Contents/Frameworks/Chromium Embedded Framework.framework"
VERBATIM
)
endif()
endfunction()
#add_custom_command(
# TARGET ${TARGET_NAME}
# POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy_directory
# "${CEF_ROOT}/Resources"
# "${PROJECT_BINARY_DIR}/${EXECUTABLE_SUBDIR}/${CE_CONFIGURATION}"
# VERBATIM
#)

# The trailing slashes are important.
# Reference: https://cmake.org/cmake/help/v3.12/command/install.html#installing-directories
# "The last component of each directory name is appended to the destination directory but
# a trailing slash may be used to avoid this because it leaves the last component empty."
install(
DIRECTORY "${CEF_ROOT}/${CEF_CONFIGURATION}/"
DESTINATION "${CMAKE_INSTALL_PREFIX}"
FILES_MATCHING
PATTERN "*.dll"
PATTERN "*.bin"
)
install(
DIRECTORY "${CEF_ROOT}/Resources/"
DESTINATION "${CMAKE_INSTALL_PREFIX}"
)
elseif(OS_MACOSX)
# TODO: This should use EXECUTABLE_SUBDIR, and only one of these two should exist.
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CEF_ROOT}/${CEF_CONFIGURATION}/Chromium Embedded Framework.framework"
"${PROJECT_BINARY_DIR}/engine/${CE_CONFIGURATION}/CompositeEngine.app/Contents/Frameworks/Chromium Embedded Framework.framework"
VERBATIM
)
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CEF_ROOT}/${CEF_CONFIGURATION}/Chromium Embedded Framework.framework"
"${PROJECT_BINARY_DIR}/ui/${CE_CONFIGURATION}/CompositeCefSubprocess.app/Contents/Frameworks/Chromium Embedded Framework.framework"
VERBATIM
)
endif()
@@ -1,4 +1,3 @@
include("${CMAKE_DIR}/CEF.cmake")

if(OS_MACOSX)
set(COMPOSITE_ENGINE_EXECUTABLE_ARGS MACOSX_BUNDLE)
@@ -21,14 +20,9 @@ add_executable(CompositeEngine ${COMPOSITE_ENGINE_EXECUTABLE_ARGS} ${ENGINE_SRC_
add_dependencies(
CompositeEngine
CompositeCefSubprocess
CEF
#GLEW
#GLM
#RapidJSON
#SDL
)

target_link_libraries(CompositeEngine PRIVATE GLEW GLM OpenGL RapidJSON SDL)
target_link_libraries(CompositeEngine PRIVATE CEF GLEW GLM OpenGL RapidJSON SDL)

source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${ENGINE_SRC_FILES})

@@ -43,8 +37,6 @@ if(WIN32)
#target_link_libraries(CompositeEngine -manifest:embed -manifestinput:"${ENGINE_SRC_DIR}/CompositeEngine.manifest")
endif()

BootstrapCEF(CompositeEngine "engine")

install(
TARGETS CompositeEngine
RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
@@ -805,7 +805,7 @@ bool StartCef()
settings.external_message_pump = true;
settings.windowless_rendering_enabled = true;
settings.remote_debugging_port = 3469;
CefString(&settings.browser_subprocess_path).FromASCII("../../ui/Debug/CompositeCefSubprocess.exe");
CefString(&settings.browser_subprocess_path).FromASCII("CompositeCefSubprocess.exe");
if (!CefInitialize(main_args, settings, app, NULL))
{
printf("CEF failed to initialize.\n");
@@ -6,5 +6,3 @@ include("${CMAKE_DIR}/OpenGL.cmake")
include("${CMAKE_DIR}/RapidJSON.cmake")
include("${CMAKE_DIR}/SDL.cmake")
include("${CMAKE_DIR}/STB.cmake")

BuildCEF()
@@ -1,4 +1,3 @@
include("${CMAKE_DIR}/CEF.cmake")

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(COMPOSITE_CEF_SUBPROCESS_EXECUTABLE_ARGS MACOSX_BUNDLE)
@@ -19,10 +18,7 @@ endif()

add_executable(CompositeCefSubprocess ${COMPOSITE_CEF_SUBPROCESS_EXECUTABLE_ARGS} ${CEF_SUBPROCESS_SRC_FILES})

add_dependencies(
CompositeCefSubprocess
CEF
)
target_link_libraries(CompositeCefSubprocess PRIVATE CEF)

source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${CEF_SUBPROCESS_SRC_FILES})

@@ -33,4 +29,12 @@ if(WIN32)
#target_link_libraries(CompositeCefSubprocess -manifest:embed -manifestinput:"${ENGINE_SRC_DIR}/CompositeEngine.manifest")
endif()

BootstrapCEF(CompositeCefSubprocess "ui")
install(
TARGETS CompositeCefSubprocess
RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
)
install(
FILES $<TARGET_PDB_FILE:CompositeCefSubprocess>
DESTINATION "${CMAKE_INSTALL_PREFIX}"
OPTIONAL
)

0 comments on commit c0f74d8

Please sign in to comment.
You can’t perform that action at this time.