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 9111613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:32:53+00:00 2026-06-17T03:32:53+00:00

I use CMake to generate unix makefiles. After that I compile project using make

  • 0

I use CMake to generate unix makefiles. After that I compile project using make utility.
Problem is that I can’t see any warnings! For example, this results in clean build without warnings:

#include <iostream>

class Foo
{
    int first;
    int second;
public:
    Foo(int a, int b)
    : second(a) // invalid initialization order
    , first(b)
    {
    }
};

int main(int argc, char** argv)
{
    int unused; // unused variable
    int x;
    double y = 3.14159;
    x = y; // invalid cast
    Foo foo(1,2);
    std::cout << y << std::endl;
    return 0;
}

Unused variable and lossy variable cast – no warnings! My CMakeLists.txt file is minimalistic:

cmake_minimum_required(VERSION 2.8)

add_executable(main main.cpp)

When I run cmake and then make my output looks like this:

[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
Linking CXX executable main
[100%] Built target main

But when I add this line of code:

#warning ("Custom warning")

resulting output contains warning:

[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
../src/main.cpp:15:2: warning: #warning ("Custom Warning") [-Wcpp]
Linking CXX executable main
[100%] Built target main

I use Ubuntu 12.04 LTS and GCC as a compiler. Maybe CMake passes some flag to compiler that results in absence of warnings. How can I check it? I can’t read makefiles generated by CMake, they are a little bit cryptic.

  • 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-17T03:32:54+00:00Added an answer on June 17, 2026 at 3:32 am

    The positions on compiler warnings are divided. There are package maintainers who will tell you that they know what they are doing, and compiler warnings should be ignored in any case. (I think they couldn’t be more wrong.) But I guess that is why CMake mostly leaves the warning settings alone.

    If you want to be a bit more sophisticated about it, check for the compiler being used, and add the flag to the specific property of the specific target.

    Apply to a Single Target

    if ( CMAKE_COMPILER_IS_GNUCC )
        target_compile_options(main PRIVATE -Wall -Wextra)
    endif()
    if ( MSVC )
        target_compile_options(main PRIVATE /W4)
    endif()
    

    Apply to All Targets

    if ( CMAKE_COMPILER_IS_GNUCC )
        set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -Wall -Wextra")
    endif()
    if ( MSVC )
        set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} /W4")
    endif()
    

    Note: add -Werror for GCC or /WX for MSVC to treat all warnings as errors. This will treat all warnings as errors. This can be handy for new projects to enforce warning strictness.

    Also, -Wall -Wextra does not mean "all errors"; historically -Wall meant "all errors that everybody could agree on", and -Wextra "some more". Start with that, then peruse the manual for your version of GCC, and find what else the compiler can do for you with regards to warnings…

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

Sidebar

Related Questions

Question: Can CMake generate build scripts that do not, in any way, use CMake?
I use cmake to generate qtcreator's project files, For the run part I can
I'm trying to use CMake to build generate the make file for a project
I've got the following problem using cmake. I use UseDoxygen from http://tobias.rautenkranz.ch/cmake/doxygen/ to generate
I use a cmake generated makefile to compile a c++ file that depends on
GCC 4.6.0 Linux cmake 2.8 I am using cmake to generate my make file.
I use CMake with GNU Make and would like to see all commands exactly
I'm trying to use ios-cmake to generate Xcode project targeting iOS. However, it cannot
I've been using qmake and CMake in the past without any problem to generate
I'm using cmake with C++ project. I want to use precompiled headers in GCC.

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.