[CMake] Share build system options across ports
[WebKit-https.git] / 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
11 # -----------------------------------------------------------------------------
12 # Default library type
13 # -----------------------------------------------------------------------------
14 SET(ENABLE_WEBCORE ON)
15
16 IF (NOT ENABLE_WEBKIT AND NOT ENABLE_WEBKIT2)
17     SET(ENABLE_WEBKIT ON)
18 ENDIF ()
19
20 SET(ENABLE_TOOLS ON)
21
22 OPTION(ONLY_BUILD_JAVASCRIPTCORE "only build JavaScriptCore")
23 IF (ONLY_BUILD_JAVASCRIPTCORE)
24     SET(ENABLE_WEBCORE OFF)
25     SET(ENABLE_WEBKIT OFF)
26     SET(ENABLE_WEBKIT2 OFF)
27     SET(ENABLE_TOOLS OFF)
28 ENDIF ()
29
30 SET(WTF_DIR "${CMAKE_SOURCE_DIR}/Source/WTF")
31 SET(JAVASCRIPTCORE_DIR "${CMAKE_SOURCE_DIR}/Source/JavaScriptCore")
32 SET(WEBCORE_DIR "${CMAKE_SOURCE_DIR}/Source/WebCore")
33 SET(WEBKIT_DIR "${CMAKE_SOURCE_DIR}/Source/WebKit")
34 SET(WEBKIT2_DIR "${CMAKE_SOURCE_DIR}/Source/WebKit2")
35 SET(THIRDPARTY_DIR "${CMAKE_SOURCE_DIR}/Source/ThirdParty")
36
37 SET(TOOLS_DIR "${CMAKE_SOURCE_DIR}/Tools")
38
39 SET(DERIVED_SOURCES_DIR "${CMAKE_BINARY_DIR}/DerivedSources")
40 SET(DERIVED_SOURCES_JAVASCRIPTCORE_DIR "${CMAKE_BINARY_DIR}/DerivedSources/JavaScriptCore")
41 SET(DERIVED_SOURCES_WEBCORE_DIR "${CMAKE_BINARY_DIR}/DerivedSources/WebCore")
42 SET(DERIVED_SOURCES_WEBKIT2_DIR "${CMAKE_BINARY_DIR}/DerivedSources/WebKit2")
43
44 SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Source/cmake")
45
46 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
47 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
48 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
49
50 INCLUDE(WebKitMacros)
51 INCLUDE(WebKitFS)
52 INCLUDE(WebKitHelpers)
53 INCLUDE(WebKitFeatures)
54
55 # -----------------------------------------------------------------------------
56 # Determine which port will be built
57 # -----------------------------------------------------------------------------
58 SET(ALL_PORTS Efl WinCE BlackBerry)
59 SET(PORT "NOPORT" CACHE STRING "choose which WebKit port to build (one of ${ALL_PORTS})")
60
61 LIST(FIND ALL_PORTS ${PORT} RET)
62 IF (${RET} EQUAL -1)
63     MESSAGE(FATAL_ERROR "Please choose which WebKit port to build (one of ${ALL_PORTS})")
64 ENDIF ()
65
66 STRING(TOLOWER ${PORT} WEBKIT_PORT_DIR)
67
68 # -----------------------------------------------------------------------------
69 # Find common packages (used by all ports)
70 # -----------------------------------------------------------------------------
71 FIND_PACKAGE(BISON REQUIRED)
72 FIND_PACKAGE(FLEX REQUIRED)
73 FIND_PACKAGE(Gperf REQUIRED)
74 FIND_PACKAGE(Perl REQUIRED)
75 FIND_PACKAGE(PythonInterp REQUIRED)
76
77 # -----------------------------------------------------------------------------
78 # Determine the target processor
79 # -----------------------------------------------------------------------------
80 STRING(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} LOWERCASE_CMAKE_SYSTEM_PROCESSOR)
81 IF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
82     SET(WTF_CPU_ARM 1)
83 ELSEIF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
84     SET(WTF_CPU_MIPS 1)
85 ELSEIF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64)")
86     SET(WTF_CPU_X86_64 1)
87 ELSEIF (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "(i[3-6]86|x86)")
88     SET(WTF_CPU_X86 1)
89 ELSE ()
90     MESSAGE(FATAL_ERROR "Unknown CPU '${CMAKE_SYSTEM_PROCESSOR}'")
91 ENDIF ()
92
93 # -----------------------------------------------------------------------------
94 # Determine the operating system
95 # -----------------------------------------------------------------------------
96 IF (UNIX)
97     IF (APPLE)
98         SET(WTF_OS_MAC_OS_X 1)
99     ELSE ()
100         SET(WTF_OS_UNIX 1)
101     ENDIF ()
102 ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
103     SET(WTF_OS_WINDOWS 1)
104 ELSEIF (CMAKE_SYSTEM_NAME MATCHES "QNX")
105     SET(WTF_OS_QNX 1)
106     SET(WTF_OS_UNIX 1)
107 ELSE ()
108     MESSAGE(FATAL_ERROR "Unknown OS '${CMAKE_SYSTEM_NAME}'")
109 ENDIF ()
110
111 # -----------------------------------------------------------------------------
112 # Default target names (can be overrriden in Options${PORT}.cmake file)
113 # -----------------------------------------------------------------------------
114 SET(JSC_EXECUTABLE_NAME JSC)
115 SET(WTF_LIBRARY_NAME WTF)
116 SET(JavaScriptCore_LIBRARY_NAME JavaScriptCore)
117 SET(WebCore_LIBRARY_NAME WebCore)
118 SET(WebKit_LIBRARY_NAME WebKit)
119 SET(WebKit2_LIBRARY_NAME WebKit2)
120 SET(WebCoreTestSupport_LIBRARY_NAME WebCoreTestSupport)
121
122 # -----------------------------------------------------------------------------
123 # Default library types
124 # -----------------------------------------------------------------------------
125 OPTION(SHARED_CORE "build JavaScriptCore and WebCore as shared libraries")
126
127 IF (SHARED_CORE)
128     SET(JavaScriptCore_LIBRARY_TYPE SHARED)
129     SET(WebCore_LIBRARY_TYPE SHARED)
130 ELSE ()
131     SET(JavaScriptCore_LIBRARY_TYPE STATIC)
132     SET(WebCore_LIBRARY_TYPE STATIC)
133 ENDIF ()
134
135 SET(WebKit_LIBRARY_TYPE SHARED)
136 SET(WebKit2_LIBRARY_TYPE SHARED)
137 SET(WebCoreTestSupport_LIBRARY_TYPE STATIC)
138
139 # -----------------------------------------------------------------------------
140 # Port-specific options
141 # -----------------------------------------------------------------------------
142 INCLUDE(OptionsCommon)
143 INCLUDE(Options${PORT})
144
145 # -----------------------------------------------------------------------------
146 # Install JavaScript shell
147 # -----------------------------------------------------------------------------
148 OPTION(SHOULD_INSTALL_JS_SHELL "generate an installation rule to install the built JavaScript shell")
149
150 # -----------------------------------------------------------------------------
151 # Define packaging
152 # -----------------------------------------------------------------------------
153 INCLUDE(WebKitPackaging)
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