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,928
    • Issues 3,928
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 21
    • Merge requests 21
  • 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
  • #18553
Closed
Open
Created Nov 05, 2018 by ddstamenov@ddstamenov

CMAKE_CXX_COMPILER_ARCHITECTURE_ID is empty even when passed to cmake in command line with -D

I passed -DCMAKE_CXX_COMPILER_ARCHITECTURE_ID=x64 in command line to cmake:

cmake ../ -DCMAKE_CXX_COMPILER_ARCHITECTURE_ID=x64

and in CMakeLists.txt I have the following lines:

message(STATUS "CMAKE_CXX_COMPILER_ARCHITECTURE_ID: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")

end it prints empty variable. If run cmake for second time it prints correct value.

Then I changed my CMakeLists.txt to the following:

message(STATUS "CMAKE_CXX_COMPILER_ARCHITECTURE_ID: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
set (CMAKE_CXX_COMPILER_ARCHITECTURE_ID ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})
message(STATUS "CMAKE_CXX_COMPILER_ARCHITECTURE_ID: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")

remove the build directory and run cmake ../ -DCMAKE_CXX_COMPILER_ARCHITECTURE_ID=x64 and then:

-- CMAKE_CXX_COMPILER_ARCHITECTURE_ID: 
-- CMAKE_CXX_COMPILER_ARCHITECTURE_ID: x64

Also I added message in Modules/CMakeDetermineCXXCompiler.cmake

if(CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
...
else()
   message(STATUS "empty CMAKE_CXX_COMPILER_ARCHITECTURE_ID")
endif()

and it is printed.

I tested with: cmake version 3.10.2 (on Ubuntu 18.04) and cmake version 3.12.3

Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)

project(TestCxxArhId)

message(STATUS "CMAKE_CXX_COMPILER_ARCHITECTURE_ID: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
#######   workaround CMAKE_CXX_COMPILER_ARCHITECTURE_ID to be set by command line
set (CMAKE_CXX_COMPILER_ARCHITECTURE_ID ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})
message(STATUS "CMAKE_CXX_COMPILER_ARCHITECTURE_ID: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")

SET(srcfiles main.cpp CACHE INTERNAL "" FORCE) # main.cpp -> just an empty main() function
add_executable(demo ${srcfiles})

Here is a simple main.cpp

int main() {}
Edited Nov 05, 2018 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