How do I specify the CFLAGS and CXXFLAGS? I tried using --extra-cmake-options="-DCMAKE_C_FLAGS=
and --extra-cmake-options="-DCMAKE_CXX_FLAGS=
, but they didn't seem to have any effect (I'm trying to add more paths to the include path).
It depends what you're trying to build, but since most of the Swift toolchain build is configured by CMake, it should automatically pick up those flags from the environment, ie you won't need to pass them in that way. You can usually check this by examining the CMakeCache.txt
file in your build directory.
The one exception might be building the compiler and stdlib, as those still mostly use their own specialized CMake config that predates CMake itself supporting Swift. What is the precise error you're seeing?
build-script
doesn't seem to update CMakeCache.txt whenever you modify --extra-cmake-options
. You'll need to either modify the CMakeCache.txt manually or just rm it and rerun build-script
.
I am trying to build the compiler with additional include paths that aren't in the environment variables.
It has the flag --reconfigure
to force running CMake again. Of course, CMake is a little weird in what it allows you to reset that way, so sometimes you're right that the only way is those manual methods.
Your flags should work for that when run with --reconfigure
on an existing build, but those will apply to LLVM and all other repos too. You probably want the --swift-cmake-options
flag instead, which will only apply to building the Swift compiler frontend and stdlib. However, as I said, the compiler/stdlib often does not take just regular CMake flags and rolls its own CMake build config.
--reconfigure
works to get it to see the LDFLAGS I tried to add, but --swift-cmake-options
forcibly splits the LDFLAGS (-DCMAKE_EXE_LINKER_FLAGS
etc) on spaces. Also, it seems to override my attempts to add -DCMAKE_C_FLAGS
and similar, as it provides its own -DCMAKE_C_FLAGS
to CMake and mine don't show up.
Am I supposed to use -DSWIFT_COMPILER_SOURCES_SDK_FLAGS
instead?
I'm currently trying this: utils/build-script --release-debuginfo --export-compile-commands --reconfigure --swift-cmake-options="-DSWIFT_COMPILER_SOURCES_SDK_FLAGS='$CFLAGS $LDFLAGS'"
(where I set CFLAGS
and LDFLAGS
earlier)