이것은 매크로의 매개 변수와 ARGN
과 같은 특수 값이 일반적인 CMake 의미에서 변수가 아니기 때문에 발생합니다. C 전처리 기가 매크로를 사용하는 것처럼 문자열 대체입니다.
당신은 변수가 발견을 나열 할 변수와 다음 패스에 입력 인수를 복사 할 수 있습니다 :
foo(test foo bar test foo)
foo("test" foo bar test foo)
foo(test foo;bar;test;foo)
foo("test" foo;bar;test;foo)
foo(test "foo;bar;test;foo")
foo("test" "foo;bar;test;foo")
업데이트,보다 일반적인 :
이
macro(foo a)
set(b "${ARGN}")
list(FIND b "${a}" is_found)
endmacro()
으로이 결과를 다음의 모든 작업이 변형 버전 - "NEXTLIST"단어로 구분 된 여러 목록 검색 :
macro(foo a)
set(is_found)
set(foo_current_list)
foreach(arg ${ARGN})
if(arg STREQUAL "NEXTLIST")
list(FIND foo_current_list "${a}" foo_is_found)
list(APPEND is_found ${foo_is_found})
set(foo_current_list)
else()
list(APPEND foo_current_list ${arg})
endif()
endforeach()
list(FIND foo_current_list "${a}" foo_is_found)
list(APPEND is_found ${foo_is_found})
unset(foo_is_found)
unset(foo_current_list)
endmacro()
foo (test bar bar bar NEXTLIST foo test NEXTLIST test test x test)
message("${is_found}") #-1;1;0
감사합니다. 나는 ARGN을 잊었다. 'foo'에 전달하고자하는 목록이 2 개있는 시나리오는 어떻게됩니까? –
여러 목록을 전달하려면 어떤 방법으로 구분해야합니다. 각 목록에 대해 이름 지정된 인수를 도입 할 수 있지만이 경우에는 공백으로 구분 된 값 목록을 매크로에 간단하게 지정할 수 없습니다. 또는 많은 cmake 명령과 유사하게 특별한 구분 기호를 사용하여 인수를 구별 할 수 있습니다. 여러 목록을 검색 할 수있는 일반 버전으로 답변을 업데이트했습니다. –