问题描述
我有这个简单的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所评论,这些是CMAKE_CXX_STANDARD_LIBRARIES_INIT从CMake定义的默认值./blob/master/Modules/CMakeCXXInformation.cmake"rel =" nofollow noreferrer> CMakeCXXInformation.cmake
.
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项目中添加不必要的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!