1# Copyright (c) 2016 The Chromium Embedded Framework Authors. All rights 2# reserved. Use of this source code is governed by a BSD-style license that 3# can be found in the LICENSE file. 4 5# Must be loaded via FindCEF.cmake. 6if(NOT DEFINED _CEF_ROOT_EXPLICIT) 7 message(FATAL_ERROR "Use find_package(CEF) to load this file.") 8endif() 9 10 11# 12# Shared macros. 13# 14 15# Print the current CEF configuration. 16macro(PRINT_CEF_CONFIG) 17 message(STATUS "*** CEF CONFIGURATION SETTINGS ***") 18 message(STATUS "Generator: ${CMAKE_GENERATOR}") 19 message(STATUS "Platform: ${CMAKE_SYSTEM_NAME}") 20 message(STATUS "Project architecture: ${PROJECT_ARCH}") 21 22 if(GEN_NINJA OR GEN_MAKEFILES) 23 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") 24 endif() 25 26 message(STATUS "Binary distribution root: ${_CEF_ROOT}") 27 28 if(OS_MAC) 29 message(STATUS "Base SDK: ${CMAKE_OSX_SYSROOT}") 30 message(STATUS "Target SDK: ${CEF_TARGET_SDK}") 31 endif() 32 33 if(OS_WINDOWS) 34 message(STATUS "Visual Studio ATL support: ${USE_ATL}") 35 endif() 36 37 message(STATUS "CEF sandbox: ${USE_SANDBOX}") 38 39 set(_libraries ${CEF_STANDARD_LIBS}) 40 if(OS_WINDOWS AND USE_SANDBOX) 41 list(APPEND _libraries ${CEF_SANDBOX_STANDARD_LIBS}) 42 endif() 43 message(STATUS "Standard libraries: ${_libraries}") 44 45 message(STATUS "Compile defines: ${CEF_COMPILER_DEFINES}") 46 message(STATUS "Compile defines (Debug): ${CEF_COMPILER_DEFINES_DEBUG}") 47 message(STATUS "Compile defines (Release): ${CEF_COMPILER_DEFINES_RELEASE}") 48 message(STATUS "C compile flags: ${CEF_COMPILER_FLAGS} ${CEF_C_COMPILER_FLAGS}") 49 message(STATUS "C compile flags (Debug): ${CEF_COMPILER_FLAGS_DEBUG} ${CEF_C_COMPILER_FLAGS_DEBUG}") 50 message(STATUS "C compile flags (Release): ${CEF_COMPILER_FLAGS_RELEASE} ${CEF_C_COMPILER_FLAGS_RELEASE}") 51 message(STATUS "C++ compile flags: ${CEF_COMPILER_FLAGS} ${CEF_CXX_COMPILER_FLAGS}") 52 message(STATUS "C++ compile flags (Debug): ${CEF_COMPILER_FLAGS_DEBUG} ${CEF_CXX_COMPILER_FLAGS_DEBUG}") 53 message(STATUS "C++ compile flags (Release): ${CEF_COMPILER_FLAGS_RELEASE} ${CEF_CXX_COMPILER_FLAGS_RELEASE}") 54 message(STATUS "Exe link flags: ${CEF_LINKER_FLAGS} ${CEF_EXE_LINKER_FLAGS}") 55 message(STATUS "Exe link flags (Debug): ${CEF_LINKER_FLAGS_DEBUG} ${CEF_EXE_LINKER_FLAGS_DEBUG}") 56 message(STATUS "Exe link flags (Release): ${CEF_LINKER_FLAGS_RELEASE} ${CEF_EXE_LINKER_FLAGS_RELEASE}") 57 message(STATUS "Shared link flags: ${CEF_LINKER_FLAGS} ${CEF_SHARED_LINKER_FLAGS}") 58 message(STATUS "Shared link flags (Debug): ${CEF_LINKER_FLAGS_DEBUG} ${CEF_SHARED_LINKER_FLAGS_DEBUG}") 59 message(STATUS "Shared link flags (Release): ${CEF_LINKER_FLAGS_RELEASE} ${CEF_SHARED_LINKER_FLAGS_RELEASE}") 60 61 if(OS_LINUX OR OS_WINDOWS) 62 message(STATUS "CEF Binary files: ${CEF_BINARY_FILES}") 63 message(STATUS "CEF Resource files: ${CEF_RESOURCE_FILES}") 64 endif() 65endmacro() 66 67# Append platform specific sources to a list of sources. 68macro(APPEND_PLATFORM_SOURCES name_of_list) 69 if(OS_LINUX AND ${name_of_list}_LINUX) 70 list(APPEND ${name_of_list} ${${name_of_list}_LINUX}) 71 endif() 72 if(OS_POSIX AND ${name_of_list}_POSIX) 73 list(APPEND ${name_of_list} ${${name_of_list}_POSIX}) 74 endif() 75 if(OS_WINDOWS AND ${name_of_list}_WINDOWS) 76 list(APPEND ${name_of_list} ${${name_of_list}_WINDOWS}) 77 endif() 78 if(OS_MAC AND ${name_of_list}_MAC) 79 list(APPEND ${name_of_list} ${${name_of_list}_MAC}) 80 endif() 81endmacro() 82 83# Determine the target output directory based on platform and generator. 84macro(SET_CEF_TARGET_OUT_DIR) 85 if(GEN_NINJA OR GEN_MAKEFILES) 86 # By default Ninja and Make builds don't create a subdirectory named after 87 # the configuration. 88 set(CEF_TARGET_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}") 89 90 # Output binaries (executables, libraries) to the correct directory. 91 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CEF_TARGET_OUT_DIR}) 92 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CEF_TARGET_OUT_DIR}) 93 else() 94 set(CEF_TARGET_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>") 95 endif() 96endmacro() 97 98# Copy a list of files from one directory to another. Relative files paths are maintained. 99# The path component of the source |file_list| will be removed. 100macro(COPY_FILES target file_list source_dir target_dir) 101 foreach(FILENAME ${file_list}) 102 set(source_file ${source_dir}/${FILENAME}) 103 get_filename_component(target_name ${FILENAME} NAME) 104 set(target_file ${target_dir}/${target_name}) 105 106 string(FIND ${source_file} "$<CONFIGURATION>" _pos) 107 if(NOT ${_pos} EQUAL -1) 108 # Must test with an actual configuration directory. 109 string(REPLACE "$<CONFIGURATION>" "Release" existing_source_file ${source_file}) 110 if(NOT EXISTS ${existing_source_file}) 111 string(REPLACE "$<CONFIGURATION>" "Debug" existing_source_file ${source_file}) 112 endif() 113 else() 114 set(existing_source_file ${source_file}) 115 endif() 116 117 if(IS_DIRECTORY ${existing_source_file}) 118 add_custom_command( 119 TARGET ${target} 120 POST_BUILD 121 COMMAND ${CMAKE_COMMAND} -E copy_directory "${source_file}" "${target_file}" 122 VERBATIM 123 ) 124 else() 125 add_custom_command( 126 TARGET ${target} 127 POST_BUILD 128 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${source_file}" "${target_file}" 129 VERBATIM 130 ) 131 endif() 132 endforeach() 133endmacro() 134 135 136# 137# Linux macros. 138# 139 140if(OS_LINUX) 141 142# Use pkg-config to find Linux libraries and update compiler/linker variables. 143macro(FIND_LINUX_LIBRARIES libraries) 144 # Read pkg-config info into variables. 145 execute_process(COMMAND pkg-config --cflags ${libraries} OUTPUT_VARIABLE FLL_CFLAGS) 146 execute_process(COMMAND pkg-config --libs-only-L --libs-only-other ${libraries} OUTPUT_VARIABLE FLL_LDFLAGS) 147 execute_process(COMMAND pkg-config --libs-only-l ${libraries} OUTPUT_VARIABLE FLL_LIBS) 148 149 # Strip leading and trailing whitepspace. 150 STRING(STRIP "${FLL_CFLAGS}" FLL_CFLAGS) 151 STRING(STRIP "${FLL_LDFLAGS}" FLL_LDFLAGS) 152 STRING(STRIP "${FLL_LIBS}" FLL_LIBS) 153 154 # Convert to a list. 155 separate_arguments(FLL_CFLAGS) 156 separate_arguments(FLL_LDFLAGS) 157 separate_arguments(FLL_LIBS) 158 159 # Update build variables. 160 list(APPEND CEF_C_COMPILER_FLAGS ${FLL_CFLAGS}) 161 list(APPEND CEF_CXX_COMPILER_FLAGS ${FLL_CFLAGS}) 162 list(APPEND CEF_EXE_LINKER_FLAGS ${FLL_LDFLAGS}) 163 list(APPEND CEF_SHARED_LINKER_FLAGS ${FLL_LDFLAGS}) 164 list(APPEND CEF_STANDARD_LIBS ${FLL_LIBS}) 165endmacro() 166 167# Set SUID permissions on the specified executable. 168macro(SET_LINUX_SUID_PERMISSIONS target executable) 169 add_custom_command( 170 TARGET ${target} 171 POST_BUILD 172 COMMAND ${CMAKE_COMMAND} -E echo "" 173 COMMAND ${CMAKE_COMMAND} -E echo "*** Run the following command manually to set SUID permissions ***" 174 COMMAND ${CMAKE_COMMAND} -E echo "EXE=\"${executable}\" && sudo -- chown root:root $EXE && sudo -- chmod 4755 $EXE" 175 COMMAND ${CMAKE_COMMAND} -E echo "" 176 VERBATIM 177 ) 178endmacro() 179 180endif(OS_LINUX) 181 182 183# 184# Mac OS X macros. 185# 186 187if(OS_MAC) 188 189# Manually process and copy over resource files. 190macro(COPY_MAC_RESOURCES resource_list prefix_list target source_dir app_path) 191 foreach(FILENAME ${resource_list}) 192 # Remove one or more prefixes from the source paths. 193 set(TARGET_FILENAME "${FILENAME}") 194 foreach(PREFIX ${prefix_list}) 195 string(REGEX REPLACE "^.*${PREFIX}" "" TARGET_FILENAME ${TARGET_FILENAME}) 196 endforeach() 197 198 # Determine the absolute source and target paths. 199 set(TARGET_PATH "${app_path}/Contents/Resources/${TARGET_FILENAME}") 200 if(IS_ABSOLUTE ${FILENAME}) 201 set(SOURCE_PATH ${FILENAME}) 202 else() 203 set(SOURCE_PATH "${source_dir}/${FILENAME}") 204 endif() 205 206 if(${FILENAME} MATCHES ".xib$") 207 # Change the target file extension. 208 string(REGEX REPLACE ".xib$" ".nib" TARGET_PATH ${TARGET_PATH}) 209 210 get_filename_component(TARGET_DIRECTORY ${TARGET_PATH} PATH) 211 add_custom_command( 212 TARGET ${target} 213 POST_BUILD 214 # Create the target directory. 215 COMMAND ${CMAKE_COMMAND} -E make_directory "${TARGET_DIRECTORY}" 216 # Compile the XIB file to a NIB. 217 COMMAND /usr/bin/ibtool --output-format binary1 --compile "${TARGET_PATH}" "${SOURCE_PATH}" 218 VERBATIM 219 ) 220 elseif(NOT ${TARGET_FILENAME} STREQUAL "Info.plist") 221 # Copy the file as-is. 222 add_custom_command( 223 TARGET ${target} 224 POST_BUILD 225 COMMAND ${CMAKE_COMMAND} -E copy "${SOURCE_PATH}" "${TARGET_PATH}" 226 VERBATIM 227 ) 228 endif() 229 endforeach() 230endmacro() 231 232endif(OS_MAC) 233 234 235# 236# Windows macros. 237# 238 239if(OS_WINDOWS) 240 241# Add custom manifest files to an executable target. 242macro(ADD_WINDOWS_MANIFEST manifest_path target extension) 243 add_custom_command( 244 TARGET ${target} 245 POST_BUILD 246 COMMAND "mt.exe" -nologo 247 -manifest \"${manifest_path}/${target}.${extension}.manifest\" \"${manifest_path}/compatibility.manifest\" 248 -outputresource:"${CEF_TARGET_OUT_DIR}/${target}.${extension}"\;\#1 249 COMMENT "Adding manifest..." 250 ) 251endmacro() 252 253endif(OS_WINDOWS) 254 255 256# 257# Target configuration macros. 258# 259 260# Add a logical target that can be used to link the specified libraries into an 261# executable target. 262macro(ADD_LOGICAL_TARGET target debug_lib release_lib) 263 add_library(${target} ${CEF_LIBTYPE} IMPORTED) 264 set_target_properties(${target} PROPERTIES 265 IMPORTED_LOCATION "${release_lib}" 266 IMPORTED_LOCATION_DEBUG "${debug_lib}" 267 IMPORTED_LOCATION_RELEASE "${release_lib}" 268 ) 269endmacro() 270 271# Set common target properties. Use SET_LIBRARY_TARGET_PROPERTIES() or 272# SET_EXECUTABLE_TARGET_PROPERTIES() instead of calling this macro directly. 273macro(SET_COMMON_TARGET_PROPERTIES target) 274 # Compile flags. 275 target_compile_options(${target} PRIVATE ${CEF_COMPILER_FLAGS} ${CEF_CXX_COMPILER_FLAGS}) 276 target_compile_options(${target} PRIVATE $<$<CONFIG:Debug>:${CEF_COMPILER_FLAGS_DEBUG} ${CEF_CXX_COMPILER_FLAGS_DEBUG}>) 277 target_compile_options(${target} PRIVATE $<$<CONFIG:Release>:${CEF_COMPILER_FLAGS_RELEASE} ${CEF_CXX_COMPILER_FLAGS_RELEASE}>) 278 279 # Compile definitions. 280 target_compile_definitions(${target} PRIVATE ${CEF_COMPILER_DEFINES}) 281 target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:${CEF_COMPILER_DEFINES_DEBUG}>) 282 target_compile_definitions(${target} PRIVATE $<$<CONFIG:Release>:${CEF_COMPILER_DEFINES_RELEASE}>) 283 284 # Include directories. 285 target_include_directories(${target} PRIVATE ${CEF_INCLUDE_PATH}) 286 287 # Linker flags. 288 if(CEF_LINKER_FLAGS) 289 string(REPLACE ";" " " _flags_str "${CEF_LINKER_FLAGS}") 290 set_property(TARGET ${target} PROPERTY LINK_FLAGS ${_flags_str}) 291 endif() 292 if(CEF_LINKER_FLAGS_DEBUG) 293 string(REPLACE ";" " " _flags_str "${CEF_LINKER_FLAGS_DEBUG}") 294 set_property(TARGET ${target} PROPERTY LINK_FLAGS_DEBUG ${_flags_str}) 295 endif() 296 if(CEF_LINKER_FLAGS_RELEASE) 297 string(REPLACE ";" " " _flags_str "${CEF_LINKER_FLAGS_RELEASE}") 298 set_property(TARGET ${target} PROPERTY LINK_FLAGS_RELEASE ${_flags_str}) 299 endif() 300 301 if(OS_MAC) 302 # Set Xcode target properties. 303 set_target_properties(${target} PROPERTIES 304 XCODE_ATTRIBUTE_ALWAYS_SEARCH_USER_PATHS NO 305 XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "gnu++11" # -std=gnu++11 306 XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME NO # -fno-objc-link-runtime 307 XCODE_ATTRIBUTE_CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS YES # -Wobjc-missing-property-synthesis 308 XCODE_ATTRIBUTE_COPY_PHASE_STRIP NO 309 XCODE_ATTRIBUTE_DEAD_CODE_STRIPPING[variant=Release] YES # -Wl,-dead_strip 310 XCODE_ATTRIBUTE_GCC_C_LANGUAGE_STANDARD "c99" # -std=c99 311 XCODE_ATTRIBUTE_GCC_CW_ASM_SYNTAX NO # No -fasm-blocks 312 XCODE_ATTRIBUTE_GCC_DYNAMIC_NO_PIC NO 313 XCODE_ATTRIBUTE_GCC_ENABLE_CPP_EXCEPTIONS NO # -fno-exceptions 314 XCODE_ATTRIBUTE_GCC_ENABLE_CPP_RTTI NO # -fno-rtti 315 XCODE_ATTRIBUTE_GCC_ENABLE_PASCAL_STRINGS NO # No -mpascal-strings 316 XCODE_ATTRIBUTE_GCC_INLINES_ARE_PRIVATE_EXTERN YES # -fvisibility-inlines-hidden 317 XCODE_ATTRIBUTE_GCC_OBJC_CALL_CXX_CDTORS YES # -fobjc-call-cxx-cdtors 318 XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES # -fvisibility=hidden 319 XCODE_ATTRIBUTE_GCC_THREADSAFE_STATICS NO # -fno-threadsafe-statics 320 XCODE_ATTRIBUTE_GCC_TREAT_WARNINGS_AS_ERRORS YES # -Werror 321 XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0" 322 XCODE_ATTRIBUTE_GCC_WARN_ABOUT_MISSING_NEWLINE YES # -Wnewline-eof 323 XCODE_ATTRIBUTE_USE_HEADERMAP NO 324 OSX_ARCHITECTURES_DEBUG "${CMAKE_OSX_ARCHITECTURES}" 325 OSX_ARCHITECTURES_RELEASE "${CMAKE_OSX_ARCHITECTURES}" 326 ) 327 endif() 328endmacro() 329 330# Set library-specific properties. 331macro(SET_LIBRARY_TARGET_PROPERTIES target) 332 SET_COMMON_TARGET_PROPERTIES(${target}) 333 334 # Shared library linker flags. 335 if(CEF_SHARED_LINKER_FLAGS) 336 string(REPLACE ";" " " _flags_str "${CEF_SHARED_LINKER_FLAGS}") 337 set_property(TARGET ${target} PROPERTY LINK_FLAGS ${_flags_str}) 338 endif() 339 if(CEF_SHARED_LINKER_FLAGS_DEBUG) 340 string(REPLACE ";" " " _flags_str "${CEF_SHARED_LINKER_FLAGS_DEBUG}") 341 set_property(TARGET ${target} PROPERTY LINK_FLAGS_DEBUG ${_flags_str}) 342 endif() 343 if(CEF_SHARED_LINKER_FLAGS_RELEASE) 344 string(REPLACE ";" " " _flags_str "${CEF_SHARED_LINKER_FLAGS_RELEASE}") 345 set_property(TARGET ${target} PROPERTY LINK_FLAGS_RELEASE ${_flags_str}) 346 endif() 347endmacro() 348 349# Set executable-specific properties. 350macro(SET_EXECUTABLE_TARGET_PROPERTIES target) 351 SET_COMMON_TARGET_PROPERTIES(${target}) 352 353 # Executable linker flags. 354 if(CEF_EXE_LINKER_FLAGS) 355 string(REPLACE ";" " " _flags_str "${CEF_EXE_LINKER_FLAGS}") 356 set_property(TARGET ${target} PROPERTY LINK_FLAGS ${_flags_str}) 357 endif() 358 if(CEF_EXE_LINKER_FLAGS_DEBUG) 359 string(REPLACE ";" " " _flags_str "${CEF_EXE_LINKER_FLAGS_DEBUG}") 360 set_property(TARGET ${target} PROPERTY LINK_FLAGS_DEBUG ${_flags_str}) 361 endif() 362 if(CEF_EXE_LINKER_FLAGS_RELEASE) 363 string(REPLACE ";" " " _flags_str "${CEF_EXE_LINKER_FLAGS_RELEASE}") 364 set_property(TARGET ${target} PROPERTY LINK_FLAGS_RELEASE ${_flags_str}) 365 endif() 366endmacro() 367