[CMake] Add possibility to overwrite WEBKIT_PORT_DIR in platform specific files
[WebKit-https.git] / Source / CMakeLists.txt
1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2 PROJECT(WebKit)
3
4 # Set a default build type if and only if user did not define one as command
5 # line options and he did not give custom CFLAGS or CXXFLAGS. Otherwise, flags
6 # from default build type would overwrite user-defined ones.
7 IF (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_C_FLAGS AND NOT CMAKE_CXX_FLAGS)
8     SET(CMAKE_BUILD_TYPE Release)
9 ENDIF ()
10 SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
11
12 # -----------------------------------------------------------------------------
13 # Default library type
14 # -----------------------------------------------------------------------------
15 IF (NOT ENABLE_WEBKIT AND NOT ENABLE_WEBKIT2)
16     SET(ENABLE_WEBKIT On)
17 ENDIF ()
18
19 SET(JAVASCRIPTCORE_DIR "${CMAKE_SOURCE_DIR}/JavaScriptCore")
20 SET(WEBCORE_DIR "${CMAKE_SOURCE_DIR}/WebCore")
21 SET(WEBKIT_DIR "${CMAKE_SOURCE_DIR}/WebKit")
22 SET(WEBKIT2_DIR "${CMAKE_SOURCE_DIR}/WebKit2")
23
24 SET(THIRDPARTY_DIR "${CMAKE_SOURCE_DIR}/ThirdParty")
25 SET(TOOLS_DIR "${CMAKE_SOURCE_DIR}/../Tools")
26
27 SET(DERIVED_SOURCES_DIR "${CMAKE_BINARY_DIR}/DerivedSources")
28 SET(DERIVED_SOURCES_JAVASCRIPTCORE_DIR "${CMAKE_BINARY_DIR}/DerivedSources/JavaScriptCore")
29 SET(DERIVED_SOURCES_WEBCORE_DIR "${CMAKE_BINARY_DIR}/DerivedSources/WebCore")
30 SET(DERIVED_SOURCES_WEBKIT2_DIR "${CMAKE_BINARY_DIR}/DerivedSources/WebKit2")
31
32 INCLUDE(WebKitMacros)
33 INCLUDE(WebKitFS)
34 INCLUDE(WebKitHelpers)
35 INCLUDE(WebKitFeatures)
36
37 # -----------------------------------------------------------------------------
38 # Determine which port will be built
39 # -----------------------------------------------------------------------------
40 SET(ALL_PORTS Efl WinCE)
41 SET(PORT "NOPORT" CACHE STRING "choose which WebKit port to build (one of ${ALL_PORTS})")
42
43 LIST(FIND ALL_PORTS ${PORT} RET)
44 IF (${RET} EQUAL -1)
45     MESSAGE(FATAL_ERROR "Please choose which WebKit port to build (one of ${ALL_PORTS})")
46 ENDIF ()
47
48 STRING(TOLOWER ${PORT} WEBKIT_PORT_DIR)
49
50 # -----------------------------------------------------------------------------
51 # Find common packages (used by all ports)
52 # -----------------------------------------------------------------------------
53 FIND_PACKAGE(BISON REQUIRED)
54 FIND_PACKAGE(FLEX REQUIRED)
55 FIND_PACKAGE(Gperf REQUIRED)
56 FIND_PACKAGE(Perl REQUIRED)
57 FIND_PACKAGE(PythonInterp REQUIRED)
58
59 # -----------------------------------------------------------------------------
60 # Determine the target processor
61 # -----------------------------------------------------------------------------
62 STRING(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
63 IF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
64     SET(WTF_CPU_ARM 1)
65 ELSEIF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
66     SET(WTF_CPU_MIPS 1)
67 ELSEIF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64)")
68     SET(WTF_CPU_X86_64 1)
69 ELSEIF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86)")
70     SET(WTF_CPU_X86 1)
71 ELSE ()
72     MESSAGE(FATAL_ERROR "Unknown CPU '${CMAKE_SYSTEM_PROCESSOR}'")
73 ENDIF ()
74
75 # -----------------------------------------------------------------------------
76 # Determine the operating system
77 # -----------------------------------------------------------------------------
78 IF (UNIX)
79     IF (APPLE)
80         SET(WTF_OS_MAC_OS_X 1)
81     ELSE ()
82         SET(WTF_OS_UNIX 1)
83     ENDIF ()
84 ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
85     SET(WTF_OS_WINDOWS 1)
86 ELSE ()
87     MESSAGE(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'")
88 ENDIF ()
89
90 # -----------------------------------------------------------------------------
91 # Default target names (can be overrriden in Options${PORT}.cmake file)
92 # -----------------------------------------------------------------------------
93 SET(JSC_EXECUTABLE_NAME JSC)
94 SET(WTF_LIBRARY_NAME WTF)
95 SET(JavaScriptCore_LIBRARY_NAME JavaScriptCore)
96 SET(WebCore_LIBRARY_NAME WebCore)
97 SET(WebKit_LIBRARY_NAME WebKit)
98 SET(WebKit2_LIBRARY_NAME WebKit2)
99
100 # -----------------------------------------------------------------------------
101 # Default library types
102 # -----------------------------------------------------------------------------
103 OPTION(SHARED_CORE "build WTF, JavaScriptCore and WebCore as shared libraries")
104
105 IF (SHARED_CORE)
106     SET(WTF_LIBRARY_TYPE SHARED)
107     SET(JavaScriptCore_LIBRARY_TYPE SHARED)
108     SET(WebCore_LIBRARY_TYPE SHARED)
109 ELSE ()
110     SET(WTF_LIBRARY_TYPE STATIC)
111     SET(JavaScriptCore_LIBRARY_TYPE STATIC)
112     SET(WebCore_LIBRARY_TYPE STATIC)
113 ENDIF ()
114
115 SET(WebKit_LIBRARY_TYPE SHARED)
116 SET(WebKit2_LIBRARY_TYPE SHARED)
117
118 # -----------------------------------------------------------------------------
119 # Port-specific options
120 # -----------------------------------------------------------------------------
121 INCLUDE(OptionsCommon)
122 INCLUDE(Options${PORT})
123
124 # -----------------------------------------------------------------------------
125 # Define packaging
126 # -----------------------------------------------------------------------------
127 INCLUDE(WebKitPackaging)
128
129 # -----------------------------------------------------------------------------
130 # Add module directories
131 # -----------------------------------------------------------------------------
132 ADD_SUBDIRECTORY(JavaScriptCore)
133 ADD_SUBDIRECTORY(WebCore)
134
135 IF (ENABLE_WEBKIT)
136     ADD_SUBDIRECTORY(WebKit)
137 ENDIF ()
138
139 IF (ENABLE_WEBKIT2)
140     ADD_SUBDIRECTORY(WebKit2)
141 ENDIF ()
142
143 # -----------------------------------------------------------------------------
144 # Install JavaScript shell
145 # -----------------------------------------------------------------------------
146 OPTION(SHOULD_INSTALL_JS_SHELL "generate an installation rule to install the built JavaScript shell")
147
148 # -----------------------------------------------------------------------------
149 # Add test browser if exists
150 # -----------------------------------------------------------------------------
151 INCLUDE_IF_EXISTS(${TOOLS_DIR}/CMakeLists${PORT}.txt)
152
153 # -----------------------------------------------------------------------------
154 # Set compiler flags for all targets
155 # -----------------------------------------------------------------------------
156 WEBKIT_SET_EXTRA_COMPILER_FLAGS(${WTF_LIBRARY_NAME})
157 WEBKIT_SET_EXTRA_COMPILER_FLAGS(${JavaScriptCore_LIBRARY_NAME})
158 WEBKIT_SET_EXTRA_COMPILER_FLAGS(${WebCore_LIBRARY_NAME})
159
160 IF (ENABLE_WEBKIT)
161     WEBKIT_SET_EXTRA_COMPILER_FLAGS(${WebKit_LIBRARY_NAME})
162 ENDIF ()
163
164 IF (ENABLE_WEBKIT2)
165     WEBKIT_SET_EXTRA_COMPILER_FLAGS(${WebKit2_LIBRARY_NAME})
166 ENDIF ()
167
168 # -----------------------------------------------------------------------------
169 # Create the configuration file
170 # -----------------------------------------------------------------------------
171 CONFIGURE_FILE(cmakeconfig.h.cmake ${CMAKE_BINARY_DIR}/cmakeconfig.h @ONLY)
172
173 # -----------------------------------------------------------------------------
174 # Prints a summary of all enabled/disabled features
175 # -----------------------------------------------------------------------------
176 WEBKIT_PRINT_FEATURES()