7c69c39bb7321d915db1afa96b4dfb21aa77b507
[WebKit-https.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.12)
2 project(WebKit)
3
4 # This should be removed once we require CMake 3.3.
5 if (POLICY CMP0058)
6     cmake_policy(SET CMP0058 NEW)
7 endif ()
8
9 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Source/cmake")
10
11 set(ENABLE_WEBCORE ON)
12
13 if (NOT DEFINED ENABLE_WEBKIT)
14     set(ENABLE_WEBKIT ON)
15 endif ()
16
17 if (NOT DEFINED ENABLE_TOOLS AND EXISTS "${CMAKE_SOURCE_DIR}/Tools")
18     set(ENABLE_TOOLS ON)
19 endif ()
20
21 # -----------------------------------------------------------------------------
22 # Determine which port will be built
23 # -----------------------------------------------------------------------------
24 set(ALL_PORTS
25     AppleWin
26     Efl
27     GTK
28     JSCOnly
29     Mac
30     WPE
31     WinCairo
32 )
33 set(PORT "NOPORT" CACHE STRING "choose which WebKit port to build (one of ${ALL_PORTS})")
34
35 list(FIND ALL_PORTS ${PORT} RET)
36 if (${RET} EQUAL -1)
37     message(FATAL_ERROR "Please choose which WebKit port to build (one of ${ALL_PORTS})")
38 endif ()
39
40 string(TOLOWER ${PORT} WEBKIT_PORT_DIR)
41
42 # -----------------------------------------------------------------------------
43 # Determine the compiler
44 # -----------------------------------------------------------------------------
45 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang")
46     set(COMPILER_IS_CLANG ON)
47 endif ()
48
49 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
50     if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "5.0.0")
51         message(FATAL_ERROR "GCC 5.0.0 is required to build WebKitGTK+, use a newer GCC version or clang")
52     endif ()
53 endif ()
54
55 if (CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG)
56     set(COMPILER_IS_GCC_OR_CLANG ON)
57 endif ()
58
59 if (MSVC AND COMPILER_IS_CLANG)
60     set(COMPILER_IS_CLANG_CL ON)
61 endif ()
62
63 # -----------------------------------------------------------------------------
64 # Determine the target processor
65 # -----------------------------------------------------------------------------
66 # Use MSVC_CXX_ARCHITECTURE_ID instead of CMAKE_SYSTEM_PROCESSOR when defined,
67 # since the later one just resolves to the host processor on Windows.
68 if (MSVC_CXX_ARCHITECTURE_ID)
69     string(TOLOWER ${MSVC_CXX_ARCHITECTURE_ID} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
70 else ()
71     string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
72 endif ()
73 if (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
74     set(WTF_CPU_ARM 1)
75 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
76     set(WTF_CPU_ARM64 1)
77 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
78     set(WTF_CPU_MIPS 1)
79 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "sh4")
80     set(WTF_CPU_SH4 1)
81 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(x64|x86_64|amd64)")
82     set(WTF_CPU_X86_64 1)
83 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86)")
84     set(WTF_CPU_X86 1)
85 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc")
86     set(WTF_CPU_PPC 1)
87 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
88     set(WTF_CPU_PPC64 1)
89 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
90     set(WTF_CPU_PPC64LE 1)
91 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "parisc*")
92     set(WTF_CPU_HPPA 1)
93 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "s390")
94     set(WTF_CPU_S390 1)
95 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
96     set(WTF_CPU_S390X 1)
97 else ()
98     message(FATAL_ERROR "Unknown CPU '${LOWERCASE_CMAKE_SYSTEM_PROCESSOR}'")
99 endif ()
100
101 # -----------------------------------------------------------------------------
102 # Determine the operating system
103 # -----------------------------------------------------------------------------
104 if (UNIX)
105     if (APPLE)
106         set(WTF_OS_MAC_OS_X 1)
107     else ()
108         set(WTF_OS_UNIX 1)
109     endif ()
110 elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
111     set(WTF_OS_WINDOWS 1)
112 else ()
113     message(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'")
114 endif ()
115
116 # -----------------------------------------------------------------------------
117 # Default library types
118 # -----------------------------------------------------------------------------
119 option(SHARED_CORE "build WebCore as a shared library")
120
121 if (SHARED_CORE)
122     set(WebCore_LIBRARY_TYPE SHARED)
123 else ()
124     set(WebCore_LIBRARY_TYPE STATIC)
125 endif ()
126
127 set(JavaScriptCore_LIBRARY_TYPE SHARED)
128 set(PAL_LIBRARY_TYPE STATIC)
129 set(WebKit_LIBRARY_TYPE SHARED)
130 set(WebKit2_LIBRARY_TYPE SHARED)
131 set(WebCoreTestSupport_LIBRARY_TYPE STATIC)
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 # Define packaging
159 # -----------------------------------------------------------------------------
160 include(WebKitPackaging)
161
162 # -----------------------------------------------------------------------------
163 # Add module directories
164 # -----------------------------------------------------------------------------
165 add_subdirectory(Source)
166
167 # -----------------------------------------------------------------------------
168 # Add tools
169 # -----------------------------------------------------------------------------
170 if (ENABLE_TOOLS)
171     add_subdirectory(Tools)
172 endif ()
173
174 # -----------------------------------------------------------------------------
175 # Print the features list last, for maximum visibility.
176 # -----------------------------------------------------------------------------
177 PRINT_WEBKIT_OPTIONS()