[macOS] Switching to discrete GPU should be done in the UI process
[WebKit-https.git] / CMakeLists.txt
1 # -----------------------------------------------------------------------------
2 # Determine CMake version and build type.
3 # -----------------------------------------------------------------------------
4 #
5 # NOTE: cmake_minimum_required() and project() *MUST* be the two fist commands
6 # used, see https://cmake.org/cmake/help/v3.3/command/project.html -- the
7 # latter in particular handles loading a bunch of shared CMake definitions
8 # and loading the cross-compilation settings from CMAKE_TOOLCHAIN_FILE.
9 #
10
11 cmake_minimum_required(VERSION 3.3)
12
13 project(WebKit)
14
15 if (NOT CMAKE_BUILD_TYPE)
16     message(WARNING "No CMAKE_BUILD_TYPE value specified, defaulting to RelWithDebInfo.")
17     set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build." FORCE)
18 else ()
19     message(STATUS "The CMake build type is: ${CMAKE_BUILD_TYPE}")
20 endif ()
21
22 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Source/cmake")
23
24 set(ENABLE_WEBCORE ON)
25
26 if (NOT DEFINED ENABLE_WEBKIT)
27     set(ENABLE_WEBKIT ON)
28 endif ()
29
30 if (NOT DEFINED ENABLE_TOOLS AND EXISTS "${CMAKE_SOURCE_DIR}/Tools")
31     set(ENABLE_TOOLS ON)
32 endif ()
33
34 # -----------------------------------------------------------------------------
35 # Determine which port will be built
36 # -----------------------------------------------------------------------------
37 set(ALL_PORTS
38     AppleWin
39     Efl
40     GTK
41     JSCOnly
42     Mac
43     WPE
44     WinCairo
45 )
46 set(PORT "NOPORT" CACHE STRING "choose which WebKit port to build (one of ${ALL_PORTS})")
47
48 list(FIND ALL_PORTS ${PORT} RET)
49 if (${RET} EQUAL -1)
50     message(FATAL_ERROR "Please choose which WebKit port to build (one of ${ALL_PORTS})")
51 endif ()
52
53 string(TOLOWER ${PORT} WEBKIT_PORT_DIR)
54
55 # -----------------------------------------------------------------------------
56 # Determine the compiler
57 # -----------------------------------------------------------------------------
58 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
59     set(COMPILER_IS_CLANG ON)
60 endif ()
61
62 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
63     if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "6.0.0")
64         message(FATAL_ERROR "GCC 6.0.0 is required to build WebKitGTK+, use a newer GCC version or clang")
65     endif ()
66 endif ()
67
68 if (CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG)
69     set(COMPILER_IS_GCC_OR_CLANG ON)
70 endif ()
71
72 if (MSVC AND COMPILER_IS_CLANG)
73     set(COMPILER_IS_CLANG_CL ON)
74 endif ()
75
76 # -----------------------------------------------------------------------------
77 # Determine the target processor
78 # -----------------------------------------------------------------------------
79 # Use MSVC_CXX_ARCHITECTURE_ID instead of CMAKE_SYSTEM_PROCESSOR when defined,
80 # since the later one just resolves to the host processor on Windows.
81 if (MSVC_CXX_ARCHITECTURE_ID)
82     string(TOLOWER ${MSVC_CXX_ARCHITECTURE_ID} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
83 else ()
84     string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
85 endif ()
86 if (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
87     set(WTF_CPU_ARM 1)
88 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
89     set(WTF_CPU_ARM64 1)
90 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^mips64")
91     set(WTF_CPU_MIPS64 1)
92 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
93     set(WTF_CPU_MIPS 1)
94 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(x64|x86_64|amd64)")
95     set(WTF_CPU_X86_64 1)
96 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86)")
97     set(WTF_CPU_X86 1)
98 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc")
99     set(WTF_CPU_PPC 1)
100 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
101     set(WTF_CPU_PPC64 1)
102 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
103     set(WTF_CPU_PPC64LE 1)
104 else ()
105     set(WTF_CPU_UNKNOWN 1)
106 endif ()
107
108 # -----------------------------------------------------------------------------
109 # Determine the operating system
110 # -----------------------------------------------------------------------------
111 if (UNIX)
112     if (APPLE)
113         set(WTF_OS_MAC_OS_X 1)
114     else ()
115         set(WTF_OS_UNIX 1)
116     endif ()
117 elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
118     set(WTF_OS_WINDOWS 1)
119 elseif (CMAKE_SYSTEM_NAME MATCHES "Fuchsia")
120     set(WTF_OS_FUCHSIA 1)
121 else ()
122     message(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'")
123 endif ()
124
125 # -----------------------------------------------------------------------------
126 # Default library types
127 # -----------------------------------------------------------------------------
128 # By default, only the highest-level libraries, WebKitLegacy and WebKit, are
129 # shared, because properly building shared libraries that depend on each other
130 # can be tricky. Override these in Options*.cmake for your port as needed.
131 set(WTF_LIBRARY_TYPE STATIC)
132 set(JavaScriptCore_LIBRARY_TYPE STATIC)
133 set(PAL_LIBRARY_TYPE STATIC)
134 set(WebCore_LIBRARY_TYPE STATIC)
135 set(WebKitLegacy_LIBRARY_TYPE SHARED)
136 set(WebKit_LIBRARY_TYPE SHARED)
137 set(WebCoreTestSupport_LIBRARY_TYPE STATIC)
138
139 set(CMAKE_POSITION_INDEPENDENT_CODE True)
140
141 # -----------------------------------------------------------------------------
142 # Install JavaScript shell
143 # -----------------------------------------------------------------------------
144 option(SHOULD_INSTALL_JS_SHELL "generate an installation rule to install the built JavaScript shell")
145
146 # -----------------------------------------------------------------------------
147 # Default output directories, which can be overwritten by ports
148 #------------------------------------------------------------------------------
149 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
150 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
151 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
152
153 # -----------------------------------------------------------------------------
154 # Common configuration
155 #------------------------------------------------------------------------------
156 include(WebKitCommon)
157
158 # -----------------------------------------------------------------------------
159 # Enable API unit tests and create a target for the test runner
160 # -----------------------------------------------------------------------------
161 if (ENABLE_API_TESTS)
162     enable_testing()
163 endif ()
164
165 # -----------------------------------------------------------------------------
166 # Add module directories
167 # -----------------------------------------------------------------------------
168 add_subdirectory(Source)
169
170 # -----------------------------------------------------------------------------
171 # Add tools
172 # -----------------------------------------------------------------------------
173 if (ENABLE_TOOLS)
174     add_subdirectory(Tools)
175 endif ()
176
177 if ("${PORT}" STREQUAL "GTK" OR "${PORT}" STREQUAL "WPE")
178     if (DEVELOPER_MODE)
179         add_subdirectory(PerformanceTests)
180     endif ()
181 else ()
182     add_subdirectory(PerformanceTests)
183 endif ()
184
185 # -----------------------------------------------------------------------------
186 # Print the features list last, for maximum visibility.
187 # -----------------------------------------------------------------------------
188 PRINT_WEBKIT_OPTIONS()