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