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