LLNL / blt

A streamlined CMake build system foundation for developing HPC software
BSD 3-Clause "New" or "Revised" License
260 stars 60 forks source link

blt_append_custom_compiler_flag macro should support list parameters #314

Open kennyweiss opened 5 years ago

kennyweiss commented 5 years ago

Our flag related macros have recently been unified to operate on lists (#305), but our macro to generate flags -- blt_append_custom_compiler_flag -- only operates on strings, and the results are not directly compatible with our flag-related macros.

E.g. I'd expect the following to work:

blt_append_custom_compiler_flag(FLAGS_VAR _flags
    DEFAULT     " "
    GNU         "string-flag1  string-flag2"  # space-delimited
    CLANG       list-flag1 list-flag2         # list
    MSVC        single )
  blt_add_target_compile_flags(TO <target> SCOPE <scope> FLAGS ${_flags})

But, since the arguments to blt_append_custom_compiler_flag are strings rather than list (i.e. singleValuedArgs in our macro, rather than multiValuedArgs), only the first flag is used.

Note: I was able to get my example working (after some effort), but it is not as simple or obvious as it can be:

 # Current workaround 
blt_append_custom_compiler_flag(FLAGS_VAR _flags
    DEFAULT     " "
    GNU         "string-flag1  string-flag2"
    CLANG       "string-flag3  string-flag4"
    MSVC        single )
string (REPLACE " " ";" _flags "${_flags}")
blt_add_target_compile_flags(TO <target> SCOPE <scope> FLAGS ${_flags})

Note: This only works for space-delimited strings and requires a manual conversion from strings to lists.

white238 commented 5 years ago

I am for this but this needs to be thoroughly tested replacing spaces with ;'s is not safe. What if your argument has a space in it, like a path?