Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7785569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:16:37+00:00 2026-06-01T20:16:37+00:00

Currently to change a compiler flag when using gcc, I edit the CMakeLists.txt for

  • 0

Currently to change a compiler flag when using gcc, I edit the CMakeLists.txt for the build target:

if (UNIX)
    add_definitions(-Wall)
    add_definitions(-g)
    #add_definitions(-O2)
endif (UNIX)

The problem with this is that git picks up the change. If I go ahead and commit this change, I will annoy the other developers who expect to use -O2 instead of -g but they get my version when they pull unrelated changes. Normally, I could just exclude this change from my commits, but when I make an actual change to the CMakeLists.txt file, there is no way to avoid pushing up my personal selection of compile flags.

Is there a way to tell CMake to create a file in the build/ directory (specific to each working copy, and therefore to each developer) that an individual person can modify to their heart’s desire without touching project files (everything but build/). Naturally, our build/ is not committed to the git repository.

It might be helpful to note that when using Visual Studio instead of gcc, the IDE handles this for us through its UI which modifies the VS solution file in build/. The problem is that we have no such mechanism when using GNU Makefiles.

Our project is organized like this:

ourproject/
    bin/
    build/ <-- CMake-generated stuff goes here
    lib/
    src/
        abuildtarget/
        anotherbuildtarget/
            source.cpp
            source.h
            CMakeLists.txt
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:16:38+00:00Added an answer on June 1, 2026 at 8:16 pm

    You are using CMake incorrectly here. The add_definitions function is not for adding compiler options like you are doing; rather, it is to add pre-processor definitions such as add_definitions(-DDEBUG).

    What you want to do is set the CMAKE_<language>_FLAGS when you configure to the options you want. If there is a standard set you need, then put that in the CMakeLists.txt file such as:

    if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel")                                   
      set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -xhost" CACHE STRING "" FORCE)
    
      set(CMAKE_Fortran_FLAGS_NODEBUG "-O0" CACHE STRING "" FORCE)
      mark_as_advanced(CMAKE_Fortran_FLAGS_NODEBUG)
    
      set(CMAKE_Fortran_FLAGS_PROFILING "-O2 -xhost -p" CACHE STRING "" FORCE)
      mark_as_advanced(CMAKE_Fortran_FLAGS_PROFILING)
    
      set(CMAKE_Fortran_FLAGS_DEBUG
          "-DDEBUG -g -check noarg_temp_created -C -traceback" CACHE STRING "" FORCE)
    endif()
    

    Where Fortran can be replaced by CXX or C.

    In this case, the CMAKE_<language>_FLAGS_<build type> sets the flags based on the CMAKE_BUILD_TYPE variable. If it is set to Release, then it uses CMAKE_Fortran_FLAGS_RELEASE. We added several other possible build types. If the user wants something that isn’t one of the standard build types, then they set CMAKE_<language>_FLAGS to whatever they want when configuring and it overrides the build type setting and uses the user-defined flags instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using NSFileManager setAttributes to change the permission of a directory. My problem
I'm currently using msbuild for a solution of over 600 projects. Imagine I change
Currently our website uses links to allow the user to change their locale. The
We currently use VSS 6, this is not going to change I am afraid.
I want the tr that's currently hovered over to change color, and then change
I'm currently implementing a user registration for an app. I'm tying to change the
I'm currently building a simple application on Gjs , which should change the background-image
I have to build my code for two different platforms at once using two
I'm a newbie at using the STL Algorithms and am currently stuck on a
I was developing an application using xcode 4 to target snow leopard (10.6) Now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.