install works only for RUNTIME

Hello,
I try to solve generating 3rd-party .dll files to the executable folder or install folder with install(TARGETS). The install works only for RUNTIME but not for LIBRARY others. Here is my code:

INSTALL(TARGETS ${PROJECT_NAME} 
    RUNTIME DESTINATION ${CMAKE_INSTALL_PATH}/bin
    LIBRARY DESTINATION ${CMAKE_INSTALL_PATH}/lib
    ARCHIVE DESTINATION ${CMAKE_INSTALL_PATH}/lib
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PATH}/include
    PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_PATH}/include)

After compilation of the project, a folder named install comes out correctly under the ${CMAKE_INSTALL_PATH} and also a subdirectory bin shown there with an executable file inside but nothing else was found.

4>------ Rebuild All started: Project: INSTALL, Configuration: Debug Win32 ------
4>  -- Install configuration: "Debug"
4>  -- Installing: D:/win32/Project/source/../install/bin/Prjoect.exe
========== Rebuild All: 4 succeeded, 0 failed, 0 skipped ==========

You wouldn’t normally add the ${CMAKE_INSTALL_PATH} prefix to the various destinations.

There isn’t enough information here to know what the cause could be. Please post a complete, minimal project which someone else can use to reproduce the problem on their machine. Cut down your real project as far as you can, removing anything that isn’t relevant to the issue you are seeing.

Thanks for reply, @craig.scott. Later, I modified it as shown below.

     # Install
    if(MSVC)
     set(CMAKE_INSTALL_PATH ${PROJECT_SOURCE_DIR}/../install CACHE STRING "installation path")
     message(${CMAKE_INSTALL_PATH})
    endif()
     set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/../install)
     message(${CMAKE_INSTALL_PREFIX})

    INSTALL(TARGETS ${PROJECT_NAME} 
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    )

    INSTALL(DIRECTORY ${PROJECT_SOURCE_DIR}/include DESTINATION ${CMAKE_INSTALL_PATH})

This modification gives a bin folder and an include folder in the “install” one. It still failed to generate lib folder and anything related to that. The project is very simple. The tree structure looks like

\source 
       \include 
            \header.h
       \src 
            \header.cpp
            \main.cpp
      \CMakeLists.txt

and a

\build

It is the same level for source, build and install.
In CMakeLists.txt, there are few libraries and can be found correctly during configuration of cmake-gui. OpenCV is shown here as an example

    # opencv 
    set(CMAKE_PREFIX_PATH "D:/opencv343")
    find_package(OpenCV REQUIRED)
    message(${OpenCV_INCLUDE_DIRS})
    message(${OpenCV_LIBS})

    # Update LIBRARIES variable
    LIST(APPEND LIBRARIES
    ${OpenCV_LIBS})

    # include
    include_directories(
    ${PROJECT_SOURCE_DIR}/include
    )

    # source
    aux_source_directory(${PROJECT_SOURCE_DIR}/src SRCFILES)

    # Executable
    add_executable(${PROJECT_NAME} ${SRCFILES})
    target_link_libraries(${PROJECT_NAME} ${LIBRARIES})

and then they are only codes given at the beginning of my post.

The only target you are installing is an executable. If you are expecting the OpenCV libraries to be installed as well, you have to install those yourself. I’d recommend you checkout the CMake docs for the file(GET_RUNTIME_DEPENDENCIES) command for that.

This would have been easier if you had provided a complete CMakeLists.txt rather than making others piece one together from fragments.

I found this before having my post. Is there a version limitation in using this command. Thanks.

file(GET_RUNTIME_DEPENDENCIES) is available with CMake 3.16 or later.

:joy: I don’t want to update my cmake which has been used since 2017.