1# Copyright (c) 2014, 2019, 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, version 2.0, 5# as published by the Free Software Foundation. 6# 7# This program is also distributed with certain software (including 8# but not limited to OpenSSL) that is licensed under separate terms, 9# as designated in a particular file or component or in included license 10# documentation. The authors of MySQL hereby grant you an additional 11# permission to link the program and your derivative works with the 12# separately licensed software that they have included with MySQL. 13# 14# This program is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License, version 2.0, for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with this program; if not, write to the Free Software 21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 23 24## ADD_COMPILE_FLAGS(<source files> COMPILE_FLAGS <flags>) 25## Use this for adding compiler flags to source files. 26FUNCTION(ADD_COMPILE_FLAGS) 27 SET(FILES "") 28 SET(FLAGS "") 29 SET(COMPILE_FLAGS_SEEN) 30 FOREACH(ARG ${ARGV}) 31 IF(ARG STREQUAL "COMPILE_FLAGS") 32 SET(COMPILE_FLAGS_SEEN 1) 33 ELSEIF(COMPILE_FLAGS_SEEN) 34 LIST(APPEND FLAGS ${ARG}) 35 IF(${ARG} MATCHES "^-D") 36 MESSAGE(WARNING 37 "${ARG} should be in COMPILE_DEFINITIONS not COMPILE_FLAGS") 38 ENDIF() 39 ELSE() 40 LIST(APPEND FILES ${ARG}) 41 ENDIF() 42 ENDFOREACH() 43 FOREACH(FILE ${FILES}) 44 FOREACH(FLAG ${FLAGS}) 45 GET_SOURCE_FILE_PROPERTY(PROP ${FILE} COMPILE_FLAGS) 46 IF(NOT PROP) 47 SET(PROP ${FLAG}) 48 ELSE() 49 STRING_APPEND(PROP " ${FLAG}") 50 ENDIF() 51 SET_SOURCE_FILES_PROPERTIES( 52 ${FILE} PROPERTIES COMPILE_FLAGS "${PROP}" 53 ) 54 ENDFOREACH() 55 ENDFOREACH() 56ENDFUNCTION() 57 58 59## ADD_COMPILE_DEFINITIONS(<source files> COMPILE_DEFINITIONS <flags>) 60## Use this for adding preprocessor flags VAR or VAR=value to source files. 61## cmake will prefix with '-D' and sort all COMPILE_DEFINITIONS alphabetically. 62FUNCTION(ADD_COMPILE_DEFINITIONS) 63 SET(FILES "") 64 SET(FLAGS "") 65 SET(COMPILE_DEFINITIONS_SEEN) 66 FOREACH(ARG ${ARGV}) 67 IF(ARG STREQUAL "COMPILE_DEFINITIONS") 68 SET(COMPILE_DEFINITIONS_SEEN 1) 69 ELSEIF(COMPILE_DEFINITIONS_SEEN) 70 LIST(APPEND FLAGS ${ARG}) 71 ELSE() 72 LIST(APPEND FILES ${ARG}) 73 ENDIF() 74 ENDFOREACH() 75 FOREACH(FILE ${FILES}) 76 GET_SOURCE_FILE_PROPERTY(DEFS ${FILE} COMPILE_DEFINITIONS) 77 IF(NOT DEFS) 78 SET(DEFS ${FLAGS}) 79 ELSE() 80 LIST(APPEND DEFS ${FLAGS}) 81 ENDIF() 82 SET_SOURCE_FILES_PROPERTIES( 83 ${FILE} PROPERTIES COMPILE_DEFINITIONS "${DEFS}") 84 ENDFOREACH() 85ENDFUNCTION() 86