cmake caches w/additional compile+link flags

In an internal project, we build libcxx+libcxxabi with many settings configured in a cmake cache file. It gets invoked roughly like so:

cmake -DLLVM_ENABLE_PROJECTS=libcxx;libcxxabi;pstl -C./libcxx/xyz/target.cmake -DCMAKE_INSTALL_PREFIX=/target/install/path …/llvm-project/llvm

… I would prefer to include as many of the relevant build settings as possible in the ‘target.cmake’ file. Today we clobber “CMAKE_CXX_FLAGS” with the required target-specific flags in that file and it’s effective. But it doesn’t cooperate well with the rest of the libcxx/libcxxabi cmake configuration.

This seems really simple but I’ve never quite been able to figure out how to append flags to the build configuration from the cmake cache. I’ve tried a few different ways of writing to LIBCXX_COMPILE_FLAGS (including with CACHE FORCE) but even if the value in LIBCXX_COMPILE_FLAGS persists in the CMakeCache.txt they don’t seem to be reflected in the flags used to build. So it’s probably some cmake rules I don’t quite understand about the order or scope in which LIBCXX_COMPILE_FLAGS is defined.

I’m sure I’m missing something simple – can anyone share a good way to accomplish my goal of adding/removing compile+link flags in the preloaded cmake cache file?

-Brian

I'm not sure there's a way to do that -- the question I'd have is what flags are you trying to set? At first sight, it looks to me like you're trying to use CMake the wrong way, and that's why it gets in your way :-). There might be another way of achieving what you're trying to do.

Louis

“trying to use CMake the wrong way, and that’s why it gets in your way"

Yes that could very likely be the case. I want to add compile flags to build with target-specific tuning options in order to build different versions of libcxx. The driver picks the right version of the library given the corresponding link arguments.

It seems like if there were an empty-by-default-but-overridable-in-cache “LIBCXX_EXTRA_CFLAGS” (and LIBCXXABI_/LIBUNWIND_) it would be an effective way to get what I’m looking for. But as you point out it might not be the Right Way.

-Brian