0

Currently, when I build my windows project (dynamic library) using CMake, my .dll files go in ./output/bin, my .h files go in ./output/include, but my .lib files go only to ./lib.

Is there anything I can do to make my .lib files go to ./output/lib instead? I didn't do the CMake script and it's pretty big, so I'm not too sure where to look. Here's some snippets I think might be helpful.

macro(artifacts)
    install(TARGETS ${CMAKE_PROJECT_NAME}
            RUNTIME DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/output/bin"
            LIBRARY DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/output/lib"
            )
    foreach(header_file ${includes})
        string(REGEX REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/(include|src)/" "" header_path_buffer ${header_file})
        string(REGEX REPLACE "[^\/]+$" "" header_path ${header_path_buffer})
        install(FILES ${header_file} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/output/include/${header_path})
    endforeach()
endmacro()
        string(REGEX REPLACE "^lib-" ${prefix} CMAKE_PROJECT_NAME ${TL_NAME})
        project(${CMAKE_PROJECT_NAME})
        add_library(${CMAKE_PROJECT_NAME} SHARED ${sources})
        target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC "include" "${thirdparty_include_dirs}")
        set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${includes}")
        set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VERSION ${TL_VERSION})
        set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES SOVERSION "${TL_VERSION_MAJOR}")

Any advice is appreciated.

  • 2
    What is a reason of **installing** files under the **build** tree (under directory specified by `CMAKE_CURRENT_BINARY_DIR` variable)? Your files are already in that tree after you build your project. If you want to build libraries into specific directory, then use `CMAKE_LIBRARY_OUTPUT_DIRECTORY` and similar variables. *Installing* is for placing all needed files into the final location, after which source tree and build tree could be safely deleted. – Tsyvarev Apr 14 '21 at 17:20
  • 1
    As for installing `.lib` files (both static libraries and import libraries), documentation for [install](https://cmake.org/cmake/help/latest/command/install.html#installing-targets) command explicitly tells, that they have `ARCHIVE` kind, not `LIBRARY` one. – Tsyvarev Apr 14 '21 at 17:32
  • Thank you Tsyvarev, this is very helpful. – Luis Angel Urena Lopez Apr 14 '21 at 17:34

0 Answers0