Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake remove added libraries

Tags:

cmake

Is there any way to remove a library from the LINK_LIBRARIES added by target_link_libraries ?

target_link_libraries(Project library1 library2)
get_target_property(cur_cflags Project LINK_LIBRARIES)
message(STATUS ${cur_cflags})
# should print library1 and library2
# here I do something to remove library1
get_target_property(cur_cflags Project LINK_LIBRARIES)
message(STATUS ${cur_cflags})
#should print library2 only

Thanks

like image 1000
user1618465 Avatar asked Apr 01 '18 15:04

user1618465


1 Answers

Check this

target_link_libraries(Project PRIVATE library1 library2)
get_target_property(TARGET_LIBRARIES Project LINK_LIBRARIES)
message("Libraries at start")
message(${TARGET_LIBRARIES})
LIST(REMOVE_ITEM TARGET_LIBRARIES library1 )
message("Modified libraries list")
message(${TARGET_LIBRARIES})
set_property(TARGET Project PROPERTY LINK_LIBRARIES  ${TARGET_LIBRARIES} )
get_target_property(TARGET_LIBRARIES2 Project LINK_LIBRARIES)
message("Libraries after change")
message(${TARGET_LIBRARIES2})
like image 194
Master Yoda Avatar answered Oct 03 '22 13:10

Master Yoda