1# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; version 2 of the License.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program; if not, write to the Free Software
14# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA
15
16
17## ADD_COMPILE_FLAGS(<source files> COMPILE_FLAGS <flags>)
18MACRO(ADD_COMPILE_FLAGS)
19  SET(FILES "")
20  SET(FLAGS "")
21  SET(COMPILE_FLAGS_SEEN)
22  FOREACH(ARG ${ARGV})
23    IF(ARG STREQUAL "COMPILE_FLAGS")
24      SET(COMPILE_FLAGS_SEEN 1)
25    ELSEIF(COMPILE_FLAGS_SEEN)
26      LIST(APPEND FLAGS ${ARG})
27    ELSE()
28      LIST(APPEND FILES ${ARG})
29    ENDIF()
30  ENDFOREACH()
31  FOREACH(FILE ${FILES})
32    FOREACH(FLAG ${FLAGS})
33      GET_SOURCE_FILE_PROPERTY(PROP ${FILE} COMPILE_FLAGS)
34      IF(NOT PROP)
35        SET(PROP ${FLAG})
36      ELSE()
37        SET(PROP "${PROP} ${FLAG}")
38      ENDIF()
39      SET_SOURCE_FILES_PROPERTIES(
40        ${FILE} PROPERTIES COMPILE_FLAGS "${PROP}"
41        )
42    ENDFOREACH()
43  ENDFOREACH()
44ENDMACRO()
45