Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list(REMOVE_ITEM) not working in cmake

Tags:

cmake

Following is a part of my CMakeLists.txt file.

file(GLOB SOURCES "xyz/*.cpp")
message("${SOURCES}")
list(REMOVE_ITEM SOURCES "src1.cpp")
message("${SOURCES}")

Here in file "xyz/*.cpp" is a relative path. Content of ${SOURCES} is the same before and after REMOVE_ITEM.

Why is list(REMOVE_ITEM) not working in my case? Any help would be invaluable.

like image 444
sp497 Avatar asked Mar 21 '16 14:03

sp497


1 Answers

I got a solution for your problem. The idea behind my solution is, to get the full path of the special cpp file, because I saw, that the command file(GLOB SOURCES "src/*.cpp") gives me a list of full paths. After getting the full path of the special file, I could do a remove from the list. Here is a small example

cmake_minimum_required(VERSION 3.4)
project(list_remove_item_ex)

file(GLOB SOURCES "src/*.cpp")
# this is the file I want to exclude / remove from the list
get_filename_component(full_path_test_cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/test.cpp ABSOLUTE)
message("${full_path_test_cpp}")

list(REMOVE_ITEM SOURCES "${full_path_test_cpp}")
message("${SOURCES}")
like image 184
devopsfun Avatar answered Dec 28 '22 05:12

devopsfun