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? > On Jan 21, 2016, at 1:51 AM, Eric Wing <ewmail...@gmail.com> wrote: > > On 1/20/16, David Morsberger <d...@morsberger.com> wrote: >> >>> On Jan 19, 2016, at 10:11 PM, Eric Wing <ewmail...@gmail.com> wrote: >>> >>> On 1/19/16, David Morsberger <d...@morsberger.com> wrote: >>>> Any help would be appreciated. >>>> >>>> In particular I’d like to know how the default compiler arguments are >>>> set >>>> when ‘cmake -G Xcode’ is executed. The attached file contains the cmake >>>> test >>>> compile extracted and reformatted from CMakeOutput.log that should have >>>> failed. Again, what is setting all the clang compiler options when this >>>> is >>>> executed? >>>> >>>> >>>> >>>> All help is appreciated >>>> >>>>> On Jan 18, 2016, at 2:58 PM, David Morsberger <d...@morsberger.com> >>>>> wrote: >>>>> >>>>> I’m having an issue generating and using a XCode project using cmake >>>>> -G. >>>>> >>>>> cmake —version >>>>> cmake version 3.4.1 >>>>> >>>>> Xcode Version 7.2 (7C68) >>>>> >>>>> Mac OS 10.11. >>>>> >>>>> >>>>> My CMakeLists.txt has a clang option that fails during the -G Xcode >>>>> pass >>>>> but fails when linking within XCode. >>>>> >>>>> The compiler / linker option is ‘-Wl,—as-needed’ >>>>> >>>>> The test compile/link step in ‘cmake -G Xcode' creates a long clang >>>>> command with arguments ‘-Wl,—as-needed’ plus ‘—serialize-diagnostics >>>>> <path >>>>> to .dia file>’ >>>>> >>>>> The link step within Xcode after the project created has the >>>>> ‘-Wl,—as-needed’ argument and does not have the ‘—serialize-diagnostics >>>>> <path to .dia file>’ argument. The link fails because ‘-Wl,—as-needed’ >>>>> isn’t supported. >>>>> >>>>> If copy and execute the long clang command from the ‘cmake -G Xcode’ >>>>> command and remove the ‘—serialize-diagnostics <path to .dia file>’ >>>>> then >>>>> it successfully fails with ‘-Wl, —as-needed’ isn’t supported. >>>>> >>>>> Finally, when I use cmake to generate unix makefiles it works meaning >>>>> cmake determines ‘-Wl—as-needed’ isn’t supported and doesn’t add it to >>>>> the >>>>> argument list. >>>>> >>>>> Questions: >>>>> - Where is the ‘—serialized-diagnostics’ argument coming from when >>>>> executing ‘cmake -G Xcode’? >>>>> >>>>> - What is a .dia file and how do I read it? >>>>> >>>>> - What’s the preferred / recommended way of detecting the non-supported >>>>> ‘-Wl,—as-needed’ argument during the ‘cmake -G Xcode’ phase? One option >>>>> might to be to remove the ‘—serialize-diagnostics’ argument during the >>>>> generation phase. >>>>> >>>>> I can provide more details on request. >>>>> >>>>> David >>>>> >>>>> >>>>> >>> >>> >>> I just spot checked one of my Xcode compile logs. I see the >>> —serialize-diagnostics flag, but I don't have —as-needed anywhere. >>> Maybe one of your CMake scripts is adding that in, or you have set >>> some kind of environment variable that clang or Xcode is picking up? >>> (This recently happened to me on Linux.) >> >> Ed, >> >> In this case cmake is attempting to determine if ‘—as-needed' is a supported >> option and the build should fail. >> >> I have searched (grep’d) everything I can think of for the string >> ’serialize-diagnostics’ with zero hits. >> >> I can easily add an ‘if( Xcode )’ around the setting in CMakeLists.txt >> however I’m trying to figure out what is exactly going on. The best >> solutions are chosen when you know what is going on under the hood. >> >> >> > > I believe the serialize-diagnostics flag is added by Xcode itself. I > see it (along with many other flags) in a native (non-CMake generated) > Xcode project. > > -Eric
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake