|
| 1 | +set(LKCEF_SRCS app.cpp app.hpp utils.cpp utils.hpp handler.hpp handler.cpp) |
| 2 | +set(LKCEF_SRCS_LINUX main_linux.cpp) |
| 3 | +set(LKCEF_SRCS_MAC main_mac.mm handler_mac.mm app_mac.mm) |
| 4 | +set(LKCEF_SRCS_WINDOWS main_win.cpp ) |
| 5 | +append_platform_sources(LKCEF_SRCS) |
| 6 | +source_group(lkcef FILES ${LKCEF_SRCS}) |
| 7 | + |
| 8 | +set(LKCEF_HELPER_SRCS utils.cpp utils.hpp) |
| 9 | +set(LKCEF_HELPER_SRCS_LINUX helper_main_linux.cpp) |
| 10 | +set(LKCEF_HELPER_SRCS_MAC helper_main_mac.mm) |
| 11 | +set(LKCEF_HELPER_SRCS_WINDOWS helper_main_win.cpp) |
| 12 | +append_platform_sources(LKCEF_HELPER_SRCS) |
| 13 | +source_group(lkcef FILES ${LKCEF_HELPER_SRCS}) |
| 14 | + |
| 15 | +set(LKCEF_PYTHON_SRCS agents_python.hpp |
| 16 | + agents_python.cpp) |
| 17 | + |
| 18 | +if(OS_LINUX OR OS_WINDOWS) |
| 19 | + # Logical target used to link the libcef library on Linux and Windows. On |
| 20 | + # macOS the CEF framework is loaded dynamically at startup. |
| 21 | + add_logical_target("libcef_lib" "${CEF_LIB_DEBUG}" "${CEF_LIB_RELEASE}") |
| 22 | +endif() |
| 23 | + |
| 24 | +set_cef_target_out_dir() # Determine the target output directory. |
| 25 | + |
| 26 | +if(OS_LINUX) |
| 27 | + # Helper executable target. |
| 28 | + add_executable(lkcef_helper ${LKCEF_HELPER_SRCS}) |
| 29 | + set_executable_target_properties(lkcef_helper) |
| 30 | + add_dependencies(lkcef_helper libcef_dll_wrapper) |
| 31 | + target_link_libraries(lkcef_helper libcef_lib libcef_dll_wrapper |
| 32 | + ${CEF_STANDARD_LIBS}) |
| 33 | + |
| 34 | + # Set rpath so that libraries can be placed next to the executable. |
| 35 | + set_target_properties(lkcef_helper PROPERTIES INSTALL_RPATH "$ORIGIN") |
| 36 | + set_target_properties(lkcef_helper PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE) |
| 37 | + |
| 38 | + # library target. |
| 39 | + add_library(lkcef SHARED ${LKCEF_SRCS}) |
| 40 | + set_library_target_properties(lkcef) |
| 41 | + add_dependencies(lkcef libcef_dll_wrapper lkcef_helper) |
| 42 | + target_link_libraries(lkcef libcef_lib libcef_dll_wrapper |
| 43 | + ${CEF_STANDARD_LIBS}) |
| 44 | + |
| 45 | + # Set rpath so that libraries can be placed next to the library. |
| 46 | + set_target_properties(lkcef PROPERTIES INSTALL_RPATH "$ORIGIN") |
| 47 | + set_target_properties(lkcef PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE) |
| 48 | + |
| 49 | + # Copy binary and resource files to the target output directory. |
| 50 | + copy_files("lkcef" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" |
| 51 | + "${CEF_TARGET_OUT_DIR}") |
| 52 | + copy_files("lkcef" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" |
| 53 | + "${CEF_TARGET_OUT_DIR}") |
| 54 | +endif() |
| 55 | + |
| 56 | +if(OS_MAC) |
| 57 | + # Avoid CMP0042 policy errors. |
| 58 | + set(CMAKE_MACOSX_RPATH 1) |
| 59 | + |
| 60 | + # Avoid CMP0068 policy errors. |
| 61 | + if(POLICY CMP0068) |
| 62 | + cmake_policy(SET CMP0068 NEW) |
| 63 | + endif() |
| 64 | + |
| 65 | + # output path for the main app bundle. |
| 66 | + set(LKCEF_APP "${CEF_TARGET_OUT_DIR}/lkcef_app.app") |
| 67 | + |
| 68 | + # library target. |
| 69 | + add_library(lkcef STATIC ${LKCEF_SRCS}) |
| 70 | + set_library_target_properties(lkcef) |
| 71 | + add_dependencies(lkcef libcef_dll_wrapper) |
| 72 | + target_link_libraries(lkcef libcef_dll_wrapper ${CEF_STANDARD_LIBS}) |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + add_custom_command( |
| 77 | + TARGET lkcef |
| 78 | + POST_BUILD |
| 79 | + # Copy the CEF framework into the main app bundle. |
| 80 | + COMMAND |
| 81 | + ${CMAKE_COMMAND} -E copy_directory |
| 82 | + "${CEF_BINARY_DIR}/Chromium Embedded Framework.framework" |
| 83 | + "${LKCEF_APP}/Contents/Frameworks/Chromium Embedded Framework.framework" |
| 84 | + # Copy the library into the main app bindle. COMMAND ${CMAKE_COMMAND} -E |
| 85 | + # copy_if_different "${CEF_TARGET_OUT_DIR}/liblkcef.dylib" |
| 86 | + # "${LKCEF_APP}/Contents/MacOS/liblkcef.dylib" |
| 87 | + VERBATIM) |
| 88 | + |
| 89 | + # Create the multiple Helper app bundle targets. |
| 90 | + foreach(_suffix_list ${CEF_HELPER_APP_SUFFIXES}) |
| 91 | + # Convert to a list and extract the suffix values. |
| 92 | + string(REPLACE ":" ";" _suffix_list ${_suffix_list}) |
| 93 | + list(GET _suffix_list 0 _name_suffix) |
| 94 | + list(GET _suffix_list 1 _target_suffix) |
| 95 | + list(GET _suffix_list 2 _plist_suffix) |
| 96 | + |
| 97 | + # Define Helper target and output names. |
| 98 | + set(_helper_target "lkcef_Helper${_target_suffix}") |
| 99 | + set(_helper_output_name "lkcef Helper${_name_suffix}") |
| 100 | + |
| 101 | + # Create Helper-specific variants of the helper-Info.plist file. |
| 102 | + set(_helper_info_plist |
| 103 | + "${CMAKE_CURRENT_BINARY_DIR}/lkcef-Info${_target_suffix}.plist") |
| 104 | + file(READ "${CMAKE_CURRENT_SOURCE_DIR}/resources/lkcef-Info.plist" |
| 105 | + _plist_contents) |
| 106 | + string(REPLACE "\${EXECUTABLE_NAME}" "${_helper_output_name}" |
| 107 | + _plist_contents ${_plist_contents}) |
| 108 | + string(REPLACE "\${PRODUCT_NAME}" "${_helper_output_name}" _plist_contents |
| 109 | + ${_plist_contents}) |
| 110 | + string(REPLACE "\${BUNDLE_ID_SUFFIX}" "${_plist_suffix}" _plist_contents |
| 111 | + ${_plist_contents}) |
| 112 | + file(WRITE ${_helper_info_plist} ${_plist_contents}) |
| 113 | + |
| 114 | + # Create Helper executable target. |
| 115 | + add_executable(${_helper_target} MACOSX_BUNDLE ${LKCEF_HELPER_SRCS}) |
| 116 | + set_executable_target_properties(${_helper_target}) |
| 117 | + add_dependencies(${_helper_target} libcef_dll_wrapper) |
| 118 | + target_link_libraries(${_helper_target} libcef_dll_wrapper |
| 119 | + ${CEF_STANDARD_LIBS}) |
| 120 | + set_target_properties( |
| 121 | + ${_helper_target} |
| 122 | + PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${_helper_info_plist} |
| 123 | + OUTPUT_NAME ${_helper_output_name}) |
| 124 | + |
| 125 | + # Add the Helper as a dependency of the main executable target. |
| 126 | + add_dependencies(lkcef "${_helper_target}") |
| 127 | + |
| 128 | + # Copy the Helper app bundle into the Frameworks directory. |
| 129 | + add_custom_command( |
| 130 | + TARGET lkcef |
| 131 | + POST_BUILD |
| 132 | + COMMAND |
| 133 | + ${CMAKE_COMMAND} -E copy_directory |
| 134 | + "${CEF_TARGET_OUT_DIR}/${_helper_output_name}.app" |
| 135 | + "${LKCEF_APP}/Contents/Frameworks/${_helper_output_name}.app" |
| 136 | + VERBATIM) |
| 137 | + endforeach() |
| 138 | +endif() |
| 139 | + |
| 140 | +if(OS_WINDOWS) |
| 141 | + # Helper executable target. |
| 142 | + add_executable(lkcef_helper WIN32 ${LKCEF_HELPER_SRCS}) |
| 143 | + set_executable_target_properties(lkcef_helper) |
| 144 | + add_dependencies(lkcef_helper libcef_dll_wrapper) |
| 145 | + target_link_libraries(lkcef_helper libcef_lib libcef_dll_wrapper |
| 146 | + ${CEF_STANDARD_LIBS}) |
| 147 | + |
| 148 | + # library target. |
| 149 | + add_library(lkcef SHARED ${LKCEF_SRCS}) |
| 150 | + set_library_target_properties(lkcef) |
| 151 | + add_dependencies(lkcef libcef_dll_wrapper lkcef_helper) |
| 152 | + target_link_libraries(lkcef libcef_lib libcef_dll_wrapper |
| 153 | + ${CEF_STANDARD_LIBS}) |
| 154 | + |
| 155 | + # Add the custom manifest files to the DLL and helper EXE. |
| 156 | + add_windows_manifest("${CMAKE_CURRENT_SOURCE_DIR}" "lkcef" "dll") |
| 157 | + add_windows_manifest("${CMAKE_CURRENT_SOURCE_DIR}" "lkcef_helper" "exe") |
| 158 | + |
| 159 | + # Copy binary and resource files to the target output directory. |
| 160 | + copy_files("lkcef" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" |
| 161 | + "${CEF_TARGET_OUT_DIR}") |
| 162 | + copy_files("lkcef" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" |
| 163 | + "${CEF_TARGET_OUT_DIR}") |
| 164 | +endif() |
| 165 | + |
| 166 | + |
| 167 | +# TODO(theomonnom): should be pretty similar for NodeJS |
| 168 | +pybind11_add_module(lkcef_python ${LKCEF_PYTHON_SRCS}) |
| 169 | + |
| 170 | +set_target_properties(lkcef_python PROPERTIES INSTALL_RPATH "$ORIGIN") |
| 171 | +set_target_properties(lkcef_python PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE) |
| 172 | + |
| 173 | +target_include_directories(lkcef_python PRIVATE ${CEF_INCLUDE_PATH}) |
| 174 | +target_link_libraries(lkcef_python PUBLIC lkcef) |
| 175 | +target_link_libraries(lkcef_python PUBLIC libcef_dll_wrapper ${CEF_STANDARD_LIBS}) |
| 176 | + |
| 177 | + |
| 178 | + |
0 commit comments