59 | | # Handle configure.cppflags, configure.optflags, configure.cflags, |
60 | | # configure.cxxflags, configure.ldflags by setting the equivalent CMAKE_*_FLAGS. |
61 | | # |
62 | | # Be aware that a CMake script can always override these flags when it runs, as |
63 | | # they are frequently set internally in function of other CMake build variables! |
| 59 | # CMake honors set environment variables CFLAGS, CXXFLAGS, and LDFLAGS when it |
| 60 | # is first run in a build directory to initialize CMAKE_C_FLAGS, |
| 61 | # CMAKE_CXX_FLAGS, CMAKE_[EXE|SHARED|MODULE]_LINKER_FLAGS. However, be aware |
| 62 | # that a CMake script can always override these flags when it runs, as they |
| 63 | # are frequently set internally in function of other CMake build variables! |
66 | | # configure.args, you have to set manually configure.optflags to "", as it is by |
67 | | # default "-O2" and added to all language-specific flags. If you want to turn off |
68 | | # optimization, explicitly set configue.optflags to "-O0". |
69 | | if {${configure.cppflags} != ""} { |
70 | | # Add the preprocessor flags to the C/C++ compiler flags as CMake does not |
71 | | # honor separately CPPFLAGS (it uses usually add_definitions() for that). |
72 | | # We use the compiler flags for all build types, as they are usually empty. |
73 | | # Cf. also to CMake upstream ticket #12928 "CMake silently ignores CPPFLAGS" |
74 | | # <http://www.cmake.org/Bug/view.php?id=12928>. |
75 | | configure.args-append -DCMAKE_C_FLAGS="${configure.cppflags}" |
76 | | configure.args-append -DCMAKE_CXX_FLAGS="${configure.cppflags}" |
77 | | } |
78 | | if {${configure.cflags} != ""} { |
79 | | # The configure.cflags contain configure.optflags by default. Therefore, we |
80 | | # set the Release flags, which would otherwise overrule the optimization |
81 | | # flags, as they are set by default to "-O3 -NDEBUG". Therefore, be sure |
82 | | # to add "-NDEBUG" to the configure.cflags if you want to turn off |
83 | | # assertions in release builds! |
84 | | configure.args-append -DCMAKE_C_FLAGS_RELEASE="${configure.cflags}" |
85 | | } |
86 | | set cxx_stdlibflags {} |
87 | | if {[info exists configure.cxx_stdlib] && |
88 | | ${configure.cxx_stdlib} ne {} && |
89 | | [string match *clang* ${configure.cxx}]} { |
90 | | set cxx_stdlibflags -stdlib=${configure.cxx_stdlib} |
91 | | } |
92 | | if {${configure.cxxflags} != "" || ${cxx_stdlibflags} != ""} { |
93 | | # The configure.cxxflags contain configure.optflags by default. Therefore, |
94 | | # we set the Release flags, which would otherwise overrule the optimization |
95 | | # flags, as they are set by default to "-O3 -NDEBUG". Therefore, be sure |
96 | | # to add "-NDEBUG" to the configure.cflags if you want to turn off |
97 | | # assertions in release builds! |
98 | | configure.args-append -DCMAKE_CXX_FLAGS_RELEASE="${configure.cxxflags} ${cxx_stdlibflags}" |
99 | | } |
100 | | if {${configure.ldflags} != ""} { |
101 | | # CMake supports individual linker flags for executables, modules, and dlls. |
102 | | # By default, they are empty. |
103 | | configure.args-append -DCMAKE_EXE_LINKER_FLAGS="${configure.ldflags}" |
104 | | configure.args-append -DCMAKE_SHARED_LINKER_FLAGS="${configure.ldflags}" |
105 | | configure.args-append -DCMAKE_MODULE_LINKER_FLAGS="${configure.ldflags}" |
106 | | } |
| 66 | # configure.args, you have to set manually configure.optflags to "", as it is |
| 67 | # by default "-O2" and added to all language-specific flags. If you want to |
| 68 | # turn off optimization, explicitly set configue.optflags to "-O0". |
117 | | platform darwin { |
118 | | pre-configure { |
| 79 | pre-configure { |
| 80 | # The environment variable CPPFLAGS is not considered by CMake. |
| 81 | # (CMake upstream ticket #12928 "CMake silently ignores CPPFLAGS" |
| 82 | # <http://www.cmake.org/Bug/view.php?id=12928>). |
| 83 | # Thus, we have to add them manually to the CFLAGS and CXXFLAGS in the |
| 84 | # pre-configure phase. |
| 85 | if {${configure.cppflags} != ""} { |
| 86 | configure.cflags-append ${configure.cppflags} |
| 87 | configure.cxxflags-append ${configure.cppflags} |
| 88 | } |
| 89 | |
| 90 | # In addition, CMake provides build-type-specific flags for |
| 91 | # Release (-O3 -DNDEBUG), Debug (-g), MinSizeRel (-Os -DNDEBUG), and |
| 92 | # RelWithDebInfo (-O2 -g -DNDEBUG). If the configure.optflags have been |
| 93 | # set (-O2 by default), we have to remove the optimization flags from the |
| 94 | # from the concerned Release build type so that configure.optflags |
| 95 | # gets honored (Debug used by the +debug variant does not set |
| 96 | # optimization flags by default). |
| 97 | if {${configure.optflags} != ""} { |
| 98 | configure.args-append -DCMAKE_C_FLAGS_RELEASE="-NDEBUG" \ |
| 99 | -DCMAKE_CXX_FLAGS_RELEASE="-NDEBUG" |
| 100 | } |
| 101 | |
| 102 | platform darwin { |