Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake install is not installing libraries on Windows

Tags:

windows

cmake

For some reason, the below CMake file fails to install the project libraries. It creates the directory in the right location, and it even recursively installs the headers... But it fails to install the library. How can this be fixed?

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)
like image 716
dicroce Avatar asked Feb 06 '14 01:02

dicroce


People also ask

Can CMake install dependencies?

Any complex software will have its dependencies – be it system API calls or other libraries calls either statically or dynamically linked to it. As a build system generator CMake will help you manage these dependencies in the most natural way possible.

What is Cmake_install CMake file?

As previous answer tells, the cmake_install. cmake contains the commands generated by install command from your CMakeLists. txt . You can execute it by cmake -P cmake_install. cmake and it performs the installation of your project even on windows.


1 Answers

You're just missing the RUNTIME DESTINATION argument in the install(TARGETS...) command.

CMake treats shared libraries as runtime objects on "DLL platforms" like Windows. If you change your command to:

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

then you should find that MyLib.dll ends up in "devel_artifacts/bin".

like image 96
Fraser Avatar answered Oct 03 '22 16:10

Fraser