Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
992 views
in Technique[技术] by (71.8m points)

cmake - Disable install for FetchContent

Let's say I have the following code:

include(FetchContent)
FetchContent_Declare(cmark
  GIT_REPOSITORY https://github.com/commonmark/cmark.git
  GIT_TAG        0.29.0
)
FetchContent_MakeAvailable(cmark)

target_link_libraries(hello_world cmark::cmark_static)
install(TARGETS hello_world DESTINATION bin)

That works correctly, but whenever I run make install, it also installs all the cmark files (like include/cmark_version.h, lib/pkgconfig/libcmark.pc, etc).

Is there any way to disable installing files from packages with FetchContent?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The macro FetchContent_MakeAvailable includes subproject with use of add_subdirectory command. And this command has as special option - EXCLUDE_FROM_ALL - for disable inner install calls.

So, you may replace call FetchContent_MakeAvailable with:

FetchContent_GetProperties(cmark)
if(NOT cmark_POPULATED)
  FetchContent_Populate(cmark)
  add_subdirectory(${cmark_SOURCE_DIR} ${cmark_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

(This is actually an exact alternative to FetchContent_GetProperties call noted in the FetchContent documentation but with additional EXCLUDE_FROM_ALL parameter.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...