为什么CMake会在Visual Studio项目中添加不必要的库? [英] Why CMake adds unnecessary libraries to Visual studio project?

查看:164
本文介绍了为什么CMake会在Visual Studio项目中添加不必要的库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个简单的CMake文件

I have this simple CMake file

cmake_minimum_required(VERSION 2.8)
project(test)
set(SOURCES source.cpp)
add_executable(test ${SOURCES})

其中source.cpp是一个简单的hello world程序.然后,我生成Visual Studio项目

where source.cpp is a simple hello world program. I then generate the Visual Studio project

cmake -G"Visual Studio 14 2015" ..\Sources  

生成的Visual Studio项目在Configuration Properties > Linker > Input > Additional Dependencies下具有以下库:

The generated Visual Studio project has the following libraries, under Configuration Properties > Linker > Input > Additional Dependencies:

kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib

如果删除这些库,我仍然可以成功构建并运行hello world.

If I remove these libraries I can still successfully build and run the hello world.

为什么CMake会添加所有这些库,我该怎么办才能使它们不包含在我的项目中?

Why does CMake add all these libraries and what can I do to not have them in my projects?

推荐答案

如@Vertexwahn所评论,这些是

As commented by @Vertexwahn those are the defaults defined from CMake by CMAKE_CXX_STANDARD_LIBRARIES_INIT in CMakeCXXInformation.cmake.

我只想添加一个简单的AdditionalDependencies宏替换项,发现它此处:

I just wanted to add a simple AdditionalDependencies macro replacement found here:

cmake_minimum_required(VERSION 3.0)

file(
    WRITE "${CMAKE_BINARY_DIR}/MakeRulesOverwrite.cmake"
[=[
    if (MSVC)        
        set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "%(AdditionalDependencies)")
    endif()
]=]
)
set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_BINARY_DIR}/MakeRulesOverwrite.cmake")

project(test)
...

参考

  • CMAKE_USER_MAKE_RULES_OVERRIDE
  • what is %(AdditionalDependencies) macro?
  • Change default value of CMAKE_CXX_FLAGS_DEBUG and friends in CMake

这篇关于为什么CMake会在Visual Studio项目中添加不必要的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆