4c3b940995d8da3682d708ecaf31fc95cdabc5a4
[WebKit-https.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.3)
2 project(WebKit)
3
4 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Source/cmake")
5
6 set(ENABLE_WEBCORE ON)
7
8 if (NOT DEFINED ENABLE_WEBKIT)
9     set(ENABLE_WEBKIT ON)
10 endif ()
11
12 if (NOT DEFINED ENABLE_TOOLS AND EXISTS "${CMAKE_SOURCE_DIR}/Tools")
13     set(ENABLE_TOOLS ON)
14 endif ()
15
16 # -----------------------------------------------------------------------------
17 # Determine which port will be built
18 # -----------------------------------------------------------------------------
19 set(ALL_PORTS
20     AppleWin
21     Efl
22     GTK
23     JSCOnly
24     Mac
25     WPE
26     WinCairo
27 )
28 set(PORT "NOPORT" CACHE STRING "choose which WebKit port to build (one of ${ALL_PORTS})")
29
30 list(FIND ALL_PORTS ${PORT} RET)
31 if (${RET} EQUAL -1)
32     message(FATAL_ERROR "Please choose which WebKit port to build (one of ${ALL_PORTS})")
33 endif ()
34
35 string(TOLOWER ${PORT} WEBKIT_PORT_DIR)
36
37 # -----------------------------------------------------------------------------
38 # Determine the compiler
39 # -----------------------------------------------------------------------------
40 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
41     set(COMPILER_IS_CLANG ON)
42 endif ()
43
44 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
45     if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "5.0.0")
46         message(FATAL_ERROR "GCC 5.0.0 is required to build WebKitGTK+, use a newer GCC version or clang")
47     endif ()
48 endif ()
49
50 if (CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG)
51     set(COMPILER_IS_GCC_OR_CLANG ON)
52 endif ()
53
54 if (MSVC AND COMPILER_IS_CLANG)
55     set(COMPILER_IS_CLANG_CL ON)
56 endif ()
57
58 # -----------------------------------------------------------------------------
59 # Determine the target processor
60 # -----------------------------------------------------------------------------
61 # Use MSVC_CXX_ARCHITECTURE_ID instead of CMAKE_SYSTEM_PROCESSOR when defined,
62 # since the later one just resolves to the host processor on Windows.
63 if (MSVC_CXX_ARCHITECTURE_ID)
64     string(TOLOWER ${MSVC_CXX_ARCHITECTURE_ID} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
65 else ()
66     string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
67 endif ()
68 if (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
69     set(WTF_CPU_ARM 1)
70 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
71     set(WTF_CPU_ARM64 1)
72 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "alpha*")
73     set(WTF_CPU_ALPHA 1)
74 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
75     set(WTF_CPU_MIPS 1)
76 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "sh4")
77     set(WTF_CPU_SH4 1)
78 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(x64|x86_64|amd64)")
79     set(WTF_CPU_X86_64 1)
80 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86)")
81     set(WTF_CPU_X86 1)
82 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc")
83     set(WTF_CPU_PPC 1)
84 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
85     set(WTF_CPU_PPC64 1)
86 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
87     set(WTF_CPU_PPC64LE 1)
88 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "parisc*")
89     set(WTF_CPU_HPPA 1)
90 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "s390")
91     set(WTF_CPU_S390 1)
92 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
93     set(WTF_CPU_S390X 1)
94 else ()
95     message(FATAL_ERROR "Unknown CPU '${LOWERCASE_CMAKE_SYSTEM_PROCESSOR}'")
96 endif ()
97
98 # -----------------------------------------------------------------------------
99 # Determine the operating system
100 # -----------------------------------------------------------------------------
101 if (UNIX)
102     if (APPLE)
103         set(WTF_OS_MAC_OS_X 1)
104     else ()
105         set(WTF_OS_UNIX 1)
106     endif ()
107 elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
108     set(WTF_OS_WINDOWS 1)
109 else ()
110     message(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'")
111 endif ()
112
113 # -----------------------------------------------------------------------------
114 # Default library types
115 # -----------------------------------------------------------------------------
116 option(SHARED_CORE "build WebCore as a shared library")
117
118 if (SHARED_CORE)
119     set(WebCore_LIBRARY_TYPE SHARED)
120 else ()
121     set(WebCore_LIBRARY_TYPE STATIC)
122 endif ()
123
124 set(WTF_LIBRARY_TYPE STATIC)
125 set(JavaScriptCore_LIBRARY_TYPE SHARED)
126 set(PAL_LIBRARY_TYPE STATIC)
127 set(WebKitLegacy_LIBRARY_TYPE SHARED)
128 set(WebKit_LIBRARY_TYPE SHARED)
129 set(WebCoreTestSupport_LIBRARY_TYPE STATIC)
130
131 set(CMAKE_POSITION_INDEPENDENT_CODE True)
132
133 # -----------------------------------------------------------------------------
134 # Install JavaScript shell
135 # -----------------------------------------------------------------------------
136 option(SHOULD_INSTALL_JS_SHELL "generate an installation rule to install the built JavaScript shell")
137
138 # -----------------------------------------------------------------------------
139 # Default output directories, which can be overwritten by ports
140 #------------------------------------------------------------------------------
141 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
142 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
143 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
144
145 # -----------------------------------------------------------------------------
146 # Common configuration
147 #------------------------------------------------------------------------------
148 include(WebKitCommon)
149
150 # -----------------------------------------------------------------------------
151 # Enable API unit tests and create a target for the test runner
152 # -----------------------------------------------------------------------------
153 if (ENABLE_API_TESTS)
154     enable_testing()
155 endif ()
156
157 # -----------------------------------------------------------------------------
158 # Add module directories
159 # -----------------------------------------------------------------------------
160 add_subdirectory(Source)
161
162 # -----------------------------------------------------------------------------
163 # Add tools
164 # -----------------------------------------------------------------------------
165 if (ENABLE_TOOLS)
166     add_subdirectory(Tools)
167 endif ()
168
169 # -----------------------------------------------------------------------------
170 # Print the features list last, for maximum visibility.
171 # -----------------------------------------------------------------------------
172 PRINT_WEBKIT_OPTIONS()