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 |
---|
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() |
---|
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 | IF(${_target_type} STREQUAL SHARED_LIBRARY) |
---|
61 | GET_TARGET_PROPERTY(_target_def_symbol ${_target} DEFINE_SYMBOL) |
---|
62 | ENDIF() |
---|
63 | |
---|
64 | # Prefix them all with a "-D" if the property was found |
---|
65 | FOREACH(_def ${_directory_defs} ${_directory_defs_build_type} ${_target_defs} |
---|
66 | ${_target_defs_build_type} ${_target_def_symbol}) |
---|
67 | IF(_def) |
---|
68 | SET(_flag_str "${_flag_str} -D${_def}") |
---|
69 | ENDIF(_def) |
---|
70 | ENDFOREACH(_def) |
---|
71 | |
---|
72 | SEPARATE_FLAGS("${_flag_str}" _flags) |
---|
73 | LIST(REMOVE_DUPLICATES _flags) |
---|
74 | SET(${_flagsvar} ${_flags} PARENT_SCOPE) |
---|
75 | |
---|
76 | ENDFUNCTION(GET_GCC_COMPILER_FLAGS) |
---|