简体   繁体   English

如何在 Visual Studio 的 CMakeLists.txt 文件中设置 CLion 构建架构?

[英]How to set the CLion build architecture in the CMakeLists.txt file for Visual Studio?

In CLion, how can I set the Visual Studio build architecture in the CMakeLists.txt file ?在 CLion 中,如何在 CMakeLists.txt 文件中设置 Visual Studio 构建架构?

According to cmake.org , one can set host=x64 in the CMAKE_GENERATOR_TOOLSET option.根据cmake.org ,可以在 CMAKE_GENERATOR_TOOLSET 选项中设置 host=x64 。

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_GENERATOR_TOOLSET 选项中指定 host=x86 或 host=x64 值,VS 2013 及更高版本的 Visual Studio 生成器支持使用 32 位或 64 位主机工具链。 CMake provides the selected toolchain architecture preference in this variable (x86, x64, or empty). CMake 在此变量中提供选定的工具链架构首选项(x86、x64 或空)。

But whatever I do, it has no effect when I click on run in CLion.但是无论我做什么,当我在 CLion 中单击 run 时它都不起作用。

CMakeLists.txt: 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.我能做的是在 CLion 设置中设置一个额外的工具链,并将所需的工具链设置为默认工具链,但包含的缓慢绝对是可怕的,而不是我想要的。
I want to set the executable architecture in the CMakeLists.txt file, so I can quickly switch, in a second.我想在 CMakeLists.txt 文件中设置可执行架构,以便我可以在一秒钟内快速切换。

For example, on Linux, where I use gcc, I can just set either例如,在 Linux 上,我使用 gcc,我可以只设置

set(CMAKE_C_FLAGS -m32)

or或者

set(CMAKE_CXX_FLAGS -m32)

But unfortunately, the Visual-Studio-Compiler seems to not have such an option...但不幸的是,Visual-Studio-Compiler 似乎没有这样的选项......

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您需要在 Settings -> Build, Execution, Deployment -> Toolchain 下将您的工具链更新为 x64(在我的情况下为amd64 ),并确保更新 CMake 配置文件

工具链设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM