<div dir="ltr">Hello,<div>I am trying to compile the following code snippet:</div><div><br></div><div><div>int main(int argc, char ** argv) {</div><div>  int stack_array[100];</div><div>  stack_array[1] = 0;</div><div>  return stack_array[argc + 100]; // BOOM</div><div>}</div><div><br></div><div>The followin CMakeLists.txt works fine, but you can notice that target_compile_options takes a list, while target_link_libraries takes a string. Always using the string will result in a compilation error, because the compiler flags are passed quoted to the compiler. Always using the list doesn't work either, because the generator expression is evaluated as $<1:-fsanitize=address -fno-omit-frame-pointer> and then passed as-is to the linker, which doesn't know what to do with it.</div><div>Is this supposed to be like this? If yes, what's the rationale?</div><div>Thanks in advance!</div><div>  Roberto</div><div><br></div><div><div>cmake_minimum_required(VERSION 3.3 FATAL_ERROR)</div><div><br></div><div>project(recipe-09 CXX)</div><div><br></div><div>set(CMAKE_CXX_STANDARD 11)</div><div>set(CMAKE_CXX_EXTENSIONS OFF)</div><div>set(CMAKE_CXX_STANDARD_REQUIRED ON)</div><div><br></div><div>list(APPEND CXX_BASIC_FLAGS "-g3" "-O1")</div><div><br></div><div>include(CheckCXXCompilerFlag)</div><div><br></div><div>set(ASAN_FLAGS "-fsanitize=address -fno-omit-frame-pointer")</div><div>set(CMAKE_REQUIRED_FLAGS ${ASAN_FLAGS})</div><div>check_cxx_compiler_flag(${ASAN_FLAGS} asan_works)</div><div>unset(CMAKE_REQUIRED_FLAGS)</div><div><br></div><div>add_executable(asan-example asan-example.cpp)</div><div>string(REPLACE " " ";" _asan_flags ${ASAN_FLAGS})</div><div>target_compile_options(asan-example</div><div>  PUBLIC</div><div>    ${CXX_BASIC_FLAGS}</div><div>    $<$<BOOL:${asan_works}>:${_asan_flags}></div><div>  )</div><div>target_link_libraries(asan-example</div><div>  PUBLIC</div><div>    $<$<BOOL:${asan_works}>:${ASAN_FLAGS}></div><div>  )</div></div>
</div></div>