Uploaded image for project: 'Percona Server'
  1. Percona Server
  2. PS-5289

Small update to cmake code to allow overwriting any set variable

    Details

    • Type: Improvement
    • Status: On Hold
    • Priority: Medium
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Packaging
    • Labels:
      None

      Description

      In cmake/maintainer.cmake there is the following code;

      # Set warning flags for GCC/Clang
      IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
        SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_C_WARNING_FLAGS}")
      ENDIF()
      # Set warning flags for G++/Clang++
      IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_CXX_WARNING_FLAGS}")
      ENDIF()
      

      I propose changing this to:

      # Set warning flags for GCC/Clang
      IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
        SET(CMAKE_C_FLAGS "${MY_C_WARNING_FLAGS} ${CMAKE_C_FLAGS}")
      ENDIF()
      # Set warning flags for G++/Clang++
      IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        SET(CMAKE_CXX_FLAGS "${MY_CXX_WARNING_FLAGS} ${CMAKE_CXX_FLAGS}")
      ENDIF()
      

      Which makes effectively zero difference (they are just swapped), until you need to pass a flag for example like this;

      -DCMAKE_CXX_FLAGS=-Wno-error

      Which is possible with the second changed code, and not possible with the first (as the first will overwrite any set flags with whatever is set in the cmake/maintainer.cmake script and that includes, for example, -Werror)

      I have tested this, and it works. When the change is in place, and when 

      -DCMAKE_CXX_FLAGS=-Wno-error

      Is passed to cmake, the following is shown during the build process (at the beginning, near where the 0% is about to appear);

       CMAKE_CXX_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter -Werror -Wno-error -fPIC

      versus

       CMAKE_CXX_FLAGS: -Wno-error -fPIC -Werror -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter

      Without the patch.

      And thus 

      -Wno-error

      Will overwrite

      -Werror

      As was instructed by

      -DCMAKE_CXX_FLAGS=-Wno-error

        Smart Checklist

          Attachments

            Activity

              People

              • Assignee:
                evgeniy.patlan Evgeniy Patlan
                Reporter:
                roel.vandepaar Roel Van de Paar (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 52 minutes
                  52m