1 # -----------------------------------------------------------------------------
2 # Determine CMake version and build type.
3 # -----------------------------------------------------------------------------
5 # NOTE: cmake_minimum_required() and project() *MUST* be the two first 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.
11 cmake_minimum_required(VERSION 3.10)
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)
19 message(STATUS "The CMake build type is: ${CMAKE_BUILD_TYPE}")
22 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Source/cmake")
24 set(ENABLE_WEBCORE ON)
26 if (NOT DEFINED ENABLE_WEBKIT)
30 if (NOT DEFINED ENABLE_TOOLS AND EXISTS "${CMAKE_SOURCE_DIR}/Tools")
34 # -----------------------------------------------------------------------------
35 # Determine which port will be built
36 # -----------------------------------------------------------------------------
49 set(PORT "Qt" CACHE STRING "choose which WebKit port to build (one of ${ALL_PORTS})")
51 list(FIND ALL_PORTS ${PORT} RET)
53 message(FATAL_ERROR "Please choose which WebKit port to build (one of ${ALL_PORTS})")
56 string(TOLOWER ${PORT} WEBKIT_PORT_DIR)
58 # -----------------------------------------------------------------------------
59 # Determine the compiler
60 # -----------------------------------------------------------------------------
61 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
62 set(COMPILER_IS_CLANG ON)
65 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
66 if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "7.3.0")
67 message(FATAL_ERROR "GCC 7.3 or newer is required to build WebKit. Use a newer GCC version or Clang.")
71 if (CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG)
72 set(COMPILER_IS_GCC_OR_CLANG ON)
75 if (MSVC AND COMPILER_IS_CLANG)
76 set(COMPILER_IS_CLANG_CL ON)
79 # -----------------------------------------------------------------------------
80 # Determine the target processor
81 # -----------------------------------------------------------------------------
82 # Use MSVC_CXX_ARCHITECTURE_ID instead of CMAKE_SYSTEM_PROCESSOR when defined,
83 # since the later one just resolves to the host processor on Windows.
84 if (MSVC_CXX_ARCHITECTURE_ID)
85 string(TOLOWER ${MSVC_CXX_ARCHITECTURE_ID} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
87 string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
89 if (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(^aarch64|^arm64)")
91 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
93 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^mips64")
95 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
97 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(x64|x86_64|amd64)")
98 # FORCE_32BIT is set in the build script when --32-bit is passed
99 # on a Linux/intel 64bit host. This allows us to produce 32bit
100 # binaries without setting the build up as a crosscompilation,
101 # which is the only way to modify CMAKE_SYSTEM_PROCESSOR.
105 set(WTF_CPU_X86_64 1)
107 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86)")
109 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc")
111 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
113 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
114 set(WTF_CPU_PPC64LE 1)
116 set(WTF_CPU_UNKNOWN 1)
119 # -----------------------------------------------------------------------------
120 # Determine the operating system
121 # -----------------------------------------------------------------------------
124 set(WTF_OS_MAC_OS_X 1)
125 elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
130 elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
131 set(WTF_OS_WINDOWS 1)
132 elseif (CMAKE_SYSTEM_NAME MATCHES "Fuchsia")
133 set(WTF_OS_FUCHSIA 1)
135 message(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'")
138 # -----------------------------------------------------------------------------
139 # Default library types
140 # -----------------------------------------------------------------------------
141 # By default, only the highest-level libraries, WebKitLegacy and WebKit, are
142 # shared, because properly building shared libraries that depend on each other
143 # can be tricky. Override these in Options*.cmake for your port as needed.
144 set(bmalloc_LIBRARY_TYPE STATIC)
145 set(WTF_LIBRARY_TYPE STATIC)
146 set(JavaScriptCore_LIBRARY_TYPE STATIC)
147 set(PAL_LIBRARY_TYPE STATIC)
148 set(WebCore_LIBRARY_TYPE STATIC)
149 set(WebKitLegacy_LIBRARY_TYPE SHARED)
150 set(WebKit_LIBRARY_TYPE SHARED)
151 set(WebCoreTestSupport_LIBRARY_TYPE STATIC)
153 set(CMAKE_POSITION_INDEPENDENT_CODE True)
155 # -----------------------------------------------------------------------------
156 # Install JavaScript shell
157 # -----------------------------------------------------------------------------
158 option(SHOULD_INSTALL_JS_SHELL "generate an installation rule to install the built JavaScript shell")
160 # -----------------------------------------------------------------------------
161 # Default output directories, which can be overwritten by ports
162 #------------------------------------------------------------------------------
163 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
164 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
165 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
167 # -----------------------------------------------------------------------------
168 # Common configuration
169 #------------------------------------------------------------------------------
170 include(WebKitCommon)
172 # -----------------------------------------------------------------------------
173 # Enable API unit tests and create a target for the test runner
174 # -----------------------------------------------------------------------------
175 if (ENABLE_API_TESTS)
178 # Qt API tests are at top level because of Coin requirements
179 if (${PORT} STREQUAL "Qt")
180 add_subdirectory(tests)
184 # -----------------------------------------------------------------------------
185 # Add module directories
186 # -----------------------------------------------------------------------------
187 add_subdirectory(Source)
189 # -----------------------------------------------------------------------------
191 # -----------------------------------------------------------------------------
193 add_subdirectory(Tools)
196 if ("${PORT}" STREQUAL "GTK" OR "${PORT}" STREQUAL "WPE" OR "${PORT}" STREQUAL "Qt")
198 add_subdirectory(PerformanceTests)
201 add_subdirectory(PerformanceTests)
204 # -----------------------------------------------------------------------------
205 # Print the features list last, for maximum visibility.
206 # -----------------------------------------------------------------------------
207 PRINT_WEBKIT_OPTIONS()