[CMake] The Xcode generator and ASM_NASM support

Tom Finegan tomfinegan at google.com
Wed Oct 3 14:05:14 EDT 2018


On Wed, Oct 3, 2018 at 10:29 AM Gregor Jasny <gjasny at googlemail.com> wrote:

> Hello,
>
>
> On 10/3/18 6:08 PM, Tom Finegan via CMake wrote:
> > I'm trying to get rid of some local CMake scripting for building assembly
> > with nasm and yasm, but I'm running into a problem with the Xcode
> generator.
> >
> > For the make and ninja generators, everything is fine-- nasm and yasm are
> > both working as expected.
> >
>

This works fine with Visual Studio as well.


> > The same is not true for Xcode. When building a target that includes
> > assembly files Xcode outputs the warnings like the following during its
> > "Check dependencies" step:
> >
> > warning: no rule to process file <assembly file> of type sourcecode for
> > architecture x86_64
>
> If the Xcode included nasm and the default Xcode flags are good enough
> for you you might get away with:
>
> set_source_files_properties(${yasm_file} PROPERTIES
>    XCODE_EXPLICIT_FILE_TYPE "sourcecode.nasm")
>
>
This has no impact on Xcode's behavior at build time; I see the same
warning each time Xcode encounters a .asm file. I can see that the property
is actually set on the .asm files, so it is at least doing something. Just
not quite enough. :)


> Otherwise I had to create a add_custom_command for every file and
> pointed to a shell script that based on all architectures found in ARCHS
> ran yasm and in the end called lipo to create the final fat .o file.
>

Indeed. I use add_custom_command() and then add the objects into a
dependent target. I was hoping to drop the script that was doing the work.
Oh well.

Just in case, here's the util macro I'm using to do the work-- maybe
someone can spot something silly I've missed:

macro(add_asm_object_library target dependent_target sources)
  if("${${sources}}" STREQUAL "")
    message(FATAL_ERROR "--- add_asm_object_library: empty source list.")
  endif()

  add_library(${target} OBJECT ${${sources}})
  target_sources(${dependent_target} PRIVATE $<TARGET_OBJECTS:${target}>)

  if("${CMAKE_ASM_NASM_COMPILER}" MATCHES "nasm")

    # Include path handling in nasm is broken. If the trailing slash is
omitted
    # nasm cannot find includes. Explicitly add the necessary include paths
with
    # trailing slashes.
    target_compile_options(${target} PRIVATE "-I${AOM_ROOT}/"
                           "-I${AOM_CONFIG_DIR}/")
  endif()

  if(XCODE)
    set_source_files_properties(${${sources}} PROPERTIES
                                XCODE_EXPLICIT_FILE_TYPE "sourcecode.nasm")
  endif()

  list(APPEND AOM_LIB_TARGETS ${target})
endmacro()



>
> Hope that helps,
> -Gregor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181003/4a024054/attachment.html>


More information about the CMake mailing list