← Back to team overview

kicad-developers team mailing list archive

Build flags

 

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?

Regards,
Orson
=== 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" )
+    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" )
+        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" )
+        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()
 

Follow ups