Changeset 3115 for code/branches/pch/cmake
- Timestamp:
- Jun 3, 2009, 7:45:10 PM (15 years ago)
- Location:
- code/branches/pch/cmake
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pch/cmake/FlagUtilities.cmake
r2792 r3115 24 24 # Release, Debug, RelWithDebInfo, MinSizeRel: Build configs (inclusive) 25 25 # ReleaseAll: Sets the flags of all three release builds 26 # CACHE: Values are witten with SET_CACHE (see above)26 # CACHE: Values are witten with SET_CACHE_ADVANCED 27 27 # FORCE: When writing to the cache, the values are set anyway 28 28 # Any variable names (like WIN32, MSVC, etc.): Condition (combined with AND) 29 29 # You can suffix the condition with a NOT if you wish 30 # Function s:30 # Function names: 31 31 # [ADD/SET/REMOVE]_[COMPILER/LINKER]_FLAGS 32 32 # Caution: -If you use CACHE after calling the macro without CACHE, the value 33 # Will not getwritten unless FORCE is specified.33 # Will not be written unless FORCE is specified. 34 34 # - Also be aware to always specify the flags in quotes. 35 35 # Example: … … 37 37 # This will only remove the CXX (C++) flags on a non Unix system for the 38 38 # Release, RelWithDebInfo and MinSizeRel configurations. The macros should 39 # be able to cope with "test -foo" that is like another flag in the string.39 # be able to cope with "test -foo" as string argument for a flag. 40 40 # 41 41 42 # Write to the cache by force, but only if the user didn't edit the value 43 # Additional argument is the value (may also be a list) 44 MACRO(SET_CACHE _varname _type _docstring) 45 SET(_value ${ARGN}) 46 IF(NOT "${_type}" MATCHES "^(STRING|BOOL|PATH|FILEPATH)$") 47 MESSAGE(FATAL_ERROR "${_type} is not a valid CACHE entry type") 48 ENDIF() 42 INCLUDE(SeparateFlags) 43 INCLUDE(SetCacheAdvanced) 49 44 50 IF(NOT DEFINED _INTERNAL_${_varname} OR "${_INTERNAL_${_varname}}" STREQUAL "${${_varname}}") 51 SET(${_varname} "${_value}" CACHE ${_type} "${_docstring}" FORCE) 52 SET(_INTERNAL_${_varname} "${_value}" CACHE INTERNAL "Do not edit in any case!") 53 ENDIF() 54 ENDMACRO(SET_CACHE) 45 # Compiler flags, additional arguments: 46 # C, CXX: Specify a language, default is both 47 MACRO(SET_COMPILER_FLAGS _flags) 48 _INTERNAL_PARSE_FLAGS_ARGS(SET "C;CXX" "" "${_flags}" "${ARGN}") 49 ENDMACRO(SET_COMPILER_FLAGS) 50 # Add flags (flags don't get added twice) 51 MACRO(ADD_COMPILER_FLAGS _flags) 52 _INTERNAL_PARSE_FLAGS_ARGS(APPEND "C;CXX" "" "${_flags}" "${ARGN}") 53 ENDMACRO(ADD_COMPILER_FLAGS) 54 # Remove flags 55 MACRO(REMOVE_COMPILER_FLAGS _flags) 56 _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "C;CXX" "" "${_flags}" "${ARGN}") 57 ENDMACRO(REMOVE_COMPILER_FLAGS) 55 58 56 # Visual studio (esp. IntelliSense) doesn't like dashes to specify arguments57 # Always use foward slashes instead58 IF(MSVC)59 SET(ARGUMENT_STARTER "/")60 ELSE()61 SET(ARGUMENT_STARTER "-")62 ENDIF(MSVC)63 59 64 # Separates a string of flags. " -" or " /" denotes the start of a flag. 65 # The same sequence inside double quotation marks is ignored. 66 # Spaces not within quotes are cleaned meaningfully. 67 # This macro cannot cope with semicolons in the flag string! 68 MACRO(SEPARATE_FLAGS _flags _output_variable) 69 SET(_flags_prep " ${_flags} -") 70 STRING(REPLACE " " " ;" _flag_chunks ${_flags_prep}) # Max loop iterations 71 SET(_flag_string) 72 SET(_parsed_flags) 73 # Loop is necessary because the regex engine is greedy 74 FOREACH(_chunk ${_flag_chunks}) 75 SET(_flag_string "${_flag_string}${_chunk}") 76 # Replace all " -" and " /" inside quotation marks 77 STRING(REGEX REPLACE "^(([^\"]*\"[^\"]*\")*[^\"]*\"[^\"]*) [/-]([^\"]*\")" 78 "\\1@39535493@\\3" _flag_string "${_flag_string}") 79 # Extract one flag if possible 80 SET(_flag) 81 STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "${ARGUMENT_STARTER}\\1" _flag "${_flag_string}") 82 STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "\\2" _flag_string "${_flag_string}") 83 IF(NOT _flag STREQUAL _flag_string) 84 LIST(APPEND _parsed_flags "${_flag}") 85 ENDIF(NOT _flag STREQUAL _flag_string) 86 ENDFOREACH(_chunk) 60 # Linker flags, additional arguments: 61 # EXE, SHARED, MODULE: Specify a linker mode, default is all three 62 MACRO(SET_LINKER_FLAGS _flags) 63 _INTERNAL_PARSE_FLAGS_ARGS(SET "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}") 64 ENDMACRO(SET_LINKER_FLAGS) 65 # Add flags (flags don't get added twice) 66 MACRO(ADD_LINKER_FLAGS _flags) 67 _INTERNAL_PARSE_FLAGS_ARGS(APPEND "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}") 68 ENDMACRO(ADD_LINKER_FLAGS) 69 # Remove flags 70 MACRO(REMOVE_LINKER_FLAGS _flags) 71 _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}") 72 ENDMACRO(REMOVE_LINKER_FLAGS) 87 73 88 # Re-replace all " -" and " /" inside quotation marks89 STRING(REGEX REPLACE "@39535493@" " -" ${_output_variable} "${_parsed_flags}")90 ENDMACRO(SEPARATE_FLAGS)91 92 # Internal macro, do not use93 # Modifies the flags according to the mode: set, add or remove94 # Also sets flags according to the CACHE and FORCE parameter.95 # If only CACHE is specified, SET_CACHE() is used.96 MACRO(_INTERNAL_PARSE_FLAGS _mode _flags _varname _write_to_cache _force)97 SEPARATE_FLAGS("${_flags}" _arg_flag_list)98 99 IF("${_mode}" STREQUAL "SET")100 # SET101 SET(_flag_list "${_arg_flag_list}")102 ELSE()103 # ADD or REMOVE104 SEPARATE_FLAGS("${${_varname}}" _flag_list)105 FOREACH(_flag ${_arg_flag_list})106 LIST(${_mode} _flag_list "${_flag}")107 ENDFOREACH(_flag)108 ENDIF()109 110 LIST(REMOVE_DUPLICATES _flag_list)111 LIST(SORT _flag_list)112 STRING(REPLACE ";" " " _flag_list "${_flag_list}")113 114 IF(_write_to_cache)115 IF(_force)116 SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)117 SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)118 ELSE()119 SET_CACHE(${_varname} STRING "${${_varname}}" "${_flag_list}")120 ENDIF()121 ELSE()122 SET(${_varname} "${_flag_list}")123 ENDIF()124 ENDMACRO(_INTERNAL_PARSE_FLAGS)125 74 126 75 # Internal macro, do not use … … 155 104 IF(_invert_condition) 156 105 SET(_invert_condition FALSE) 157 IF(${_arg})106 IF(${_arg}) 158 107 SET(_arg_cond FALSE) 159 ELSE()108 ELSE() 160 109 SET(_arg_cond TRUE) 161 ENDIF()110 ENDIF() 162 111 ELSE() 163 112 SET(_arg_cond ${${_arg}}) … … 191 140 192 141 193 # Compiler flags, additional arguments: 194 # C, CXX: Specify a language, default is both 195 MACRO(SET_COMPILER_FLAGS _flags) 196 _INTERNAL_PARSE_FLAGS_ARGS(SET "C;CXX" "" "${_flags}" "${ARGN}") 197 ENDMACRO(SET_COMPILER_FLAGS) 198 # Add flags (flags don't get added twice) 199 MACRO(ADD_COMPILER_FLAGS _flags) 200 _INTERNAL_PARSE_FLAGS_ARGS(APPEND "C;CXX" "" "${_flags}" "${ARGN}") 201 ENDMACRO(ADD_COMPILER_FLAGS) 202 # Remove flags 203 MACRO(REMOVE_COMPILER_FLAGS _flags) 204 _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "C;CXX" "" "${_flags}" "${ARGN}") 205 ENDMACRO(REMOVE_COMPILER_FLAGS) 142 # Internal macro, do not use 143 # Modifies the flags according to the mode: set, add or remove 144 # Also sets flags according to the CACHE and FORCE parameter. 145 # If only CACHE is specified, SET_CACHE_ADVANCED() is used. 146 MACRO(_INTERNAL_PARSE_FLAGS _mode _flags _varname _write_to_cache _force) 147 SEPARATE_FLAGS("${_flags}" _arg_flag_list) 206 148 207 # Linker flags, additional arguments: 208 # EXE, SHARED, MODULE: Specify a linker mode, default is all three 209 MACRO(SET_LINKER_FLAGS _flags) 210 _INTERNAL_PARSE_FLAGS_ARGS(SET "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}") 211 ENDMACRO(SET_LINKER_FLAGS) 212 # Add flags (flags don't get added twice) 213 MACRO(ADD_LINKER_FLAGS _flags) 214 _INTERNAL_PARSE_FLAGS_ARGS(APPEND "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}") 215 ENDMACRO(ADD_LINKER_FLAGS) 216 # Remove flags 217 MACRO(REMOVE_LINKER_FLAGS _flags) 218 _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}") 219 ENDMACRO(REMOVE_LINKER_FLAGS) 149 IF("${_mode}" STREQUAL "SET") 150 # SET 151 SET(_flag_list "${_arg_flag_list}") 152 ELSE() 153 # ADD or REMOVE 154 SEPARATE_FLAGS("${${_varname}}" _flag_list) 155 IF(NOT _flag_list) 156 SET(_flag_list "") # LIST command requires a list in any case 157 ENDIF() 158 FOREACH(_flag ${_arg_flag_list}) 159 LIST(${_mode} _flag_list "${_flag}") 160 ENDFOREACH(_flag) 161 ENDIF() 162 163 LIST(REMOVE_DUPLICATES _flag_list) 164 LIST(SORT _flag_list) 165 STRING(REPLACE ";" " " _flag_list "${_flag_list}") 166 167 IF(_write_to_cache) 168 IF(_force) 169 SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE) 170 SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE) 171 ELSE() 172 SET_CACHE_ADVANCED(${_varname} STRING "${${_varname}}" "${_flag_list}") 173 ENDIF() 174 ELSE() 175 SET(${_varname} "${_flag_list}") 176 ENDIF() 177 ENDMACRO(_INTERNAL_PARSE_FLAGS)
Note: See TracChangeset
for help on using the changeset viewer.