[112836] trunk/dports/_resources/port1.0/group/cmake-1.0.tcl

Ryan Schmidt ryandesign at macports.org
Sun Nov 3 10:56:45 PST 2013


On Nov 2, 2013, at 15:43, Ryan Schmidt <ryandesign at macports.org> wrote:

> On Nov 2, 2013, at 12:13, jeremyhu at macports.org wrote:
> 
>> Revision
>> 112836
>> Author
>> jeremyhu at macports.org
>> Date
>> 2013-11-02 10:13:52 -0700 (Sat, 02 Nov 2013)
>> Log Message
>> 
>> Improve the CMake PortGroup so that it handles the configure.*flags. (#40648)
>> 
>> The configure.cppflags, configure.optflags, configure.cflags, configure.cxxflags, configure.ldflags 
>> are handled by setting the equivalent CMAKE_*_FLAGS.
>> 
>> The configure.cppflags are added to the C/C++ compiler flags as CMake does not honor separately 
>> CPPFLAGS (it uses usually add_definitions() for that). The compiler flags for all build types 
>> (CMAKE_C_FLAGS, CMAKE_CXX_FLAGS) are used, as they are usually empty. Cf. also to CMake upstream 
>> ticket #12928 "CMake silently ignores CPPFLAGS" <​
>> http://www.cmake.org/Bug/view.php?id=12928
>>> .
>> 
>> The configure.cflags contain configure.optflags by default. Therefore, they are set via the Release 
>> flags CMAKE_C_FLAGS_RELEASE, which would otherwise overrule the optimization flags, as they are set 
>> by default to "-O3 -NDEBUG". Therefore, be sure to add "-NDEBUG" to the configure.cflags if you 
>> want to turn off assertions in release builds!
>> 
>> The configure.cxxflags contain configure.optflags by default. Therefore, they are set via the 
>> Release flags CMAKE_CXX_FLAGS_RELEASE, which would otherwise overrule the optimization flags, as 
>> they are set by default to "-O3 -NDEBUG". Therefore, be sure to add "-NDEBUG" to the 
>> configure.cflags if you want to turn off assertions in release builds!
>> 
>> A port author has to be aware that a CMake script can always override these flags when it runs, as 
>> they are frequently set internally in function of other CMake build variables!
>> 
>> Attention: If the port author wants to be sure that no compiler flags are passed via configure.args 
>> to CMake, he has to set manually configure.optflags to "", as it is by default "-O2" and added to 
>> all language-specific flags. If he wants to prevent optimization, he should set configure.optflags 
>> to "-O0".
>> 
>> TODO: Handle the compiler flags specific to Objective-C, Fortran, and Java in the CMake PortGroup.
>> 
>> Modified Paths
>> 
>> 	• trunk/dports/_resources/port1.0/group/cmake-1.0.tcl
>> Diff
>> 
>> Modified: trunk/dports/_resources/port1.0/group/cmake-1.0.tcl (112835 => 112836)
>> 
>> --- trunk/dports/_resources/port1.0/group/cmake-1.0.tcl	2013-11-02 16:44:49 UTC (rev 112835)
>> +++ trunk/dports/_resources/port1.0/group/cmake-1.0.tcl	2013-11-02 17:13:52 UTC (rev 112836)
>> 
>> @@ -56,6 +56,58 @@
>> 
>>                     -DCMAKE_FIND_FRAMEWORK=LAST \
>> 
>>                     -Wno-dev
>> 
>> 
>> 
>> +# Handle configure.cppflags, configure.optflags, configure.cflags,
>> +# configure.cxxflags, configure.ldflags by setting the equivalent CMAKE_*_FLAGS.
>> +#
>> +# Be aware that a CMake script can always override these flags when it runs, as
>> +# they are frequently set internally in function of other CMake build variables!
>> +#
>> +# Attention: If you want to be sure that no compiler flags are passed via
>> +# configure.args, you have to set manually configure.optflags to "", as it is by
>> +# default "-O2" and added to all language-specific flags. If you want to turn off
>> +# optimization, explicitly set configue.optflags to "-O0".
>> +if (${configure.cppflags} != "") {
>> +    # Add the preprocessor flags to the C/C++ compiler flags as CMake does not
>> +    # honor separately CPPFLAGS (it uses usually add_definitions() for that).
>> +    # We use the compiler flags for all build types, as they are usually empty.
>> +    # Cf. also to CMake upstream ticket #12928 "CMake silently ignores CPPFLAGS"
>> +    # <
>> http://www.cmake.org/Bug/view.php?id=12928
>>> .
>> +    configure.args-append -DCMAKE_C_FLAGS="${configure.cppflags}"
>> +    configure.args-append -DCMAKE_CXX_FLAGS="${configure.cppflags}"
>> +}
>> +if {${configure.cflags} != ""} {
>> +    # The configure.cflags contain configure.optflags by default. Therefore, we
>> +    # set the Release flags, which would otherwise overrule the optimization
>> +    # flags, as they are set by default to "-O3 -NDEBUG". Therefore, be sure
>> +    # to add "-NDEBUG" to the configure.cflags if you want to turn off
>> +    # assertions in release builds!
>> +    configure.args-append -DCMAKE_C_FLAGS_RELEASE="${configure.cflags}"
>> +}
>> +if {${configure.cxxflags} != ""} {
>> +    # The configure.cxxflags contain configure.optflags by default. Therefore,
>> +    # we set the Release flags, which would otherwise overrule the optimization
>> +    # flags, as they are set by default to "-O3 -NDEBUG". Therefore, be sure
>> +    # to add "-NDEBUG" to the configure.cflags if you want to turn off
>> +    # assertions in release builds!
>> +    configure.args-append -DCMAKE_CXX_FLAGS_RELEASE="${configure.cxxflags}"
>> +}
>> +if {${configure.ldflags} != ""} {
>> +    # CMake supports individual linker flags for executables, modules, and dlls.
>> +    # By default, they are empty.
>> +    configure.args-append -DCMAKE_EXE_LINKER_FLAGS="${configure.ldflags}"
>> +    configure.args-append -DCMAKE_SHARED_LINKER_FLAGS="${configure.ldflags}"
>> +    configure.args-append -DCMAKE_MODULE_LINKER_FLAGS="${configure.ldflags}"
>> +}
> 
> This doesn’t work because portgroups are typically included at the top of the portfile, before any of these options are set. So if you have a Portfile like this…
> 
> 
> 1. PortGroup           cmake 1.0
> 2.
> 3. name                foo
> 4. version             1.0
> 5. 
> 6. configure.cppflags-append -I${prefix}/foo/include
> 
> 
> …this won’t work, because the cmake portgroup has already added the default value of configure.cppflags to configure.args on line 1, before the portfile has had a chance to customize it on line 6.

Yup, this is breaking the vtk5 build which uses:

configure.cxxflags-append \
        -DUSE_INTERP_ERRORLINE


> For this reason a portgroup should wait to check options until a pre-phase block, in this case a pre-configure block.




More information about the macports-dev mailing list