CMake安装不是在Windows上安装库

时间:2014-02-06 01:38:02

标签: windows cmake

由于某种原因,以下CMake文件无法安装项目库。它在正确的位置创建目录,甚至递归安装头...但它无法安装库。如何解决这个问题?

cmake_minimum_required(VERSION 2.8)
project(MyLib)

include_directories(include)
add_library(MyLib SHARED source/stuff.cpp)

if(CMAKE_SYSTEM MATCHES "Windows")
target_link_libraries(MyLib DbgHelp ws2_32 iphlpapi)
set(CMAKE_INSTALL_PREFIX "../../devel_artifacts")
endif(CMAKE_SYSTEM MATCHES "Windows")

install(TARGETS MyLib LIBRARY DESTINATION "lib"
                      ARCHIVE DESTINATION "lib"
                      COMPONENT library)
install(DIRECTORY include/${PROJECT_NAME} DESTINATION include)

1 个答案:

答案 0 :(得分:7)

您只是错过install(TARGETS...)命令中的RUNTIME DESTINATION参数。

CMake将共享库视为Windows等“DLL平台”上的运行时对象。如果您将命令更改为:

install(TARGETS MyLib LIBRARY DESTINATION "lib"
                      ARCHIVE DESTINATION "lib"
                      RUNTIME DESTINATION "bin"
                      COMPONENT library)

然后您会发现MyLib.dll最终出现在“devel_artifacts / bin”中。