2011-06-23 Wyatt Carss <wcarss@chromium.org>
[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 # -----------------------------------------------------------------------------
49 # Find common packages (used by all ports)
50 # -----------------------------------------------------------------------------
51 FIND_PACKAGE(BISON REQUIRED)
52 FIND_PACKAGE(FLEX REQUIRED)
53 FIND_PACKAGE(Gperf REQUIRED)
54 FIND_PACKAGE(Perl REQUIRED)
55 FIND_PACKAGE(PythonInterp REQUIRED)
56
57 # -----------------------------------------------------------------------------
58 # Determine the target processor
59 # -----------------------------------------------------------------------------
60 STRING(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
61 IF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
62     SET(WTF_CPU_ARM 1)
63 ELSEIF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)")
64     SET(WTF_CPU_X86_64 1)
65 ELSEIF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86)")
66     SET(WTF_CPU_X86 1)
67 ELSE ()
68     MESSAGE(FATAL_ERROR "Unknown CPU '${CMAKE_SYSTEM_PROCESSOR}'")
69 ENDIF ()
70
71 # -----------------------------------------------------------------------------
72 # Determine the operating system
73 # -----------------------------------------------------------------------------
74 IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
75     SET(WTF_OS_UNIX 1)
76
77     IF (APPLE)
78         SET(WTF_OS_MAC_OS_X 1)
79     ENDIF ()
80 ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
81     SET(WTF_OS_WINDOWS 1)
82 ELSE ()
83     MESSAGE(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'")
84 ENDIF ()
85
86 # -----------------------------------------------------------------------------
87 # Default target names (can be overrriden in Options${PORT}.cmake file)
88 # -----------------------------------------------------------------------------
89 SET(JSC_EXECUTABLE_NAME JSC)
90 SET(WTF_LIBRARY_NAME WTF)
91 SET(JavaScriptCore_LIBRARY_NAME JavaScriptCore)
92 SET(WebCore_LIBRARY_NAME WebCore)
93 SET(WebKit_LIBRARY_NAME WebKit)
94 SET(WebKit2_LIBRARY_NAME WebKit2)
95
96 # -----------------------------------------------------------------------------
97 # Default library types
98 # -----------------------------------------------------------------------------
99 OPTION(SHARED_CORE "build WTF, JavaScriptCore and WebCore as shared libraries")
100
101 IF (SHARED_CORE)
102     SET(WTF_LIBRARY_TYPE SHARED)
103     SET(JavaScriptCore_LIBRARY_TYPE SHARED)
104     SET(WebCore_LIBRARY_TYPE SHARED)
105 ELSE ()
106     SET(WTF_LIBRARY_TYPE STATIC)
107     SET(JavaScriptCore_LIBRARY_TYPE STATIC)
108     SET(WebCore_LIBRARY_TYPE STATIC)
109 ENDIF ()
110
111 SET(WebKit_LIBRARY_TYPE SHARED)
112 SET(WebKit2_LIBRARY_TYPE SHARED)
113
114 # -----------------------------------------------------------------------------
115 # Port-specific options
116 # -----------------------------------------------------------------------------
117 INCLUDE(OptionsCommon)
118 INCLUDE(Options${PORT})
119
120 # -----------------------------------------------------------------------------
121 # Define packaging
122 # -----------------------------------------------------------------------------
123 INCLUDE(WebKitPackaging)
124
125 # -----------------------------------------------------------------------------
126 # Add module directories
127 # -----------------------------------------------------------------------------
128 ADD_SUBDIRECTORY(JavaScriptCore)
129 ADD_SUBDIRECTORY(WebCore)
130
131 IF (ENABLE_WEBKIT)
132     ADD_SUBDIRECTORY(WebKit)
133 ENDIF ()
134
135 IF (ENABLE_WEBKIT2)
136     ADD_SUBDIRECTORY(WebKit2)
137 ENDIF ()
138
139 # -----------------------------------------------------------------------------
140 # Add test browser if exists
141 # -----------------------------------------------------------------------------
142 INCLUDE_IF_EXISTS(${TOOLS_DIR}/CMakeLists${PORT}.txt)
143
144 # -----------------------------------------------------------------------------
145 # Set compiler flags for all targets
146 # -----------------------------------------------------------------------------
147 WEBKIT_SET_EXTRA_COMPILER_FLAGS(${WTF_LIBRARY_NAME})
148 WEBKIT_SET_EXTRA_COMPILER_FLAGS(${JavaScriptCore_LIBRARY_NAME})
149 WEBKIT_SET_EXTRA_COMPILER_FLAGS(${WebCore_LIBRARY_NAME})
150
151 IF (ENABLE_WEBKIT)
152     WEBKIT_SET_EXTRA_COMPILER_FLAGS(${WebKit_LIBRARY_NAME})
153 ENDIF ()
154
155 IF (ENABLE_WEBKIT2)
156     WEBKIT_SET_EXTRA_COMPILER_FLAGS(${WebKit2_LIBRARY_NAME})
157 ENDIF ()
158
159 # -----------------------------------------------------------------------------
160 # Create the configuration file
161 # -----------------------------------------------------------------------------
162 CONFIGURE_FILE(cmakeconfig.h.cmake ${CMAKE_BINARY_DIR}/cmakeconfig.h @ONLY)
163
164 # -----------------------------------------------------------------------------
165 # Prints a summary of all enabled/disabled features
166 # -----------------------------------------------------------------------------
167 WEBKIT_PRINT_FEATURES()