microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
10.61k stars 866 forks source link

Extra compiler flags #916

Open bgemmill opened 4 months ago

bgemmill commented 4 months ago

I'm trying to build mimalloc with march set to a deployment machine's architecture, and I can't seem to get the extra flags passed through to mimalloc's build process.

The usual way of configuring: cmake "-DCMAKE_CXX_FLAGS= -march=skylake" . runs correctly, but does not seem to produce any makefiles containing march=skylake

Near as I can tell, this is because the CMakeLists.txt file uses mi_cflags instead, and manually sets it on the target.

Is there a good way to add compile flags from the outside?

daanx commented 3 months ago

Ah, I am not a CMake expert -- but it looks like target_compile_options only adds options and still respects CMAKE_CXX_FLAGS ? (see https://cmake.org/cmake/help/latest/command/target_compile_options.html#command:target_compile_options)

Maybe it is cached and you need to first remove all files in your build folder? Or maybe use the CFLAGS environment variable? or cmake "-DCMAKE_C_FLAGS= -march=skylake" since we usually build it as a C project?.