4726c8bdae17588b346c1b13822a2b09b6eedfa7
[WebKit-https.git] / Source / ThirdParty / ANGLE / CMakeLists.txt
1 # FIXME: Remove when landing https://bugs.webkit.org/show_bug.cgi?id=197174
2 function(WEBKIT_COPY_FILES target_name)
3     set(options FLATTENED)
4     set(oneValueArgs DESTINATION)
5     set(multiValueArgs FILES)
6     cmake_parse_arguments(opt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
7     set(files ${opt_FILES})
8     set(dst_files)
9     foreach (file IN LISTS files)
10         if (IS_ABSOLUTE ${file})
11             set(src_file ${file})
12         else ()
13             set(src_file ${CMAKE_CURRENT_SOURCE_DIR}/${file})
14         endif ()
15         if (opt_FLATTENED)
16             get_filename_component(filename ${file} NAME)
17             set(dst_file ${opt_DESTINATION}/${filename})
18         else ()
19             get_filename_component(file_dir ${file} DIRECTORY)
20             file(MAKE_DIRECTORY ${opt_DESTINATION}/${file_dir})
21             set(dst_file ${opt_DESTINATION}/${file})
22         endif ()
23         add_custom_command(OUTPUT ${dst_file}
24             COMMAND ${CMAKE_COMMAND} -E copy ${src_file} ${dst_file}
25             MAIN_DEPENDENCY ${file}
26             VERBATIM
27         )
28         list(APPEND dst_files ${dst_file})
29     endforeach ()
30     add_custom_target(${target_name} DEPENDS ${dst_files})
31 endfunction()
32
33 include(Compiler.cmake)
34 include(GLESv2.cmake)
35
36 if (WIN32)
37     # FIXME: DX11 support will not compile if this preprocessor definition is set
38     # DirectX Documentation is setting that version to 0x700 but there is no
39     # corresponding value in sdkddkver.h
40     remove_definitions(-D_WIN32_WINNT=0x601 -DWINVER=0x601)
41 endif ()
42
43 set(no_gl_prototypes
44     GL_GLES_PROTOTYPES=0
45     EGL_EGL_PROTOTYPES=0
46 )
47
48 set(gl_prototypes
49     GL_GLES_PROTOTYPES=1
50     EGL_EGL_PROTOTYPES=1
51     GL_GLEXT_PROTOTYPES
52     EGL_EGLEXT_PROTOTYPES
53 )
54
55 # ANGLE makes a number of small static libraries that are then joined into a
56 # bigger library that is built shared. Rather than making the small libraries
57 # there will be a ANGLE whose sources are dependent on whether the library
58 # is being used as a compiler or as a GLES implementation.
59 #
60 # The corresponding gn targets are described below
61 #
62 # ANGLE (Compiler only)
63 # + angle_common
64 # + preprocessor
65 # + translator
66 #
67 # ANGLE (GLES)
68 # + ANGLE (Compiler only)
69 # + xxhash
70 # + angle_image_util
71 # + angle_system_utils (OS specific)
72 # + angle_(renderer) (Backend and OS specific)
73
74 set(ANGLE_PRIVATE_INCLUDE_DIRECTORIES
75     "${CMAKE_CURRENT_SOURCE_DIR}/include"
76     "${CMAKE_CURRENT_SOURCE_DIR}/src"
77     "${CMAKE_CURRENT_SOURCE_DIR}/src/common/third_party/base"
78 )
79
80 set(ANGLE_DEFINITIONS
81     ANGLE_ENABLE_ESSL
82 )
83
84 set(ANGLE_SOURCES
85     ${libangle_common_sources}
86     ${angle_preprocessor_sources}
87     ${angle_translator_essl_sources}
88     ${angle_translator_glsl_sources}
89     ${angle_translator_sources}
90 )
91
92 set(ANGLEGLESv2_LIBRARIES
93     ANGLE
94 )
95
96 WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS()
97
98 add_subdirectory(include)
99
100 add_library(ANGLEFramework INTERFACE)
101 add_dependencies(ANGLEFramework GLSLANGHeaders ANGLEHeaders)
102
103 if (USE_ANGLE_EGL)
104     add_library(ANGLE STATIC
105         ${ANGLE_SOURCES}
106         ${libangle_sources}
107         ${libangle_image_util_sources}
108         ${xxhash_sources}
109     )
110     target_include_directories(ANGLE PRIVATE ${ANGLE_PRIVATE_INCLUDE_DIRECTORIES})
111     target_compile_definitions(ANGLE PRIVATE
112         ${no_gl_prototypes}
113         LIBANGLE_IMPLEMENTATION
114     )
115     target_compile_definitions(ANGLE PUBLIC ${ANGLE_DEFINITIONS})
116
117     add_library(GLESv2 SHARED ${libglesv2_sources})
118     target_include_directories(GLESv2 PRIVATE ${ANGLE_PRIVATE_INCLUDE_DIRECTORIES})
119     target_compile_definitions(GLESv2 PRIVATE LIBGLESV2_IMPLEMENTATION)
120     target_link_libraries(GLESv2 ${ANGLEGLESv2_LIBRARIES})
121
122     add_library(EGL SHARED ${libegl_sources})
123     target_include_directories(EGL PRIVATE ${ANGLE_PRIVATE_INCLUDE_DIRECTORIES})
124     target_compile_definitions(EGL PRIVATE
125         ${gl_prototypes}
126         EGLAPI=
127     )
128     target_link_libraries(EGL GLESv2)
129
130     if (WIN32)
131         target_sources(GLESv2 PRIVATE src/libGLESv2/libGLESv2_autogen.def)
132         target_sources(EGL PRIVATE src/libEGL/libEGL.def)
133
134         # Output library names according to the .def
135         set_target_properties(GLESv2 PROPERTIES OUTPUT_NAME libGLESv2)
136         set_target_properties(EGL PROPERTIES OUTPUT_NAME libEGL)
137     endif ()
138
139     target_link_libraries(ANGLEFramework INTERFACE EGL GLESv2)
140     target_compile_definitions(ANGLEFramework INTERFACE ${gl_prototypes})
141 else ()
142     add_library(ANGLE STATIC ${ANGLE_SOURCES})
143     target_include_directories(ANGLE PRIVATE ${ANGLE_PRIVATE_INCLUDE_DIRECTORIES})
144     target_compile_definitions(ANGLE PRIVATE
145         ${ANGLE_DEFINITIONS}
146         ${no_gl_prototypes}
147         LIBANGLE_IMPLEMENTATION
148     )
149 endif ()
150
151 if (COMPILER_IS_GCC_OR_CLANG)
152     WEBKIT_ADD_TARGET_CXX_FLAGS(ANGLE -Wno-cast-align
153                                       -Wno-suggest-attribute=format
154                                       -Wno-type-limits
155                                       -Wno-undef
156                                       -Wno-unused-parameter)
157 endif ()
158
159 target_link_libraries(ANGLEFramework INTERFACE ANGLE)
160 target_include_directories(ANGLEFramework INTERFACE ${ANGLE_FRAMEWORK_HEADERS_DIR})
161
162 set_property(DIRECTORY . PROPERTY FOLDER "ANGLE")