[CMake] XCode Generation Issue

Eric Wing ewmailing at gmail.com
Thu Jan 21 18:16:34 EST 2016


On 1/21/16, David Morsberger <dave at morsberger.com> wrote:
> Eric,
>
> I went down a rabbit hole and pulled myself back out. I narrowed it down to
> the following.
>
> We are using cmake to check if the linker supports -Wl,—as-needed. The test
> compile (and link?) command cmake builds using ‘cmake -G Xcode’  does not
> fail.
>
> The command from ‘cmake -G’ has been narrowed down to the following:
>
> $
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
> \
>  -Qunused-arguments \
>  -DWS_LD_FLAG_VALID0 \
>  -Wl,--as-needed \
>  -c src.c \
>  -o src.o
> $
>
> The following modified command generates an error:
>
> $
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
> \
>  -Qunused-arguments \
>  -DWS_LD_FLAG_VALID0 \
>  -Wl,--as-needed \
>  src.c
>
> ld: unknown option: --as-needed
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
> $
>
> It appears the linker isn’t called when the -c and the -o options are
> present. The following warning is generated when the ‘-Qunused-arguments’ is
> removed.
>
> clang: warning: -Wl,--as-needed: 'linker' input unused
>
> The cmake logic in CMakeLists.txt is basically:
>
>    SET(CMAKE_REQUIRED_FLAGS "${_FLAG}")
>    CHECK_C_SOURCE_RUNS(“int main() { return 0;}" ${_RESULT})
>
> where _FLAG is set to ‘-DWS_LD_FLAG_VALID0 -Wl,—-as-needed’
>
>
> So, how/where is the clang compile/link command generated and why isn’t it
> being setup for clang to link?
>
>

Sorry, these are internals I'm not very familiar with. I'm just
starting to get up to speed on the CMake internals for the Makefile
generator (Linux focus) because I'm trying to add a Swift backend.

My impression has always been (this could be wrong) that the Xcode
generator has more deference to Xcode than CMake actively getting
involved. I probably helped push this attitude too because Apple tries
to handle a lot of specific details through Xcode that they feel is
too arcane to expect/require their developers to know about. In
general, I find this to be the right thing, because ultimately getting
stuff that works well with Obj-C (CMake makefiles have a bug where
they compile as Obj-C++), all the packaging and codesigning, and
working with the iOS simulator are platform specific and somewhat
private/changing implementation details they don't want us to manually
hardcode.


Anyway, to your question, I almost never use CHECK_ commands so I'm not sure.
CHECK_C_SOURCE_RUNS is something I would never use because 'running'
is a serious problem for cross-compilation (Mac was
PowerPC/Intel/32-bit/64-bit, iOS is armv6/armv7(s)/arm64/i386).
Cross-compilation is kind of built-into Xcode's thinking now because
there are so many targets. I don't even know how LLVM bitcode factors
into this now, but hopefully the idea of deference to Xcode is that I
mostly won't need to care.

Are there separate CHECK_ commands for compilation and linking
(without running)?

-Eric


More information about the CMake mailing list