Last active
July 5, 2025 17:29
-
-
Save dadencukillia/7fb10e325ae28de7f038c5f9008a1806 to your computer and use it in GitHub Desktop.
CEF implementation for a CMake project (Tested only on Linux)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cmake_minimum_required(VERSION 3.10.0) | |
| # CMake options | |
| set(CMAKE_INSTALL_RPATH "$ORIGIN") | |
| set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) | |
| set(CMAKE_BUILD_TYPE Release) | |
| set(BUILD_SHARED_LIBS false) | |
| set(CMAKE_CXX_STANDARD 17) | |
| project(myApplication LANGUAGES C CXX VERSION 1.0.0) | |
| # CEF initializing | |
| set(USE_SANDBOX OFF) | |
| add_subdirectory(external/cef cef_binary) # Change to the location of the downloaded CEF build (https://cef-builds.spotifycdn.com/index.html) | |
| # Application executable | |
| add_executable(${PROJECT_NAME} src/main.cpp) | |
| # Linking the library to our executable | |
| include_directories("${CEF_INCLUDE_PATH}") | |
| target_link_libraries(${PROJECT_NAME} PRIVATE | |
| libcef_dll_wrapper | |
| "${CEF_BINARY_DIR}/libcef.so" | |
| ) | |
| # Copying necessary files to build directory | |
| file(GLOB CEF_RESOURCE_FILES "${CEF_RESOURCE_DIR}/*") | |
| foreach(RES_FILE ${CEF_RESOURCE_FILES}) | |
| add_custom_command( | |
| TARGET ${PROJECT_NAME} POST_BUILD | |
| COMMAND ${CMAKE_COMMAND} -E copy_if_different | |
| "${RES_FILE}" "${CMAKE_BINARY_DIR}" | |
| COMMENT "Copying ${RES_FILE}" | |
| ) | |
| endforeach() | |
| file(GLOB CEF_BINARY_FILES "${CEF_BINARY_DIR}/*") | |
| foreach(BIN_FILE ${CEF_BINARY_FILES}) | |
| add_custom_command( | |
| TARGET ${PROJECT_NAME} POST_BUILD | |
| COMMAND ${CMAKE_COMMAND} -E copy_if_different | |
| "${BIN_FILE}" "${CMAKE_BINARY_DIR}" | |
| COMMENT "Copying ${BIN_FILE}" | |
| ) | |
| endforeach() | |
| file(GLOB CEF_LOCALES_FILES "${CEF_RESOURCE_DIR}/locales/*") | |
| foreach(LOCALE_FILE ${CEF_LOCALES_FILES}) | |
| add_custom_command( | |
| TARGET ${PROJECT_NAME} POST_BUILD | |
| COMMAND ${CMAKE_COMMAND} -E copy_if_different | |
| "${LOCALE_FILE}" "${CMAKE_BINARY_DIR}/locales" | |
| COMMENT "Copying ${LOCALE_FILE}" | |
| ) | |
| endforeach() | |
| ## Note: We used the CEF_INCLUDE_PATH, CEF_RESOURCE_DIR, CEF_BINARY_DIR variables | |
| ## that declared in the cef_variables.cmake file, but we dont have the direct access | |
| ## to variables declared in that file. So, to fix this add `CACHE INTERNAL ""` in | |
| ## `set` functions. Like: | |
| ## | |
| ## > set(CEF_BINARY_DIR "${_CEF_ROOT}/${CMAKE_BUILD_TYPE}" CACHE INTERNAL "") | |
| ## Here ^^^^^^^^^^^^^^^^^ | |
| ## Note: You can remove some lines in the CEF/CMakeLists.txt file to make configuring | |
| ## and building faster. | |
| # THATS ALL! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment