[EFL][CMake] Fix javascriptcore test failings by the jsCStack branch merge
[WebKit-https.git] / Source / cmake / WebKitHelpers.cmake
1 include(CMakeParseArguments)
2 # Sets extra compile flags for a target, depending on the compiler being used.
3 # Currently, only GCC is supported.
4 macro(WEBKIT_SET_EXTRA_COMPILER_FLAGS _target)
5     set(options ENABLE_WERROR IGNORECXX_WARNINGS)
6     CMAKE_PARSE_ARGUMENTS("OPTION" "${options}" "" "" ${ARGN})
7     if (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
8         get_target_property(OLD_COMPILE_FLAGS ${_target} COMPILE_FLAGS)
9         if (${OLD_COMPILE_FLAGS} STREQUAL "OLD_COMPILE_FLAGS-NOTFOUND")
10             set(OLD_COMPILE_FLAGS "")
11         endif ()
12
13         include(TestCXXAcceptsFlag)
14         CHECK_CXX_ACCEPTS_FLAG("-dumpversion" CMAKE_CXX_ACCEPTS_DUMPVERSION)
15         if (CMAKE_CXX_ACCEPTS_DUMPVERSION)
16             EXEC_PROGRAM(${CMAKE_CXX_COMPILER} ARGS -dumpversion OUTPUT_VARIABLE COMPILER_VERSION)
17         else ()
18             EXEC_PROGRAM("${CMAKE_CXX_COMPILER} -E -Wp,-dM - < /dev/null | grep '#define __VERSION__' | grep -E -o '[0-9]+\\.[0-9]+\\.?[0-9]+?'" OUTPUT_VARIABLE COMPILER_VERSION)
19         endif ()
20
21         # Disable some optimizations on buggy compiler versions
22         # GCC 4.5.1 does not implement -ftree-sra correctly
23         if (${COMPILER_VERSION} STREQUAL "4.5.1")
24             set(OLD_COMPILE_FLAGS "-fno-tree-sra ${OLD_COMPILE_FLAGS}")
25         endif ()
26
27         # For GTK+ we will rely on a linker script to deal with symbol visibility on
28         # production builds, we want all symbols visible for development builds.
29         if (NOT SHARED_CORE AND NOT ${PORT} STREQUAL "GTK")
30             set(OLD_COMPILE_FLAGS "-fvisibility=hidden ${OLD_COMPILE_FLAGS}")
31         endif ()
32
33         get_target_property(TARGET_TYPE ${_target} TYPE)
34         if (${TARGET_TYPE} STREQUAL "STATIC_LIBRARY") # -fPIC is automatically added to shared libraries
35             set(OLD_COMPILE_FLAGS "-fPIC ${OLD_COMPILE_FLAGS}")
36         endif ()
37
38         set(OLD_COMPILE_FLAGS "-fno-exceptions -fno-strict-aliasing ${OLD_COMPILE_FLAGS}")
39
40         # Enable warnings by default
41         if (NOT ${OPTION_IGNORECXX_WARNINGS})
42             set(OLD_COMPILE_FLAGS "-Wall -Wextra -Wcast-align -Wformat-security -Wmissing-format-attribute -Wpointer-arith -Wundef -Wwrite-strings ${OLD_COMPILE_FLAGS}")
43         endif ()
44
45         # Enable errors on warning
46         if (OPTION_ENABLE_WERROR)
47             # FIXME: When we use -fno-tree-dce to support the jsCStack branch merge, build error occurs due to the uninitialization. Temporarily we set
48             # uninitialized as build warning in order to support the jsCStack merge. https://bugs.webkit.org/show_bug.cgi?id=127777.
49             set(OLD_COMPILE_FLAGS "-Werror -Wno-error=unused-parameter -Wno-error=uninitialized ${OLD_COMPILE_FLAGS}")
50         endif ()
51
52         set_target_properties(${_target} PROPERTIES
53             COMPILE_FLAGS "${OLD_COMPILE_FLAGS}")
54
55         unset(OLD_COMPILE_FLAGS)
56     endif ()
57 endmacro()
58
59
60 # Append the given flag to the target property.
61 # Builds on top of get_target_property() and set_target_properties()
62 macro(ADD_TARGET_PROPERTIES _target _property _flags)
63     get_target_property(_tmp ${_target} ${_property})
64     if (NOT _tmp)
65         set(_tmp "")
66     endif (NOT _tmp)
67
68     foreach (f ${_flags})
69         set(_tmp "${_tmp} ${f}")
70     endforeach (f ${_flags})
71
72     set_target_properties(${_target} PROPERTIES ${_property} ${_tmp})
73     unset(_tmp)
74 endmacro(ADD_TARGET_PROPERTIES _target _property _flags)
75
76
77 # Append the given dependencies to the source file
78 macro(ADD_SOURCE_DEPENDENCIES _source _deps)
79     get_source_file_property(_tmp ${_source} OBJECT_DEPENDS)
80     if (NOT _tmp)
81         set(_tmp "")
82     endif ()
83
84     foreach (f ${_deps})
85         list(APPEND _tmp "${f}")
86     endforeach ()
87
88     set_source_files_properties(${_source} PROPERTIES OBJECT_DEPENDS "${_tmp}")
89     unset(_tmp)
90 endmacro()
91
92
93 # Append the given dependencies to the source file
94 # This one consider the given dependencies are in ${DERIVED_SOURCES_WEBCORE_DIR}
95 # and prepends this to every member of dependencies list
96 macro(ADD_SOURCE_WEBCORE_DERIVED_DEPENDENCIES _source _deps)
97     set(_tmp "")
98     foreach (f ${_deps})
99         list(APPEND _tmp "${DERIVED_SOURCES_WEBCORE_DIR}/${f}")
100     endforeach ()
101
102     ADD_SOURCE_DEPENDENCIES(${_source} ${_tmp})
103     unset(_tmp)
104 endmacro()
105
106 macro(CALCULATE_LIBRARY_VERSIONS_FROM_LIBTOOL_TRIPLE library_name current revision age)
107     math(EXPR ${library_name}_VERSION_MAJOR "${current} - ${age}")
108     set(${library_name}_VERSION_MINOR ${age})
109     set(${library_name}_VERSION_PATCH ${revision})
110     set(${library_name}_VERSION ${${library_name}_VERSION_MAJOR}.${age}.${revision})
111 endmacro()
112
113 macro(POPULATE_LIBRARY_VERSION library_name)
114 if (NOT DEFINED ${library_name}_VERSION_MAJOR)
115     set(${library_name}_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
116 endif ()
117 if (NOT DEFINED ${library_name}_VERSION_MINOR)
118     set(${library_name}_VERSION_MINOR ${PROJECT_VERSION_MINOR})
119 endif ()
120 if (NOT DEFINED ${library_name}_VERSION_PATCH)
121     set(${library_name}_VERSION_PATCH ${PROJECT_VERSION_PATCH})
122 endif ()
123 if (NOT DEFINED ${library_name}_VERSION)
124     set(${library_name}_VERSION ${PROJECT_VERSION})
125 endif ()
126 endmacro()