tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: why does devel/cmake's Makefile subst's out compiler optimization?



On Fri, Apr 06, 2018 at 10:42:39AM -0400, Chuck Cranor wrote:
> On Thu, Apr 05, 2018 at 04:40:48PM -0400, Chuck Cranor wrote:
> > in that case you might have to have pkgsrc/mk/configure/cmake.mk
> > set CMAKE_BUILD_TYPE to some non-null dummy value to avoid the 
> > above defaulting behavior...
> 
> following up on this...   it is also possible that cmake-packages
> examine ${CMAKE_BUILD_TYPE} and do something with it, so maybe a
> non-null dummy value could be an issue there.
> 
> 
> I also took at the diff generated by "SUBST_SED.flags=-e 's,-O.,,'"
> and it is problematic as well because it assumes that all the compilers
> that cmake support use the same optimizer flag format and that's 
> not true.   I don't think you can cleanly do what you want to do
> using that simple a sed expression.   for example, the sed broke:
> 
> ARMCC.cmake:
> -  string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Ospace -DNDEBUG")
> +  string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " pace -DNDEBUG")
>                                                        ^^^^
> -  string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -Otime -DNDEBUG")
> +  string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " ime -DNDEBUG")
>                                                     ^^^
> 
> GHS-C.cmake:
> -string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -Odebug -g")
> +string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " ebug -g")
>                                           ^^^^
> 
> -string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -Ospace")
> +string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " pace")
>                                                ^^^^
> -string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -O")
> +string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " )
>                                           ^^    (deleted end quote)
> 
> GHS-CXX.cmake: same issue as GHS-C.cmake above
>  
> GNU.cmake: it broke a URL in a comment:
> -    # [1]: https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gcc/Optimize-Options.html
> +    # [1]: https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gcc/Optimizetions.html
> 
> 
> XL.cmake:
> -  string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O")
> +  string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " )
>                                                   ^^    (deleted end quote)
> 
> -  string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -O")
> +  string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " )
>                                                      ^^    (deleted end quote)
> 
> 
> plus there are compilers configs like SunPro-C.cmake that use other 
> flags for optimization ("-xO3") that the sed skips:
> 
> string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -xO3 -DNDEBUG")
> 
> 
> 
> Rather than using sed, an alternate approach is to look at the
> ~150 compiler config files in work/cmake-3.9.4/Modules/Compiler
> and choose the ones pkgsrc cares about and use patches to change
> them.   You could do something like this:
> 
> --- GNU.cmake_ORIG	2018-04-06 10:20:57.000000000 -0400
> +++ GNU.cmake	2018-04-06 10:22:22.000000000 -0400
> @@ -39,9 +39,15 @@
>    # Initial configuration flags.
>    string(APPEND CMAKE_${lang}_FLAGS_INIT " ")
>    string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g")
> -  string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG")
> -  string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG")
> -  string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
> +  if (PKGSRC-INIT)   # if using pkgsrc, let it use CFLAGS to control opts
> +    string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
> +    string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -DNDEBUG")
> +    string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -g -DNDEBUG")
> +  else (PKGSRC-INIT)
> +    string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG")
> +    string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG")
> +    string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
> +  endif (PKGSRC-INIT)
>    set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
>    set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
>    if(NOT APPLE OR NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4) # work around #4462
> 
> 
> and then have pkgsrc/mk/configure/cmake.mk set a cmake cache variable
> ${PKGSRC-INIT} with "-DPKGSRC-INIT=ON" on its configure command line
> for packages it builds to enable this behavior only for packages built 
> by pkgsrc...   that way CMAKE_BUILD_TYPE would work as expected for
> stuff being built outside of pkgsrc.

That sounds reasonable to me.
Do you want to add patches for gcc and clang and get rid of the SUBST?
 Thomas


Home | Main Index | Thread Index | Old Index