0

I have following project structure

CmakeLists.txt
    src/main.cpp
      A/CMakeLists.txt
      A/test.cpp
      B/CMakeLists.txt
      B/other.cpp
   libs/

The build configuration is written in a way that the sub-directories are compiled as static libraries (stored into libs) and then they are used to produce final binary.

Now suppose I transfer this project to my bud, with only CMakeLists.txt, source-files and static libraries in libs.

When compiling the project, he/she have to recompile again all the source files, despite the libraries are already there.

Is there any way to tell cmake to re-use pre-build static libraries ??

Excerpt from top cmakelist.txt .

add_subdirectory (${PROJECT_SOURCE_DIR}/src/A)
add_subdirectory (${PROJECT_SOURCE_DIR}/src/B)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libs)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libs)

add_executable(myBinary ${PROJECT_SOURCE_DIR}/src/main.cpp )
add_dependencies(myBinary A B)
target_link_libraries (myBinary A B)

Subdirectory cmakelist.txt .

project (A)
file(GLOB SOURCES "*.cpp")
add_library (A STATIC ${SOURCES})
libxelar.so
  • 473
  • 4
  • 16
  • 1
    When you build a library with CMake, it is built in the **build tree**, and a *build tree* is not supposed to be transferable to other machine. So you may transfer only a *source tree*, not a *build* one. If you want your colleague to use the libraries which have already built, put created library files into the *source tree* (and adjust `CMakeLists.txt` to use prebuilt libraries). – Tsyvarev Nov 10 '19 at 09:23
  • If you want to transfer the results of a build around, it is suggested to install them and transfer the install tree around. Here, headers and libraries should be installed. You'll also likely want a package configuration file if the library is going to be used from another CMake project. – mathstuf Nov 10 '19 at 11:45
  • @Tsyvarev ._put created library files into the source tree (and adjust CMakeLists.txt to use prebuilt libraries_ , that was exactly my question. How should I do that? suppose I moved libraries to src/libs. what then ? – libxelar.so Nov 10 '19 at 13:25
  • If you ask about linking pre-built libraries, then see that question: https://stackoverflow.com/questions/8774593/cmake-link-to-external-library. – Tsyvarev Nov 10 '19 at 13:28

0 Answers0