How to set the CLion build architecture in the CMakeLists.txt file for Visual Studio?
Asked Answered
D

1

9

In CLion, how can I set the Visual Studio build architecture in the CMakeLists.txt file ?

According to cmake.org, one can set host=x64 in the CMAKE_GENERATOR_TOOLSET option.

The Visual Studio Generators for VS 2013 and above support using either the 32-bit or 64-bit host toolchains by specifying a host=x86 or host=x64 value in the CMAKE_GENERATOR_TOOLSET option. CMake provides the selected toolchain architecture preference in this variable (x86, x64, or empty).

But whatever I do, it has no effect when I click on run in CLion.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)
project(native_data_types)

set(CMAKE_CXX_STANDARD 14)

# http://www.saoe.net/blog/generating-64-bit-projects-for-visual-studio-with-cmake/


# https://cmake.org/cmake/help/latest/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE.html
# How to set this ?

# set(host "x64")
# set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE "x64")
# set(CMAKE_GENERATOR_TOOLSET "host=x64")



# set (native_data_types_ARCHITECTURE "x64")
# set(BUILD_ARCH "-m64")
# set(BUILD_ARCH "-m32")

# set(CMAKE_C_FLAGS -m32)
# set(CMAKE_CXX_FLAGS -m32)

# set(CMAKE_C_FLAGS -m64)
# set(CMAKE_CXX_FLAGS -m64)

add_executable(native_data_types main.cpp)

What I can do is set an additional toolchain in the CLion settings, and set the desired toolchain as the default toolchain, but the encompassing slowness is absolutely horrid and not what I want.
I want to set the executable architecture in the CMakeLists.txt file, so I can quickly switch, in a second.

For example, on Linux, where I use gcc, I can just set either

set(CMAKE_C_FLAGS -m32)

or

set(CMAKE_CXX_FLAGS -m32)

But unfortunately, the Visual-Studio-Compiler seems to not have such an option...

Dearr answered 12/2, 2020 at 13:54 Comment(0)
V
14

You need to update your toolchain into x64 (amd64 in my case) under Settings -> Build, Execution, Deployment -> Toolchain and make sure to update CMake profile as well

Toolchain Settings

Valenti answered 13/2, 2020 at 3:50 Comment(2)
this was the solution I was looking for about an hour! Also in my drop down list like yours there was no x64(instead amd64) but I typed it manually and worked fine.Hutton
How to exactly update CMake file after this change?Gingerich

© 2022 - 2024 — McMap. All rights reserved.