Move some commands from ./CMakeLists.txt to Source/cmake
[WebKit-https.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.12)
2 project(WebKit)
3
4 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Source/cmake")
5
6 if (NOT DEFINED ENABLE_WEBKIT)
7     set(ENABLE_WEBKIT ON)
8 endif ()
9
10 if (NOT DEFINED ENABLE_TOOLS AND EXISTS ${TOOLS_DIR})
11     set(ENABLE_TOOLS ON)
12 endif ()
13
14 include(WebKitMacros)
15 include(WebKitFS)
16 include(WebKitHelpers)
17 include(WebKitFeatures)
18
19 # -----------------------------------------------------------------------------
20 # Determine which port will be built
21 # -----------------------------------------------------------------------------
22 set(ALL_PORTS Efl GTK AppleWin WinCairo Mac)
23 set(PORT "NOPORT" CACHE STRING "choose which WebKit port to build (one of ${ALL_PORTS})")
24
25 list(FIND ALL_PORTS ${PORT} RET)
26 if (${RET} EQUAL -1)
27     message(FATAL_ERROR "Please choose which WebKit port to build (one of ${ALL_PORTS})")
28 endif ()
29
30 string(TOLOWER ${PORT} WEBKIT_PORT_DIR)
31
32 # -----------------------------------------------------------------------------
33 # Find common packages (used by all ports)
34 # -----------------------------------------------------------------------------
35 find_package(BISON 2.3 REQUIRED)
36 if (!APPLE)
37     find_package(FLEX 2.5.34 REQUIRED)
38 endif ()
39
40 # TODO Enforce version requirement for gperf
41 find_package(Gperf 3.0.1 REQUIRED)
42
43 # TODO Enforce version requirement for perl
44 find_package(Perl 5.10.0 REQUIRED)
45
46 find_package(PythonInterp 2.7.0 REQUIRED)
47
48 # We cannot check for RUBY_FOUND because it is set only when the full package is installed and
49 # the only thing we need is the interpreter. Unlike Python, cmake does not provide a macro
50 # for finding only the Ruby interpreter.
51 find_package(Ruby 1.8.7)
52 if (NOT RUBY_EXECUTABLE OR RUBY_VERSION VERSION_LESS 1.8.7)
53     message(FATAL_ERROR "Ruby 1.8.7 or higher is required.")
54 endif ()
55
56 # -----------------------------------------------------------------------------
57 # Determine the target processor
58 # -----------------------------------------------------------------------------
59 # Use MSVC_CXX_ARCHITECTURE_ID instead of CMAKE_SYSTEM_PROCESSOR when defined,
60 # since the later one just resolves to the host processor on Windows.
61 if (MSVC_CXX_ARCHITECTURE_ID)
62     string(TOLOWER ${MSVC_CXX_ARCHITECTURE_ID} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
63 else ()
64     string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
65 endif ()
66 if (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
67     set(WTF_CPU_ARM 1)
68 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
69     set(WTF_CPU_ARM64 1)
70 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
71     set(WTF_CPU_MIPS 1)
72 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "sh4")
73     set(WTF_CPU_SH4 1)
74 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(x64|x86_64|amd64)")
75     set(WTF_CPU_X86_64 1)
76 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86)")
77     set(WTF_CPU_X86 1)
78 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc")
79     set(WTF_CPU_PPC 1)
80 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
81     set(WTF_CPU_PPC64 1)
82 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le")
83     set(WTF_CPU_PPC64LE 1)
84 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "parisc*")
85     set(WTF_CPU_HPPA 1)
86 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "s390")
87     set(WTF_CPU_S390 1)
88 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
89     set(WTF_CPU_S390X 1)
90 else ()
91     message(FATAL_ERROR "Unknown CPU '${LOWERCASE_CMAKE_SYSTEM_PROCESSOR}'")
92 endif ()
93
94 # -----------------------------------------------------------------------------
95 # Determine the operating system
96 # -----------------------------------------------------------------------------
97 if (UNIX)
98     if (APPLE)
99         set(WTF_OS_MAC_OS_X 1)
100     else ()
101         set(WTF_OS_UNIX 1)
102     endif ()
103 elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
104     set(WTF_OS_WINDOWS 1)
105 else ()
106     message(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'")
107 endif ()
108
109 # -----------------------------------------------------------------------------
110 # Default library types
111 # -----------------------------------------------------------------------------
112 option(SHARED_CORE "build JavaScriptCore and WebCore as shared libraries")
113
114 if (SHARED_CORE)
115     set(JavaScriptCore_LIBRARY_TYPE SHARED)
116     set(WebCore_LIBRARY_TYPE SHARED)
117 else ()
118     set(JavaScriptCore_LIBRARY_TYPE SHARED)
119     set(WebCore_LIBRARY_TYPE STATIC)
120 endif ()
121
122 set(WebKit_LIBRARY_TYPE SHARED)
123 set(WebKit2_LIBRARY_TYPE SHARED)
124 set(WebCoreTestSupport_LIBRARY_TYPE STATIC)
125
126 # -----------------------------------------------------------------------------
127 # Install JavaScript shell
128 # -----------------------------------------------------------------------------
129 option(SHOULD_INSTALL_JS_SHELL "generate an installation rule to install the built JavaScript shell")
130
131 # -----------------------------------------------------------------------------
132 # Common options
133 #------------------------------------------------------------------------------
134 include(OptionsCommon)
135 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
136 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
137 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
138
139 # -----------------------------------------------------------------------------
140 # Port-specific options
141 # -----------------------------------------------------------------------------
142 include(Options${PORT})
143
144 # -----------------------------------------------------------------------------
145 # Enable API unit tests and create a target for the test runner
146 # -----------------------------------------------------------------------------
147 if (ENABLE_API_TESTS)
148     enable_testing()
149 endif ()
150
151 # -----------------------------------------------------------------------------
152 # Define packaging
153 # -----------------------------------------------------------------------------
154 include(WebKitPackaging)
155
156 # -----------------------------------------------------------------------------
157 # Add module directories
158 # -----------------------------------------------------------------------------
159 add_subdirectory(Source)
160
161 # -----------------------------------------------------------------------------
162 # Add tools
163 # -----------------------------------------------------------------------------
164 if (ENABLE_TOOLS)
165     add_subdirectory(Tools)
166 endif ()
167
168 # -----------------------------------------------------------------------------
169 # Print the features list last, for maximum visibility.
170 # -----------------------------------------------------------------------------
171 PRINT_WEBKIT_OPTIONS()
172
173 # -----------------------------------------------------------------------------
174 # Create the configuration header
175 # -----------------------------------------------------------------------------
176 CREATE_CONFIGURATION_HEADER()