How not to build a library if it is not used?

I use cmake and create a library through the function:

add_library(network_transport)

I add the library via the function:

target_link_libraries(${CMAKE_PROJECT_NAME} network_transport)

I noticed that if you remove target_link_libraries, the library is still assembled when completely reassembled. Is it possible to skip this if it (the library) is not used in this assembly?

Upvotes: 0

Views: 248

Answers (1)

KamilCuk
KamilCuk

Reputation: 141145

Add EXCLUDE_FROM_ALL to... exclude target from building when building them all.

add_library(network_transport EXCLUDE_FROM_ALL)

Or typically with third-party libraries:

add_subdirectory(dir/with/network_transport EXCLUDE_FROM_ALL)

Upvotes: 2

Related Questions