| [3117] | 1 | # | 
|---|
|  | 2 | #             ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
|  | 3 | #                             > www.orxonox.net < | 
|---|
|  | 4 | # | 
|---|
|  | 5 | #        This program is free software; you can redistribute it and/or | 
|---|
|  | 6 | #         modify it under the terms of the GNU General Public License | 
|---|
|  | 7 | #        as published by the Free Software Foundation; either version 2 | 
|---|
|  | 8 | #            of the License, or (at your option) any later version. | 
|---|
|  | 9 | # | 
|---|
|  | 10 | #       This program is distributed in the hope that it will be useful, | 
|---|
|  | 11 | #        but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 12 | #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 13 | #                 GNU General Public License for more details. | 
|---|
|  | 14 | # | 
|---|
|  | 15 | #   You should have received a copy of the GNU General Public License along | 
|---|
|  | 16 | #      with this program; if not, write to the Free Software Foundation, | 
|---|
|  | 17 | #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
|  | 18 | # | 
|---|
|  | 19 | # | 
|---|
|  | 20 | #  Author: | 
|---|
|  | 21 | #    Reto Grieder | 
|---|
|  | 22 | #  Description: | 
|---|
|  | 23 | #    Tries to return all GCC compiler flags set for a target. This also | 
|---|
|  | 24 | #    all definitions of the current directory. | 
|---|
|  | 25 | # | 
|---|
|  | 26 |  | 
|---|
|  | 27 | INCLUDE(SeparateFlags) | 
|---|
|  | 28 |  | 
|---|
|  | 29 | FUNCTION(GET_GCC_COMPILER_FLAGS _target _flagsvar) | 
|---|
|  | 30 |  | 
|---|
|  | 31 | # General flags | 
|---|
|  | 32 | STRING(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type_upper) | 
|---|
|  | 33 | SET(_flag_str "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_build_type_upper}}") | 
|---|
|  | 34 |  | 
|---|
|  | 35 | # Include directories | 
|---|
|  | 36 | GET_DIRECTORY_PROPERTY(_include_dirs INCLUDE_DIRECTORIES) | 
|---|
|  | 37 | IF(_include_dirs) | 
|---|
|  | 38 | FOREACH(_directory ${_include_dirs}) | 
|---|
|  | 39 | SET(_flag_str "${_flag_str} -I${_directory}") | 
|---|
|  | 40 | ENDFOREACH(_directory) | 
|---|
|  | 41 | ENDIF() | 
|---|
|  | 42 |  | 
|---|
|  | 43 | # For shared libraries linked with gcc, we have to add -fPIC | 
|---|
| [3161] | 44 | GET_TARGET_PROPERTY(_target_type ${_target} TYPE) | 
|---|
|  | 45 | IF(NOT MINGW AND ${_target_type} STREQUAL SHARED_LIBRARY) | 
|---|
|  | 46 | SET(_flag_str "${_flag_str} -fPIC") | 
|---|
|  | 47 | ENDIF() | 
|---|
| [3117] | 48 |  | 
|---|
|  | 49 | # Target compile flags | 
|---|
|  | 50 | GET_TARGET_PROPERTY(_target_flags ${_target} COMPILE_FLAGS) | 
|---|
|  | 51 | IF(_target_flags) | 
|---|
|  | 52 | SET(_flag_str "${_flag_str} ${_target_flags}") | 
|---|
|  | 53 | ENDIF() | 
|---|
|  | 54 |  | 
|---|
|  | 55 | # Definitions from target and directory | 
|---|
|  | 56 | GET_DIRECTORY_PROPERTY(_directory_defs                 COMPILE_DEFINITIONS) | 
|---|
|  | 57 | GET_DIRECTORY_PROPERTY(_directory_defs_build_type      COMPILE_DEFINITIONS_${_build_type_upper}) | 
|---|
|  | 58 | GET_TARGET_PROPERTY(_target_defs            ${_target} COMPILE_DEFINITIONS) | 
|---|
|  | 59 | GET_TARGET_PROPERTY(_target_defs_build_type ${_target} COMPILE_DEFINITIONS_${_build_type_upper}) | 
|---|
|  | 60 | GET_TARGET_PROPERTY(_target_def_symbol      ${_target} DEFINE_SYMBOL) | 
|---|
|  | 61 | # Prefix them all with a "-D" if the property was found | 
|---|
|  | 62 | FOREACH(_def ${_directory_defs} ${_directory_defs_build_type} ${_target_defs} | 
|---|
|  | 63 | ${_target_defs_build_type} ${_target_def_symbol}) | 
|---|
|  | 64 | IF(_def) | 
|---|
|  | 65 | SET(_flag_str "${_flag_str} -D${_def}") | 
|---|
|  | 66 | ENDIF(_def) | 
|---|
|  | 67 | ENDFOREACH(_def) | 
|---|
|  | 68 |  | 
|---|
|  | 69 | SEPARATE_FLAGS("${_flag_str}" _flags) | 
|---|
|  | 70 | LIST(REMOVE_DUPLICATES _flags) | 
|---|
|  | 71 | SET(${_flagsvar} ${_flags} PARENT_SCOPE) | 
|---|
|  | 72 |  | 
|---|
|  | 73 | ENDFUNCTION(GET_GCC_COMPILER_FLAGS) | 
|---|