[Win] CMake build fix after r188098.
[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         get_target_property(TARGET_TYPE ${_target} TYPE)
14         if (${TARGET_TYPE} STREQUAL "STATIC_LIBRARY") # -fPIC is automatically added to shared libraries
15             set(OLD_COMPILE_FLAGS "-fPIC ${OLD_COMPILE_FLAGS}")
16         endif ()
17
18         # Suppress -Wparentheses-equality warning of Clang
19         if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
20             set(OLD_COMPILE_FLAGS "-Wno-parentheses-equality ${OLD_COMPILE_FLAGS}")
21         endif ()
22
23         # Enable warnings by default
24         if (NOT ${OPTION_IGNORECXX_WARNINGS})
25             set(OLD_COMPILE_FLAGS "-Wall -Wextra -Wcast-align -Wformat-security -Wmissing-format-attribute -Wpointer-arith -Wundef -Wwrite-strings ${OLD_COMPILE_FLAGS}")
26         endif ()
27
28         # Enable errors on warning
29         if (OPTION_ENABLE_WERROR)
30             set(OLD_COMPILE_FLAGS "-Werror ${OLD_COMPILE_FLAGS}")
31         endif ()
32
33         set_target_properties(${_target} PROPERTIES
34             COMPILE_FLAGS "${OLD_COMPILE_FLAGS}")
35
36         unset(OLD_COMPILE_FLAGS)
37     endif ()
38 endmacro()
39
40
41 # Append the given flag to the target property.
42 # Builds on top of get_target_property() and set_target_properties()
43 macro(ADD_TARGET_PROPERTIES _target _property _flags)
44     get_target_property(_tmp ${_target} ${_property})
45     if (NOT _tmp)
46         set(_tmp "")
47     endif (NOT _tmp)
48
49     foreach (f ${_flags})
50         set(_tmp "${_tmp} ${f}")
51     endforeach (f ${_flags})
52
53     set_target_properties(${_target} PROPERTIES ${_property} ${_tmp})
54     unset(_tmp)
55 endmacro(ADD_TARGET_PROPERTIES _target _property _flags)
56
57
58 # Append the given dependencies to the source file
59 macro(ADD_SOURCE_DEPENDENCIES _source _deps)
60     get_source_file_property(_tmp ${_source} OBJECT_DEPENDS)
61     if (NOT _tmp)
62         set(_tmp "")
63     endif ()
64
65     foreach (f ${_deps})
66         list(APPEND _tmp "${f}")
67     endforeach ()
68
69     set_source_files_properties(${_source} PROPERTIES OBJECT_DEPENDS "${_tmp}")
70     unset(_tmp)
71 endmacro()
72
73
74 # Append the given dependencies to the source file
75 # This one consider the given dependencies are in ${DERIVED_SOURCES_WEBCORE_DIR}
76 # and prepends this to every member of dependencies list
77 macro(ADD_SOURCE_WEBCORE_DERIVED_DEPENDENCIES _source _deps)
78     set(_tmp "")
79     foreach (f ${_deps})
80         list(APPEND _tmp "${DERIVED_SOURCES_WEBCORE_DIR}/${f}")
81     endforeach ()
82
83     ADD_SOURCE_DEPENDENCIES(${_source} ${_tmp})
84     unset(_tmp)
85 endmacro()
86
87 macro(CALCULATE_LIBRARY_VERSIONS_FROM_LIBTOOL_TRIPLE library_name current revision age)
88     math(EXPR ${library_name}_VERSION_MAJOR "${current} - ${age}")
89     set(${library_name}_VERSION_MINOR ${age})
90     set(${library_name}_VERSION_MICRO ${revision})
91     set(${library_name}_VERSION ${${library_name}_VERSION_MAJOR}.${age}.${revision})
92 endmacro()
93
94 macro(POPULATE_LIBRARY_VERSION library_name)
95 if (NOT DEFINED ${library_name}_VERSION_MAJOR)
96     set(${library_name}_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
97 endif ()
98 if (NOT DEFINED ${library_name}_VERSION_MINOR)
99     set(${library_name}_VERSION_MINOR ${PROJECT_VERSION_MINOR})
100 endif ()
101 if (NOT DEFINED ${library_name}_VERSION_MICRO)
102     set(${library_name}_VERSION_MICRO ${PROJECT_VERSION_MICRO})
103 endif ()
104 if (NOT DEFINED ${library_name}_VERSION)
105     set(${library_name}_VERSION ${PROJECT_VERSION})
106 endif ()
107 endmacro()