summaryrefslogtreecommitdiff
path: root/Source/cmake/WebKitHelpers.cmake
blob: cb777940af30b89b98f2e0b8f4fb83bd487613b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
INCLUDE(CMakeParseArguments)
# Sets extra compile flags for a target, depending on the compiler being used.
# Currently, only GCC is supported.
MACRO(WEBKIT_SET_EXTRA_COMPILER_FLAGS _target)
  SET(options IGNORECXX_WARNINGS)
  CMAKE_PARSE_ARGUMENTS("OPTION" "IGNORECXX_WARNINGS" "" "" ${ARGN})
  IF (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    GET_TARGET_PROPERTY(OLD_COMPILE_FLAGS ${_target} COMPILE_FLAGS)
    IF (${OLD_COMPILE_FLAGS} STREQUAL "OLD_COMPILE_FLAGS-NOTFOUND")
        SET(OLD_COMPILE_FLAGS "")
    ENDIF ()

    INCLUDE(TestCXXAcceptsFlag)
    CHECK_CXX_ACCEPTS_FLAG("-dumpversion" CMAKE_CXX_ACCEPTS_DUMPVERSION)
    IF (CMAKE_CXX_ACCEPTS_DUMPVERSION)
        EXEC_PROGRAM(${CMAKE_CXX_COMPILER} ARGS -dumpversion OUTPUT_VARIABLE COMPILER_VERSION)
    ELSE ()
        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)
    ENDIF ()

    # Disable some optimizations on buggy compiler versions
    # GCC 4.5.1 does not implement -ftree-sra correctly
    IF (${COMPILER_VERSION} STREQUAL "4.5.1")
        SET(OLD_COMPILE_FLAGS "${OLD_COMPILE_FLAGS} -fno-tree-sra")
    ENDIF ()

    IF (NOT SHARED_CORE)
        SET(OLD_COMPILE_FLAGS "-fvisibility=hidden ${OLD_COMPILE_FLAGS}")
    ENDIF ()

    GET_TARGET_PROPERTY(TARGET_TYPE ${_target} TYPE)
    IF (${TARGET_TYPE} STREQUAL "STATIC_LIBRARY") # -fPIC is automatically added to shared libraries
        SET(OLD_COMPILE_FLAGS "-fPIC ${OLD_COMPILE_FLAGS}")
    ENDIF ()

    SET(OLD_COMPILE_FLAGS "-fno-exceptions -fno-strict-aliasing ${OLD_COMPILE_FLAGS}")

    # Enable warnings by default
    IF (NOT ${OPTION_IGNORECXX_WARNINGS})
        SET(OLD_COMPILE_FLAGS "-W -DANOTHER_BRICK_IN_THE -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat -Wformat-security -Wmissing-format-attribute -Wno-format-y2k -Wno-parentheses -Wno-unused-parameter -Wpointer-arith  -Wreturn-type -Wundef -Wwrite-strings ${OLD_COMPILE_FLAGS}")
    ENDIF ()

    # Disable C++0x compat warnings for GCC >= 4.6.0 until we build
    # cleanly with that.
    IF (NOT ${OPTION_IGNORECXX_WARNINGS} AND NOT ${COMPILER_VERSION} VERSION_LESS "4.6.0")
        SET(OLD_COMPILE_FLAGS "${OLD_COMPILE_FLAGS} -Wno-c++0x-compat")
    ENDIF ()

    SET_TARGET_PROPERTIES (${_target} PROPERTIES
	COMPILE_FLAGS "${OLD_COMPILE_FLAGS}")

    UNSET(OLD_COMPILE_FLAGS)
  ENDIF ()
ENDMACRO()


# Append the given flag to the target property.
# Builds on top of GET_TARGET_PROPERTY() and SET_TARGET_PROPERTIES()
MACRO (ADD_TARGET_PROPERTIES _target _property _flags)
  GET_TARGET_PROPERTY (_tmp ${_target} ${_property})
  IF (NOT _tmp)
    SET (_tmp "")
  ENDIF (NOT _tmp)

  FOREACH (f ${_flags})
    SET (_tmp "${_tmp} ${f}")
  ENDFOREACH (f ${_flags})

  SET_TARGET_PROPERTIES (${_target} PROPERTIES ${_property} ${_tmp})
  UNSET (_tmp)
ENDMACRO (ADD_TARGET_PROPERTIES _target _property _flags)


# Append the given dependencies to the source file
MACRO(ADD_SOURCE_DEPENDENCIES _source _deps)
  GET_SOURCE_FILE_PROPERTY(_tmp ${_source} OBJECT_DEPENDS)
  IF (NOT _tmp)
    SET (_tmp "")
  ENDIF ()

  FOREACH (f ${_deps})
    LIST(APPEND _tmp "${f}")
  ENDFOREACH ()

  SET_SOURCE_FILES_PROPERTIES(${_source} PROPERTIES OBJECT_DEPENDS "${_tmp}")
  UNSET(_tmp)
ENDMACRO()


# Append the given dependencies to the source file
# This one consider the given dependencies are in ${DERIVED_SOURCES_WEBCORE_DIR}
# and prepends this to every member of dependencies list
MACRO(ADD_SOURCE_WEBCORE_DERIVED_DEPENDENCIES _source _deps)
  SET(_tmp "")
  FOREACH (f ${_deps})
    LIST(APPEND _tmp "${DERIVED_SOURCES_WEBCORE_DIR}/${f}")
  ENDFOREACH ()

  ADD_SOURCE_DEPENDENCIES(${_source} ${_tmp})
  UNSET(_tmp)
ENDMACRO()