Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,806
    • Issues 3,806
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 8
    • Merge requests 8
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #18959

Closed
Open
Created Feb 21, 2019 by Cristian Morales Vega@RedDwarfContributor

Improve behavior when user changes CMAKE_CXX_COMPILER

cmake 3.13.4

CMAKE_CXX_FLAGS are ignored when reconfiguring with a different CMAKE_CXX_COMPILER

In the following output you can see I start using clang++ with -O1. I moved to -O2, keeping clang++, and everything is OK.

Then I move to g++, going back to -O1, and DCMAKE_CXX_FLAGS becomes empty!!!

Rerunning the same command now DCMAKE_CXX_FLAGS is actually -O1 as it should.

$ echo 'cmake_minimum_required(VERSION 3.12)' > CMakeLists.txt
$ cmake -DCMAKE_CXX_COMPILER:STRING=clang++ -DCMAKE_CXX_FLAGS:STRING="-O1" .
-- The C compiler identification is GNU 8.2.1
-- The CXX compiler identification is Clang 7.0.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: XXXXX
$ grep CMAKE_CXX_FLAGS:STRING CMakeCache.txt 
CMAKE_CXX_FLAGS:STRING=-O1
$ cmake -DCMAKE_CXX_COMPILER:STRING=clang++ -DCMAKE_CXX_FLAGS:STRING="-O2" .
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_CXX_FLAGS


-- Build files have been written to: XXXXX
$ grep CMAKE_CXX_FLAGS:STRING CMakeCache.txt 
CMAKE_CXX_FLAGS:STRING=-O2
$ cmake -DCMAKE_CXX_COMPILER:STRING=g++ -DCMAKE_CXX_FLAGS:STRING="-O1" .
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= g++

-- The C compiler identification is GNU 8.2.1
-- The CXX compiler identification is GNU 8.2.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: XXXXX
$ grep CMAKE_CXX_FLAGS:STRING CMakeCache.txt 
CMAKE_CXX_FLAGS:STRING=
$ cmake -DCMAKE_CXX_COMPILER:STRING=g++ -DCMAKE_CXX_FLAGS:STRING="-O1" .
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_CXX_FLAGS


-- Build files have been written to: XXXXX
$ grep CMAKE_CXX_FLAGS:STRING CMakeCache.txt 
CMAKE_CXX_FLAGS:STRING=-O1
$
Edited Feb 21, 2019 by Brad King
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking