[CMake] Use target oriented design for bmalloc
https://bugs.webkit.org/show_bug.cgi?id=198046

Reviewed by Konstantin Tokarev.

.:

Add WEBKIT_COPY_FILES to WebKitMacros so it is available to all CMake code. Add
bmalloc_FRAMEWORK_HEADERS_DIR for specifying the location to copy bmalloc headers to.

* Source/cmake/WebKitFS.cmake:
* Source/cmake/WebKitMacros.cmake:

Source/bmalloc:

Switch to a target oriented dsign for bmalloc. Use target_include_directories directly
instead of include_directories.

List the headers for bmalloc and copy them using WEBKIT_COPY_FILES.

Add an intermediate target bmalloc_PostBuild which depends on bmalloc and the headers
being copied. Then alias that to WebKit::bmalloc.

* CMakeLists.txt:
* PlatformMac.cmake:

Source/ThirdParty/ANGLE:

Remove WEBKIT_COPY_FILES from CMakelists.txt now that it is in WebKitMacros.

* CMakeLists.txt:

Source/WTF:

Use WebKit::bmalloc target.

* wtf/CMakeLists.txt:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@245723 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/ChangeLog b/ChangeLog
index a653437..9298ad3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2019-05-23  Don Olmstead  <don.olmstead@sony.com>
+
+        [CMake] Use target oriented design for bmalloc
+        https://bugs.webkit.org/show_bug.cgi?id=198046
+
+        Reviewed by Konstantin Tokarev.
+
+        Add WEBKIT_COPY_FILES to WebKitMacros so it is available to all CMake code. Add
+        bmalloc_FRAMEWORK_HEADERS_DIR for specifying the location to copy bmalloc headers to.
+
+        * Source/cmake/WebKitFS.cmake:
+        * Source/cmake/WebKitMacros.cmake:
+
 2019-05-21  Don Olmstead  <don.olmstead@sony.com>
 
         [WinCairo] Build WebDriver
diff --git a/Source/ThirdParty/ANGLE/CMakeLists.txt b/Source/ThirdParty/ANGLE/CMakeLists.txt
index 4726c8b..8767a2c 100644
--- a/Source/ThirdParty/ANGLE/CMakeLists.txt
+++ b/Source/ThirdParty/ANGLE/CMakeLists.txt
@@ -1,35 +1,3 @@
-# FIXME: Remove when landing https://bugs.webkit.org/show_bug.cgi?id=197174
-function(WEBKIT_COPY_FILES target_name)
-    set(options FLATTENED)
-    set(oneValueArgs DESTINATION)
-    set(multiValueArgs FILES)
-    cmake_parse_arguments(opt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-    set(files ${opt_FILES})
-    set(dst_files)
-    foreach (file IN LISTS files)
-        if (IS_ABSOLUTE ${file})
-            set(src_file ${file})
-        else ()
-            set(src_file ${CMAKE_CURRENT_SOURCE_DIR}/${file})
-        endif ()
-        if (opt_FLATTENED)
-            get_filename_component(filename ${file} NAME)
-            set(dst_file ${opt_DESTINATION}/${filename})
-        else ()
-            get_filename_component(file_dir ${file} DIRECTORY)
-            file(MAKE_DIRECTORY ${opt_DESTINATION}/${file_dir})
-            set(dst_file ${opt_DESTINATION}/${file})
-        endif ()
-        add_custom_command(OUTPUT ${dst_file}
-            COMMAND ${CMAKE_COMMAND} -E copy ${src_file} ${dst_file}
-            MAIN_DEPENDENCY ${file}
-            VERBATIM
-        )
-        list(APPEND dst_files ${dst_file})
-    endforeach ()
-    add_custom_target(${target_name} DEPENDS ${dst_files})
-endfunction()
-
 include(Compiler.cmake)
 include(GLESv2.cmake)
 
diff --git a/Source/ThirdParty/ANGLE/ChangeLog b/Source/ThirdParty/ANGLE/ChangeLog
index 3ed106d..dd1e479 100644
--- a/Source/ThirdParty/ANGLE/ChangeLog
+++ b/Source/ThirdParty/ANGLE/ChangeLog
@@ -1,3 +1,14 @@
+2019-05-23  Don Olmstead  <don.olmstead@sony.com>
+
+        [CMake] Use target oriented design for bmalloc
+        https://bugs.webkit.org/show_bug.cgi?id=198046
+
+        Reviewed by Konstantin Tokarev.
+
+        Remove WEBKIT_COPY_FILES from CMakelists.txt now that it is in WebKitMacros.
+
+        * CMakeLists.txt:
+
 2019-05-14  Miguel Gomez  <magomez@igalia.com>
 
         REGRESSION(r245088): [GTK] Several WebGL tests failing
diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog
index a8f45dd..c265abd 100644
--- a/Source/WTF/ChangeLog
+++ b/Source/WTF/ChangeLog
@@ -1,3 +1,14 @@
+2019-05-23  Don Olmstead  <don.olmstead@sony.com>
+
+        [CMake] Use target oriented design for bmalloc
+        https://bugs.webkit.org/show_bug.cgi?id=198046
+
+        Reviewed by Konstantin Tokarev.
+
+        Use WebKit::bmalloc target.
+
+        * wtf/CMakeLists.txt:
+
 2019-05-23  Ross Kirsling  <ross.kirsling@sony.com>
 
         [PlayStation] Implement platformUserPreferredLanguages.
diff --git a/Source/WTF/wtf/CMakeLists.txt b/Source/WTF/wtf/CMakeLists.txt
index 07f501a..4d2e3f9 100644
--- a/Source/WTF/wtf/CMakeLists.txt
+++ b/Source/WTF/wtf/CMakeLists.txt
@@ -458,7 +458,6 @@
 )
 
 set(WTF_INCLUDE_DIRECTORIES
-    "${BMALLOC_DIR}"
     # FIXME: https://bugs.webkit.org/show_bug.cgi?id=196734#c1
     "${CMAKE_BINARY_DIR}"
     "${DERIVED_SOURCES_DIR}"
@@ -483,7 +482,7 @@
 )
 
 if (NOT USE_SYSTEM_MALLOC)
-    list(APPEND WTF_LIBRARIES bmalloc)
+    list(APPEND WTF_LIBRARIES WebKit::bmalloc)
 endif ()
 
 list(APPEND WTF_SOURCES
diff --git a/Source/bmalloc/CMakeLists.txt b/Source/bmalloc/CMakeLists.txt
index f33bd52..2e07f1a 100644
--- a/Source/bmalloc/CMakeLists.txt
+++ b/Source/bmalloc/CMakeLists.txt
@@ -1,6 +1,6 @@
 set_property(DIRECTORY . PROPERTY FOLDER "bmalloc")
 
-set(bmalloc_INCLUDE_DIRECTORIES
+set(bmalloc_PRIVATE_INCLUDE_DIRECTORIES
     "${BMALLOC_DIR}"
 )
 
@@ -36,6 +36,101 @@
     bmalloc/mbmalloc.cpp
 )
 
+set(bmalloc_PUBLIC_HEADERS
+    bmalloc/Algorithm.h
+    bmalloc/AllIsoHeaps.h
+    bmalloc/AllIsoHeapsInlines.h
+    bmalloc/Allocator.h
+    bmalloc/AvailableMemory.h
+    bmalloc/BAssert.h
+    bmalloc/BCompiler.h
+    bmalloc/BExport.h
+    bmalloc/BInline.h
+    bmalloc/BMalloced.h
+    bmalloc/BPlatform.h
+    bmalloc/BVMTags.h
+    bmalloc/Bits.h
+    bmalloc/BulkDecommit.h
+    bmalloc/BumpAllocator.h
+    bmalloc/BumpRange.h
+    bmalloc/Cache.h
+    bmalloc/Chunk.h
+    bmalloc/CryptoRandom.h
+    bmalloc/Deallocator.h
+    bmalloc/DebugHeap.h
+    bmalloc/DeferredDecommit.h
+    bmalloc/DeferredDecommitInlines.h
+    bmalloc/DeferredTrigger.h
+    bmalloc/DeferredTriggerInlines.h
+    bmalloc/EligibilityResult.h
+    bmalloc/EligibilityResultInlines.h
+    bmalloc/Environment.h
+    bmalloc/FixedVector.h
+    bmalloc/FreeList.h
+    bmalloc/FreeListInlines.h
+    bmalloc/Gigacage.h
+    bmalloc/Heap.h
+    bmalloc/HeapKind.h
+    bmalloc/IsoAllocator.h
+    bmalloc/IsoAllocatorInlines.h
+    bmalloc/IsoConfig.h
+    bmalloc/IsoDeallocator.h
+    bmalloc/IsoDeallocatorInlines.h
+    bmalloc/IsoDirectory.h
+    bmalloc/IsoDirectoryInlines.h
+    bmalloc/IsoDirectoryPage.h
+    bmalloc/IsoDirectoryPageInlines.h
+    bmalloc/IsoHeap.h
+    bmalloc/IsoHeapImpl.h
+    bmalloc/IsoHeapImplInlines.h
+    bmalloc/IsoHeapInlines.h
+    bmalloc/IsoPage.h
+    bmalloc/IsoPageInlines.h
+    bmalloc/IsoPageTrigger.h
+    bmalloc/IsoSharedConfig.h
+    bmalloc/IsoSharedHeap.h
+    bmalloc/IsoSharedHeapInlines.h
+    bmalloc/IsoSharedPage.h
+    bmalloc/IsoSharedPageInlines.h
+    bmalloc/IsoTLS.h
+    bmalloc/IsoTLSAllocatorEntry.h
+    bmalloc/IsoTLSAllocatorEntryInlines.h
+    bmalloc/IsoTLSDeallocatorEntry.h
+    bmalloc/IsoTLSDeallocatorEntryInlines.h
+    bmalloc/IsoTLSEntry.h
+    bmalloc/IsoTLSEntryInlines.h
+    bmalloc/IsoTLSInlines.h
+    bmalloc/IsoTLSLayout.h
+    bmalloc/LargeMap.h
+    bmalloc/LargeRange.h
+    bmalloc/LineMetadata.h
+    bmalloc/List.h
+    bmalloc/Logging.h
+    bmalloc/Map.h
+    bmalloc/Mutex.h
+    bmalloc/Object.h
+    bmalloc/ObjectType.h
+    bmalloc/PerHeapKind.h
+    bmalloc/PerProcess.h
+    bmalloc/PerThread.h
+    bmalloc/PhysicalPageMap.h
+    bmalloc/ProcessCheck.h
+    bmalloc/Range.h
+    bmalloc/Scavenger.h
+    bmalloc/ScopeExit.h
+    bmalloc/Sizes.h
+    bmalloc/SmallLine.h
+    bmalloc/SmallPage.h
+    bmalloc/StaticPerProcess.h
+    bmalloc/StdLibExtras.h
+    bmalloc/Syscall.h
+    bmalloc/VMAllocate.h
+    bmalloc/VMHeap.h
+    bmalloc/Vector.h
+    bmalloc/Zone.h
+    bmalloc/bmalloc.h
+)
+
 if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
     list(APPEND bmalloc_SOURCES
         bmalloc/Zone.cpp
@@ -49,13 +144,27 @@
 WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS()
 
 WEBKIT_WRAP_SOURCELIST(${bmalloc_SOURCES})
-include_directories(${bmalloc_INCLUDE_DIRECTORIES})
+
 add_library(bmalloc STATIC ${bmalloc_SOURCES})
+target_include_directories(bmalloc PRIVATE ${bmalloc_PRIVATE_INCLUDE_DIRECTORIES})
+target_include_directories(bmalloc INTERFACE "$<BUILD_INTERFACE:${bmalloc_FRAMEWORK_HEADERS_DIR}>")
 target_link_libraries(bmalloc ${bmalloc_LIBRARIES})
 set_target_properties(bmalloc PROPERTIES COMPILE_DEFINITIONS "BUILDING_bmalloc")
 
+WEBKIT_COPY_FILES(bmalloc_CopyHeaders
+    DESTINATION ${bmalloc_FRAMEWORK_HEADERS_DIR}
+    FILES ${bmalloc_PUBLIC_HEADERS}
+)
+
+add_library(bmalloc_PostBuild INTERFACE)
+target_link_libraries(bmalloc_PostBuild INTERFACE bmalloc)
+add_dependencies(bmalloc_PostBuild bmalloc_CopyHeaders)
+
+add_library(WebKit::bmalloc ALIAS bmalloc_PostBuild)
+
 if (DEVELOPER_MODE)
     add_library(mbmalloc SHARED bmalloc/mbmalloc.cpp)
+    target_include_directories(mbmalloc PRIVATE ${bmalloc_PRIVATE_INCLUDE_DIRECTORIES})
     target_link_libraries(mbmalloc bmalloc ${CMAKE_THREAD_LIBS_INIT} ${bmalloc_LIBRARIES})
     set_target_properties(mbmalloc PROPERTIES COMPILE_DEFINITIONS "BUILDING_mbmalloc")
 endif ()
diff --git a/Source/bmalloc/ChangeLog b/Source/bmalloc/ChangeLog
index 988eb70..ddfd806 100644
--- a/Source/bmalloc/ChangeLog
+++ b/Source/bmalloc/ChangeLog
@@ -1,3 +1,21 @@
+2019-05-23  Don Olmstead  <don.olmstead@sony.com>
+
+        [CMake] Use target oriented design for bmalloc
+        https://bugs.webkit.org/show_bug.cgi?id=198046
+
+        Reviewed by Konstantin Tokarev.
+
+        Switch to a target oriented dsign for bmalloc. Use target_include_directories directly
+        instead of include_directories.
+
+        List the headers for bmalloc and copy them using WEBKIT_COPY_FILES.
+
+        Add an intermediate target bmalloc_PostBuild which depends on bmalloc and the headers
+        being copied. Then alias that to WebKit::bmalloc.
+
+        * CMakeLists.txt:
+        * PlatformMac.cmake:
+
 2019-05-16  Keith Miller  <keith_miller@apple.com>
 
         Wasm should cage the memory base pointers in structs
diff --git a/Source/bmalloc/PlatformMac.cmake b/Source/bmalloc/PlatformMac.cmake
index c53c48e..48bd546 100644
--- a/Source/bmalloc/PlatformMac.cmake
+++ b/Source/bmalloc/PlatformMac.cmake
@@ -3,3 +3,8 @@
 list(APPEND bmalloc_SOURCES
     bmalloc/ProcessCheck.mm
 )
+
+list(APPEND bmalloc_PUBLIC_HEADERS
+    bmalloc/darwin/BSoftLinking.h
+    bmalloc/darwin/MemoryStatusSPI.h
+)
diff --git a/Source/cmake/WebKitFS.cmake b/Source/cmake/WebKitFS.cmake
index b4918c1..5b36481 100644
--- a/Source/cmake/WebKitFS.cmake
+++ b/Source/cmake/WebKitFS.cmake
@@ -50,6 +50,7 @@
 
 set(FORWARDING_HEADERS_DIR ${DERIVED_SOURCES_DIR}/ForwardingHeaders)
 
+set(bmalloc_FRAMEWORK_HEADERS_DIR ${FORWARDING_HEADERS_DIR})
 set(ANGLE_FRAMEWORK_HEADERS_DIR ${FORWARDING_HEADERS_DIR})
 set(WTF_FRAMEWORK_HEADERS_DIR ${FORWARDING_HEADERS_DIR})
 set(JavaScriptCore_FRAMEWORK_HEADERS_DIR ${FORWARDING_HEADERS_DIR})
diff --git a/Source/cmake/WebKitMacros.cmake b/Source/cmake/WebKitMacros.cmake
index 4aacbd6..6d57ee3 100644
--- a/Source/cmake/WebKitMacros.cmake
+++ b/Source/cmake/WebKitMacros.cmake
@@ -333,6 +333,37 @@
     add_dependencies(${framework} ${target_name})
 endfunction()
 
+function(WEBKIT_COPY_FILES target_name)
+    set(options FLATTENED)
+    set(oneValueArgs DESTINATION)
+    set(multiValueArgs FILES)
+    cmake_parse_arguments(opt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+    set(files ${opt_FILES})
+    set(dst_files)
+    foreach (file IN LISTS files)
+        if (IS_ABSOLUTE ${file})
+            set(src_file ${file})
+        else ()
+            set(src_file ${CMAKE_CURRENT_SOURCE_DIR}/${file})
+        endif ()
+        if (opt_FLATTENED)
+            get_filename_component(filename ${file} NAME)
+            set(dst_file ${opt_DESTINATION}/${filename})
+        else ()
+            get_filename_component(file_dir ${file} DIRECTORY)
+            file(MAKE_DIRECTORY ${opt_DESTINATION}/${file_dir})
+            set(dst_file ${opt_DESTINATION}/${file})
+        endif ()
+        add_custom_command(OUTPUT ${dst_file}
+            COMMAND ${CMAKE_COMMAND} -E copy ${src_file} ${dst_file}
+            MAIN_DEPENDENCY ${file}
+            VERBATIM
+        )
+        list(APPEND dst_files ${dst_file})
+    endforeach ()
+    add_custom_target(${target_name} DEPENDS ${dst_files})
+endfunction()
+
 # Helper macros for debugging CMake problems.
 macro(WEBKIT_DEBUG_DUMP_COMMANDS)
     set(CMAKE_VERBOSE_MAKEFILE ON)