[WPE] REGRESSION(r253675) Crash when using threaded rendering
[WebKit-https.git] / Source / cmake / OptionsCommon.cmake
1 set(CMAKE_CXX_STANDARD 17)
2 set(CMAKE_CXX_STANDARD_REQUIRED ON)
3 set(CMAKE_CXX_EXTENSIONS OFF)
4
5 add_definitions(-DBUILDING_WITH_CMAKE=1)
6 add_definitions(-DHAVE_CONFIG_H=1)
7
8 option(USE_THIN_ARCHIVES "Produce all static libraries as thin archives" ON)
9 if (USE_THIN_ARCHIVES)
10     execute_process(COMMAND ${CMAKE_AR} -V OUTPUT_VARIABLE AR_VERSION)
11     if ("${AR_VERSION}" MATCHES "^GNU ar")
12         set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> crT <TARGET> <LINK_FLAGS> <OBJECTS>")
13         set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> crT <TARGET> <LINK_FLAGS> <OBJECTS>")
14         set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> rT <TARGET> <LINK_FLAGS> <OBJECTS>")
15         set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> rT <TARGET> <LINK_FLAGS> <OBJECTS>")
16     endif ()
17 endif ()
18
19 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
20 define_property(TARGET PROPERTY FOLDER INHERITED BRIEF_DOCS "folder" FULL_DOCS "IDE folder name")
21
22 set(ARM_TRADITIONAL_DETECTED FALSE)
23 if (WTF_CPU_ARM)
24     set(ARM_THUMB2_TEST_SOURCE
25     "
26     #if !defined(thumb2) && !defined(__thumb2__)
27     #error \"Thumb2 instruction set isn't available\"
28     #endif
29     int main() {}
30    ")
31
32     CHECK_CXX_SOURCE_COMPILES("${ARM_THUMB2_TEST_SOURCE}" ARM_THUMB2_DETECTED)
33     if (NOT ARM_THUMB2_DETECTED)
34         set(ARM_TRADITIONAL_DETECTED TRUE)
35         # See https://bugs.webkit.org/show_bug.cgi?id=159880#c4 for details.
36         message(STATUS "Disabling GNU gold linker, because it doesn't support ARM instruction set properly.")
37     endif ()
38 endif ()
39
40 # Use ld.lld when building with LTO
41 CMAKE_DEPENDENT_OPTION(USE_LD_LLD "Use LLD linker" ON
42                        "LTO_MODE;NOT USE_LD_GOLD;NOT WIN32" OFF)
43 if (USE_LD_LLD)
44     execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=lld -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
45     if ("${LD_VERSION}" MATCHES "LLD")
46         string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=lld -Wl,--disable-new-dtags")
47         string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=lld -Wl,--disable-new-dtags")
48         string(APPEND CMAKE_MODULE_LINKER_FLAGS " -fuse-ld=lld -Wl,--disable-new-dtags")
49     else ()
50         set(USE_LD_LLD OFF)
51     endif ()
52 endif ()
53
54 # Use ld.gold if it is available and isn't disabled explicitly
55 CMAKE_DEPENDENT_OPTION(USE_LD_GOLD "Use GNU gold linker" ON
56                        "NOT CXX_ACCEPTS_MFIX_CORTEX_A53_835769;NOT ARM_TRADITIONAL_DETECTED;NOT WIN32;NOT APPLE;NOT USE_LD_LLD" OFF)
57 if (USE_LD_GOLD)
58     execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
59     if ("${LD_VERSION}" MATCHES "GNU gold")
60         string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=gold -Wl,--disable-new-dtags")
61         string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=gold -Wl,--disable-new-dtags")
62         string(APPEND CMAKE_MODULE_LINKER_FLAGS " -fuse-ld=gold -Wl,--disable-new-dtags")
63     else ()
64         message(WARNING "GNU gold linker isn't available, using the default system linker.")
65         set(USE_LD_GOLD OFF)
66     endif ()
67 endif ()
68
69 set(ENABLE_DEBUG_FISSION_DEFAULT OFF)
70 if (USE_LD_GOLD AND CMAKE_BUILD_TYPE STREQUAL "Debug")
71     check_cxx_compiler_flag(-gsplit-dwarf CXX_COMPILER_SUPPORTS_GSPLIT_DWARF)
72     if (CXX_COMPILER_SUPPORTS_GSPLIT_DWARF)
73         set(ENABLE_DEBUG_FISSION_DEFAULT ON)
74     endif ()
75 endif ()
76
77 option(DEBUG_FISSION "Use Debug Fission support" ${ENABLE_DEBUG_FISSION_DEFAULT})
78
79 if (DEBUG_FISSION)
80     if (NOT USE_LD_GOLD)
81         message(FATAL_ERROR "Need GNU gold linker for Debug Fission support")
82     endif ()
83     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gsplit-dwarf")
84     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gsplit-dwarf")
85     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gdb-index")
86     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gdb-index")
87 endif ()
88
89 set(GCC_OFFLINEASM_SOURCE_MAP_DEFAULT OFF)
90 if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
91     set(GCC_OFFLINEASM_SOURCE_MAP_DEFAULT ON)
92 endif ()
93
94 option(GCC_OFFLINEASM_SOURCE_MAP
95   "Produce debug line information for offlineasm-generated code"
96   ${GCC_OFFLINEASM_SOURCE_MAP_DEFAULT})
97
98 # Enable the usage of OpenMP.
99 #  - At this moment, OpenMP is only used as an alternative implementation
100 #    to native threads for the parallelization of the SVG filters.
101 if (USE_OPENMP)
102     find_package(OpenMP REQUIRED)
103     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
104     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
105 endif ()
106
107 # GTK and WPE use the GNU installation directories as defaults.
108 if (NOT PORT STREQUAL "GTK" AND NOT PORT STREQUAL "WPE")
109     set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Absolute path to library installation directory")
110     set(EXEC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Absolute path to executable installation directory")
111     set(LIBEXEC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Absolute path to install executables executed by the library")
112 endif ()
113
114 # Check whether features.h header exists.
115 # Including glibc's one defines __GLIBC__, that is used in Platform.h
116 WEBKIT_CHECK_HAVE_INCLUDE(HAVE_FEATURES_H features.h)
117
118 # Check for headers
119 WEBKIT_CHECK_HAVE_INCLUDE(HAVE_ERRNO_H errno.h)
120 WEBKIT_CHECK_HAVE_INCLUDE(HAVE_LANGINFO_H langinfo.h)
121 WEBKIT_CHECK_HAVE_INCLUDE(HAVE_MMAP sys/mman.h)
122 WEBKIT_CHECK_HAVE_INCLUDE(HAVE_PTHREAD_NP_H pthread_np.h)
123 WEBKIT_CHECK_HAVE_INCLUDE(HAVE_SYS_PARAM_H sys/param.h)
124 WEBKIT_CHECK_HAVE_INCLUDE(HAVE_SYS_TIME_H sys/time.h)
125 WEBKIT_CHECK_HAVE_INCLUDE(HAVE_SYS_TIMEB_H sys/timeb.h)
126 WEBKIT_CHECK_HAVE_INCLUDE(HAVE_LINUX_MEMFD_H linux/memfd.h)
127
128 # Check for functions
129 WEBKIT_CHECK_HAVE_FUNCTION(HAVE_ALIGNED_MALLOC _aligned_malloc)
130 WEBKIT_CHECK_HAVE_FUNCTION(HAVE_ISDEBUGGERPRESENT IsDebuggerPresent)
131 WEBKIT_CHECK_HAVE_FUNCTION(HAVE_LOCALTIME_R localtime_r)
132 WEBKIT_CHECK_HAVE_FUNCTION(HAVE_MALLOC_TRIM malloc_trim)
133 WEBKIT_CHECK_HAVE_FUNCTION(HAVE_STRNSTR strnstr)
134 WEBKIT_CHECK_HAVE_FUNCTION(HAVE_TIMEGM timegm)
135 WEBKIT_CHECK_HAVE_FUNCTION(HAVE_VASPRINTF vasprintf)
136
137 # Check for symbols
138 WEBKIT_CHECK_HAVE_SYMBOL(HAVE_REGEX_H regexec regex.h)
139 if (NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin"))
140 WEBKIT_CHECK_HAVE_SYMBOL(HAVE_PTHREAD_MAIN_NP pthread_main_np pthread_np.h)
141 endif ()
142 # Windows has signal.h but is missing symbols that are used in calls to signal.
143 WEBKIT_CHECK_HAVE_SYMBOL(HAVE_SIGNAL_H SIGTRAP signal.h)
144
145 # Check for struct members
146 WEBKIT_CHECK_HAVE_STRUCT(HAVE_STAT_BIRTHTIME "struct stat" st_birthtime sys/stat.h)
147 WEBKIT_CHECK_HAVE_STRUCT(HAVE_TM_GMTOFF "struct tm" tm_gmtoff time.h)
148 WEBKIT_CHECK_HAVE_STRUCT(HAVE_TM_ZONE "struct tm" tm_zone time.h)
149
150 # Check for int types
151 check_type_size("__int128_t" INT128_VALUE)
152
153 if (HAVE_INT128_VALUE)
154   SET_AND_EXPOSE_TO_BUILD(HAVE_INT128_T INT128_VALUE)
155 endif ()