Modernize binary distribution CMake configuration

Issue #1897 resolved
Marshall Greenblatt created an issue

Modernize the binary distribution CMake configuration:

  • Load CEF using find_package(CEF).
  • Use per-target configuration via a new SET_EXECUTABLE_TARGET_PROPERTIES macro instead of setting global CMAKE_* variables.
  • Support configuration using an external binary distribution download. It's no longer necessary to copy/paste files from the binary distribution to your project folder.

See binary distribution contents after this change for additional documentation and examples. In summary, CMake usage will be as follows:

1. Create a directory structure for your project like the following:

myproject/
  CMakeLists.txt
  myapp/
    CMakeLists.txt
    ... other source files

2. Download a CEF binary distribution that includes this change and extract. For example, "c:/temp/cef_binary_3.2704.xxxx.gyyyyyyy_windows32".

3. Configure CMake from the top-level CMakeLists.txt file and load the CEF binary distribution using the new "cmake/FindCEF.cmake" file and find_package(). For example, "myproject/CMakeLists.txt" might contain the following:

cmake_minimum_required(VERSION 2.8.12.1)

# Only generate Debug and Release configuration types.
set(CMAKE_CONFIGURATION_TYPES Debug Release)

# Sample project name.
project(myproject)

# Use folders in the resulting project files.
set_property(GLOBAL PROPERTY OS_FOLDERS ON)

# Specify the CEF binary distribution root directory.
set(CEF_ROOT "c:/temp/cef_binary_3.2704.xxxx.gyyyyyyy_windows32")

# Execute FindCEF.cmake.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CEF_ROOT}/cmake")
find_package(CEF REQUIRED)

# Include the libcef_dll_wrapper target.
add_subdirectory(${CEF_LIBCEF_DLL_WRAPPER_PATH} libcef_dll_wrapper)

# Include the sample application target.
add_subdirectory(myapp)

# Display CEF configuration settings.
PRINT_CEF_CONFIG()

4. Call the new SET_EXECUTABLE_TARGET_PROPERTIES macro to associate compile/linker attributes with the target. For example:

add_executable(${CEF_TARGET} ${CEFSIMPLE_SRCS})
SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET})  # new line
add_dependencies(${CEF_TARGET} libcef_dll_wrapper)
target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS})

Comments (6)

  1. Marshall Greenblatt reporter

    Master revision 80c7c1b and 2704 branch revision f75afa3 add cmake, include and libcef_dll directories to the minimal binary distribution. The minimal distribution can now be used with applications that configure an external CEF_ROOT directory to save bandwidth.

  2. Marshall Greenblatt reporter

    Here's an example of downloading and extracting a CEF binary distribution during cmake generation:

    cmake_minimum_required(VERSION 2.8.12.1)
    
    # Only generate Debug and Release configuration types.
    set(CMAKE_CONFIGURATION_TYPES Debug Release)
    
    # Project name.
    project(cef)
    
    # Use folders in the resulting project files.
    set_property(GLOBAL PROPERTY OS_FOLDERS ON)
    
    # Specify the version.
    set(CEF_VERSION "3.2704.1427.g95055fe")
    
    # Specify the platform.
    if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
      set(CEF_PLATFORM "macosx64")
    elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
      set(CEF_PLATFORM "linux64")
    elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
      set(CEF_PLATFORM "windows32")
    endif()
    
    # Specify the binary distribution type and download directory.
    set(CEF_DISTRIBUTION "cef_binary_${CEF_VERSION}_${CEF_PLATFORM}")
    set(CEF_DOWNLOAD_DIR "${CMAKE_SOURCE_DIR}/third-party/cef")
    
    # The location where we expect the extracted binary distribution.
    set(CEF_ROOT "${CEF_DOWNLOAD_DIR}/${CEF_DISTRIBUTION}")
    
    # Download and/or extract the binary distribution if necessary.
    if(NOT IS_DIRECTORY "${CEF_ROOT}")
      set(CEF_DOWNLOAD_FILENAME "${CEF_DISTRIBUTION}.tar.bz2")
      set(CEF_DOWNLOAD_PATH "${CEF_DOWNLOAD_DIR}/${CEF_DOWNLOAD_FILENAME}")
      if(NOT EXISTS "${CEF_DOWNLOAD_PATH}")
        set(CEF_DOWNLOAD_URL "http://opensource.spotify.com/cefbuilds/${CEF_DOWNLOAD_FILENAME}")
    
        # Download the SHA1 hash for the binary distribution.
        message(STATUS "Downloading ${CEF_DOWNLOAD_PATH}.sha1...")
        file(DOWNLOAD "${CEF_DOWNLOAD_URL}.sha1" "${CEF_DOWNLOAD_PATH}.sha1")
        file(READ "${CEF_DOWNLOAD_PATH}.sha1" CEF_SHA1)
    
        # Download the binary distribution and verify the hash.
        message(STATUS "Downloading ${CEF_DOWNLOAD_PATH}...")
        file(
          DOWNLOAD "${CEF_DOWNLOAD_URL}" "${CEF_DOWNLOAD_PATH}"
          EXPECTED_HASH SHA1=${CEF_SHA1}
          SHOW_PROGRESS
          )
      endif()
    
      # Extract the binary distribution.
      message(STATUS "Extracting ${CEF_DOWNLOAD_PATH}...")
      execute_process(
        COMMAND ${CMAKE_COMMAND} -E tar xzf "${CEF_DOWNLOAD_DIR}/${CEF_DOWNLOAD_FILENAME}"
        WORKING_DIRECTORY ${CEF_DOWNLOAD_DIR}
        )
    endif()
    
    # Execute FindCEF.cmake which must exist in CMAKE_MODULE_PATH.
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CEF_ROOT}/cmake")
    find_package(CEF REQUIRED)
    
    # Include the libcef_dll_wrapper target.
    add_subdirectory(${CEF_LIBCEF_DLL_WRAPPER_PATH} libcef_dll_wrapper)
    
    # Include sample application targets from the downloaded binary distribution.
    # TODO: Change these lines to match your project target.
    add_subdirectory(${CEF_ROOT}/cefclient)
    add_subdirectory(${CEF_ROOT}/cefsimple)
    
    # Display configuration settings.
    PRINT_CEF_CONFIG()
    

    You can also use ExternalProject_Add to download/extract the binary distribution, however it will not execute until the resulting project is built. Personally I prefer to download/extract at cmake execution time. Here's an example of the ExternalProject_Add command that you could use:

    include(ExternalProject)
    ExternalProject_Add(
      cef_binary
      URL "http://opensource.spotify.com/cefbuilds/cef_binary_3.2704.1427.g95055fe_windows32.tar.bz2"
      SOURCE_DIR "${CMAKE_SOURCE_DIR}/third-party/cef"
      CONFIGURE_COMMAND ""
      BUILD_COMMAND ""
      INSTALL_COMMAND ""
      LOG_DOWNLOAD ON
      )
    
  3. Log in to comment