【问题标题】:CMake: Avoiding inclusion of Windows SDK from CMakeLists.txt. Using MinGW instead msvcCMake:避免在 CMakeLists.txt 中包含 Windows SDK。使用 MinGW 代替 msvc
【发布时间】:2021-06-09 13:03:48
【问题描述】:

我有一个编译正确的项目,当我从命令行配置它时

cmake ..  -DCMAKE_GENERATOR="MinGW Makefiles"
generator is set to MinGW Makefiles
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/jose/Documents/ApD_PRG/test_v2/Build

但令人惊讶的是当我在 CMakeLists.txt

的开头调整它时却没有
cmake_minimum_required(VERSION 3.13)
set (CMAKE_GENERATOR "MinGW Makefiles" CACHE INTERNAL "" FORCE)
message("generator is set to ${CMAKE_GENERATOR}")

set(CMAKE_PROJECT_NAME "testProject")
...

$ cmake ..
-- Building for: Visual Studio 14 2015
generator is set to MinGW Makefiles
-- Selecting Windows SDK version  to target Windows 10.0.18363.   <--------- HERE!!!
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/jose/Documents/ApD_PRG/test_v2/Build

自动获取 Windows SDK,项目不再编译。

请哪位好心人帮助我避免从 CMakeLists.txt 中包含 Windows SDK?

提前致谢

pd:我需要这种方式,因为我希望 eclipse 在导入时自动选择正确的编译器

【问题讨论】:

    标签: c++ windows cmake mingw


    【解决方案1】:

    它不起作用,因为您根本无法从 CMakeLists.txt 文件中设置生成器。

    来自documentation(强调我的)

    这个变量的值永远不应该被项目代码修改。可以通过 cmake(1) -G 选项,在 cmake-gui(1) 中交互,或者通过CMAKE_GENERATOR 环境变量。

    由于我不熟悉 Eclipse,我无法保证它可以正常工作,但您可以尝试在使用 CMake 3.15 或更高版本时将 CMAKE_GENERATOR env-variable 设置为 MinGW Makefiles

    但是,很有可能

    • 您正在使用的 CMake 插件需要了解正在使用的生成器,以便能够解析构建输出,因此手动将插件中配置的生成器的 -G &lt;generator&gt; 添加到 CMake 调用中,从而覆盖环境变量中设置的值,或
    • Eclipse 插件只知道如何处理默认生成器的输出,但也不使用-G &lt;generator&gt; 强制执行它,在这种情况下,您设置不同的生成器可能会导致它无法解析构建输出的错误/ 警告。

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 2018-08-13
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-21
      • 2018-08-23
      • 2012-04-09
      相关资源
      最近更新 更多