← Back to team overview

kicad-developers team mailing list archive

Re: Build flags

 

On 11/13/2013 10:47 AM, Maciej Sumiński wrote:
> Recently I wanted to play with build flags and I have noticed that they 
> are overwritten by CMakeLists.txt (see patch attached).
> I am just wondering - is there any specific reason for that? Does anyone 
> mind appending build flags instead of setting them constant?


This is not what you are doing. In one instance, you are setting CMAKE_CXX_FLAGS_RELEASE
from CMAKE_CXX_FLAGS.

This is a misunderstanding of how CMake works.

When the compiler is invoked, there is a concatenation done for you:

CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_<BUILD_TYPE>

Verify this with $ make VERBOSE=1

and watch.


What are the initial values of these flags that you are trying to preserve, and where are
they coming from?
(Part of why we set them, is we do not *want* to inherit anyone else's idea of what is
correct.)

Are you setting them on the command line?

After they are initially set by us, then a concatenation is appropriate for subsequent
mods obviously.

More comments below:


>
> Regards,
> Orson
>
> cmakefiles.patch
>
>
> === modified file 'CMakeLists.txt'
> --- CMakeLists.txt	2013-11-10 19:15:09 +0000
> +++ CMakeLists.txt	2013-11-13 16:44:02 +0000
> @@ -88,8 +88,8 @@
>  
>      # Establish -Wall early, so specialized relaxations of this may come
>      # subsequently on the command line, such as in pcbnew/github/CMakeLists.txt
> -    set( CMAKE_C_FLAGS   "-Wall" )
> -    set( CMAKE_CXX_FLAGS "-Wall" )

Please explain why these two:

> +    set( CMAKE_C_FLAGS   "-Wall ${CMAKE_C_FLAGS}" )
> +    set( CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS}" )
>  
>      # The optimization level is -O1 instead of the usual -O2 level because
>      # boost::polygon has a function (inflate polygon) broken by the -O2 level
> @@ -99,21 +99,21 @@
>      #   https://bugs.launchpad.net/kicad/+bug/1056926
>      #   https://svn.boost.org/trac/boost/ticket/7983
>      if( GCC_VERSION VERSION_EQUAL 4.7.0 OR ( GCC_VERSION VERSION_GREATER 4.7.0 AND GCC_VERSION VERSION_LESS 4.7.3 ) )
> -        set( CMAKE_C_FLAGS_RELEASE   "-O1" )
> -        set( CMAKE_CXX_FLAGS_RELEASE "-O1" )

No, definitely not these:

> +        set( CMAKE_C_FLAGS_RELEASE   "${CMAKE_C_FLAGS} -O1" )
> +        set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O1" )
>      else()
> -        set( CMAKE_C_FLAGS_RELEASE   "-O2" )
> -        set( CMAKE_CXX_FLAGS_RELEASE "-O2" )

Why, where are these coming from? What are their initial values?

> +        set( CMAKE_C_FLAGS_RELEASE   "${CMAKE_C_FLAGS_RELEASE} -O2" )
> +        set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" )
>      endif()
>  
> -    set( CMAKE_C_FLAGS_DEBUG   "-g3 -ggdb3 -DDEBUG" )
> -    set( CMAKE_CXX_FLAGS_DEBUG "-g3 -ggdb3 -DDEBUG" )
> +    set( CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG} -g3 -ggdb3 -DDEBUG" )
> +    set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -ggdb3 -DDEBUG" )
>  
>      set( CMAKE_C_FLAGS_RELEASE   "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG" )
>      set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG" )
>  
>      if( MINGW )
> -        set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" )
> +        set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s ${CMAKE_EXE_LINKER_FLAGS_RELEASE}" )
>  
>          # _UNICODE definition seems needed under mingw/gcc 4.8
>          # (Kicad uses unicode, and on Windows, wxWidgets >= 2.9.4 is mandatory
> @@ -146,11 +146,11 @@
>          set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PIC_FLAG}" )
>  
>          # Thou shalt not link vaporware and tell us it's a valid DSO:
> -        set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
> -        set( CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined" ) # needed by SWIG macros on linux
> +        set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
> +        set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined" ) # needed by SWIG macros on linux
>  
>          # Set default flags for Release build.
> -        set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" )
> +        set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s" )
>  
>      endif()
>  
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp



References