[CMake] Properly test if compiler supports compiler flags
[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 "^mips")
73     set(WTF_CPU_MIPS 1)
74 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "sh4")
75     set(WTF_CPU_SH4 1)
76 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(x64|x86_64|amd64)")
77     set(WTF_CPU_X86_64 1)
78 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86)")
79     set(WTF_CPU_X86 1)
80 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc")
81     set(WTF_CPU_PPC 1)
82 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
83     set(WTF_CPU_PPC64 1)
84 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
85     set(WTF_CPU_PPC64LE 1)
86 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "parisc*")
87     set(WTF_CPU_HPPA 1)
88 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "s390")
89     set(WTF_CPU_S390 1)
90 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
91     set(WTF_CPU_S390X 1)
92 else ()
93     message(FATAL_ERROR "Unknown CPU '${LOWERCASE_CMAKE_SYSTEM_PROCESSOR}'")
94 endif ()
95
96 # -----------------------------------------------------------------------------
97 # Determine the operating system
98 # -----------------------------------------------------------------------------
99 if (UNIX)
100     if (APPLE)
101         set(WTF_OS_MAC_OS_X 1)
102     else ()
103         set(WTF_OS_UNIX 1)
104     endif ()
105 elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
106     set(WTF_OS_WINDOWS 1)
107 else ()
108     message(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'")
109 endif ()
110
111 # -----------------------------------------------------------------------------
112 # Default library types
113 # -----------------------------------------------------------------------------
114 option(SHARED_CORE "build WebCore as a shared library")
115
116 if (SHARED_CORE)
117     set(WebCore_LIBRARY_TYPE SHARED)
118 else ()
119     set(WebCore_LIBRARY_TYPE STATIC)
120 endif ()
121
122 set(WTF_LIBRARY_TYPE STATIC)
123 set(JavaScriptCore_LIBRARY_TYPE SHARED)
124 set(PAL_LIBRARY_TYPE STATIC)
125 set(WebKit_LIBRARY_TYPE SHARED)
126 set(WebKit2_LIBRARY_TYPE SHARED)
127 set(WebCoreTestSupport_LIBRARY_TYPE STATIC)
128
129 set(CMAKE_POSITION_INDEPENDENT_CODE True)
130
131 # -----------------------------------------------------------------------------
132 # Install JavaScript shell
133 # -----------------------------------------------------------------------------
134 option(SHOULD_INSTALL_JS_SHELL "generate an installation rule to install the built JavaScript shell")
135
136 # -----------------------------------------------------------------------------
137 # Default output directories, which can be overwritten by ports
138 #------------------------------------------------------------------------------
139 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
140 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
141 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
142
143 # -----------------------------------------------------------------------------
144 # Common configuration
145 #------------------------------------------------------------------------------
146 include(WebKitCommon)
147
148 # -----------------------------------------------------------------------------
149 # Enable API unit tests and create a target for the test runner
150 # -----------------------------------------------------------------------------
151 if (ENABLE_API_TESTS)
152     enable_testing()
153 endif ()
154
155 # -----------------------------------------------------------------------------
156 # Add module directories
157 # -----------------------------------------------------------------------------
158 add_subdirectory(Source)
159
160 # -----------------------------------------------------------------------------
161 # Add tools
162 # -----------------------------------------------------------------------------
163 if (ENABLE_TOOLS)
164     add_subdirectory(Tools)
165 endif ()
166
167 # -----------------------------------------------------------------------------
168 # Print the features list last, for maximum visibility.
169 # -----------------------------------------------------------------------------
170 PRINT_WEBKIT_OPTIONS()