Как избежать повторных сборок и ускорить сборку с помощью CMake? ⇐ C++
-
Anonymous
Как избежать повторных сборок и ускорить сборку с помощью CMake?
I am currently working on adding CMake support to a library that currently uses waf as its build system. The code I have for CMake is excruciatingly slow compared to the existing build system with waf, and I believe it is because of the following reason.
The part of my CMake code that adds libraries and executables looks something like this
# USE_PACKAGES is a variable with loaded libraries like Boost::serialization add_library(library_a SHARED) target_sources(library_a PUBLIC ${LIBRARY_A_SOURCES} target_link_libraries(library_a PRIVATE ${USE_PACKAGES}) add_library(library_b SHARED) target_sources(library_b PUBLIC ${LIBRARY_A_SOURCES} target_link_libraries(library_b PRIVATE ${USE_PACKAGES} library_a) add_executable(executable) target_sources(executable PUBLIC ${LIBRARY_A_SOURCES} target_link_libraries(executable PRIVATE ${USE_PACKAGES} library_a library_b) What I can see is that first make builds library_a, then in order to build library_b, it builds both library_b and library_a, and then to build the executable, it builds executable, library_b, and library_a. I believe this is the source of why make is being slow. Is there a way to build every library only once?
I tried playing with the visibility a bit, but changing the PRIVATE to PUBLIC does not seem to change this behaviour.
Источник: https://stackoverflow.com/questions/780 ... sing-cmake
I am currently working on adding CMake support to a library that currently uses waf as its build system. The code I have for CMake is excruciatingly slow compared to the existing build system with waf, and I believe it is because of the following reason.
The part of my CMake code that adds libraries and executables looks something like this
# USE_PACKAGES is a variable with loaded libraries like Boost::serialization add_library(library_a SHARED) target_sources(library_a PUBLIC ${LIBRARY_A_SOURCES} target_link_libraries(library_a PRIVATE ${USE_PACKAGES}) add_library(library_b SHARED) target_sources(library_b PUBLIC ${LIBRARY_A_SOURCES} target_link_libraries(library_b PRIVATE ${USE_PACKAGES} library_a) add_executable(executable) target_sources(executable PUBLIC ${LIBRARY_A_SOURCES} target_link_libraries(executable PRIVATE ${USE_PACKAGES} library_a library_b) What I can see is that first make builds library_a, then in order to build library_b, it builds both library_b and library_a, and then to build the executable, it builds executable, library_b, and library_a. I believe this is the source of why make is being slow. Is there a way to build every library only once?
I tried playing with the visibility a bit, but changing the PRIVATE to PUBLIC does not seem to change this behaviour.
Источник: https://stackoverflow.com/questions/780 ... sing-cmake
Мобильная версия