From e7925279ab0cfc6f46a828ec8d329fcc4f25b2aa Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 15 Oct 2012 21:42:50 -0400 Subject: [PATCH] Only use -O1 GCC optimization level for versions 4.7 and above for now. --- CMakeLists.txt | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd1da4ee26..927adcbf43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules) # KiCad build options should be added below. # # If you add a new build option, please add it's state to the CopyVersionInfoToClipboard() -# function in common/basicframe.cpp so that build option settings can be includeed in bug +# function in common/basicframe.cpp so that build option settings can be included in bug # reports. # @@ -103,6 +103,13 @@ endif( USE_PCBNEW_SEXPR_FILE_FORMAT AND NOT USE_PCBNEW_NANOMETRES ) #================================================ if(CMAKE_COMPILER_IS_GNUCXX) + set(KICAD_GCC_RELEASE_BUILD_FLAGS "-O2") + set(KICAD_GCC_RELEASE_DEBUG_FLAGS "") + + execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion + OUTPUT_VARIABLE GCC_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + # Added -Wno-narrowing on 10/7/12 to prevent a huge number of warnings when # compiling with GCC 4.7. This appears to be caused by and int to unsigned # conversion in the Boost polygon library. At some point in the future when @@ -114,24 +121,40 @@ if(CMAKE_COMPILER_IS_GNUCXX) # the -O2 level with GCC 4.7 (works fine with with GCC 4.6). # This lower optimization level does not have a significant change on the speed. # + # As newer versions of GCC and/or Boost are released, this code needs reviewed to + # determine if the problems above have been fixed either in Boost or GCC. + if(GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7) + set(KICAD_GCC_RELEASE_BUILD_FLAGS "-Wno-narrowing -O1") + set(KICAD_GCC_DEBUG_BUILD_FLAGS "-Wno-narrowing") + endif() + + if(CMAKE_BUILD_TYPE STREQUAL Debug) + message(STATUS + "Setting GCC version ${GCC_VERSION} build flags \"${KICAD_GCC_DEBUG_BUILD_FLAGS}\"") + else(CMAKE_BUILD_TYPE STREQUAL Debug) + message(STATUS + "Setting GCC version ${GCC_VERSION} build flags \"${KICAD_GCC_RELEASE_BUILD_FLAGS}\"") + endif(CMAKE_BUILD_TYPE STREQUAL Debug) + + if(WIN32) # under Windows/mingw, -fPIC option is enabled by default # Set default flags for Release build. - set(CMAKE_C_FLAGS_RELEASE "-Wall -Wno-narrowing -O1 -DNDEBUG") - set(CMAKE_CXX_FLAGS_RELEASE "-Wall -Wno-narrowing -O1 -DNDEBUG") + set(CMAKE_C_FLAGS_RELEASE "-Wall ${KICAD_GCC_RELEASE_BUILD_FLAGS} -DNDEBUG") + set(CMAKE_CXX_FLAGS_RELEASE "-Wall ${KICAD_GCC_RELEASE_BUILD_FLAGS} -DNDEBUG") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s") # Set default flags for Debug build. - set(CMAKE_C_FLAGS_DEBUG "-Wall -Wno-narrowing -g3 -ggdb3 -DDEBUG") - set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Wno-narrowing -g3 -ggdb3 -DDEBUG") + set(CMAKE_C_FLAGS_DEBUG "-Wall ${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG") + set(CMAKE_CXX_FLAGS_DEBUG "-Wall ${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG") else(WIN32) # Set default flags for Release build. - set(CMAKE_C_FLAGS_RELEASE "-Wall -O1 -DNDEBUG -fPIC") - set(CMAKE_CXX_FLAGS_RELEASE "-Wall -O1 -DNDEBUG -fPIC") + set(CMAKE_C_FLAGS_RELEASE "-Wall ${KICAD_GCC_RELEASE_BUILD_FLAGS}1 -DNDEBUG -fPIC") + set(CMAKE_CXX_FLAGS_RELEASE "-Wall ${KICAD_GCC_RELEASE_BUILD_FLAGS}1 -DNDEBUG -fPIC") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s") # Set default flags for Debug build. - set(CMAKE_C_FLAGS_DEBUG "-Wall -Wno-narrowing -g3 -ggdb3 -DDEBUG -fPIC") - set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Wno-narrowing -g3 -ggdb3 -DDEBUG -fPIC") + set(CMAKE_C_FLAGS_DEBUG "-Wall ${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG -fPIC") + set(CMAKE_CXX_FLAGS_DEBUG "-Wall ${KICAD_GCC_DEBUG_BUILD_FLAGS} -g3 -ggdb3 -DDEBUG -fPIC") endif(WIN32) endif(CMAKE_COMPILER_IS_GNUCXX) @@ -162,8 +185,6 @@ endif(KICAD_SCRIPTING_MODULES) if(KICAD_SCRIPTING_WXPYTHON) add_definitions(-DKICAD_SCRIPTING_WXPYTHON) - - endif(KICAD_SCRIPTING_WXPYTHON) if(USE_WX_GRAPHICS_CONTEXT) @@ -171,7 +192,7 @@ if(USE_WX_GRAPHICS_CONTEXT) endif(USE_WX_GRAPHICS_CONTEXT) # Allow user to override the default settings for adding images to menu items. By default -# images in menu items are enabled on all plaforms except OSX. This can be over ridden by +# images in menu items are enabled on all platforms except OSX. This can be over ridden by # defining -DUSE_IMAGES_IN_MENUS=ON/OFF to force the preferred behavior. if(NOT DEFINED USE_IMAGES_IN_MENUS) if(NOT APPLE)