mimalloc-bench icon indicating copy to clipboard operation
mimalloc-bench copied to clipboard

CMAKE_C?_FLAGS are not lists but strings

Open RJVB opened this issue 2 years ago • 3 comments

https://github.com/daanx/mimalloc-bench/blob/6e4bbc7feaf51e3e94aa7a470a535a22e16e1d02/bench/CMakeLists.txt#L44

CMake lists are semicolon-separated affairs so appending flags to CMAKE_C?_FLAGS with list(APPEND CMAKE_C?_FLAGS "-foo -bar") will introduce a semicolon in the final compiler invocation if those flags aren't empty. Which can be the case if the user calls CMake with CFLAGS and/or CXXFLAGS in the environment.

The proper way to append compiler flags is a string append operation, e.g.

if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU")
  set(FLAGS " -w -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-conversion")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
endif()

RJVB avatar Aug 08 '23 13:08 RJVB

Care to send a pull-request?

jvoisin avatar Aug 08 '23 14:08 jvoisin

Really, for such a small & trivial change?

RJVB avatar Aug 08 '23 14:08 RJVB

I had the files open, so pushed a PR. https://github.com/daanx/mimalloc-bench/pull/192

mjp41 avatar Aug 08 '23 16:08 mjp41