0

I'm trying to create a binary file in cmake which: - depeneds on some .c source files - also depeneds on an assembler .s file

Now I have added the .c files normally by setting a variable as a list which contains all .c files in a directory. All good so far.

Now I need to add that assembler file as well as part of my binary directory. I did some research in the mailing archieve of cmake and I saw that with assembler files it's a little different you can't just include them as you do with the c files. You have to sometime preprocess them and include their output as a dependecy to the final binary file. Or so I understood.

The way I tried to do it in my project is something like this:

  • get assembler file name and path using a get_filename_component command:
  • in an 'add_custom_command' preprocess the file like this:

    COMMAND ${COMPILER_NAME} --preprocess=p ${ASSEMBLER_FILE_NAME} > ${OUT_S_FILE} Where OUT_S_FILE will be added as a dependency to a target which will be then added as a dependency to the binary file so that it gets created before the binary is created. Now I do not understand the --preprocess=p argument I tried googleing it but to no avail I do not know if it's correct or what it actually does(I have seen it in an example which took care of some assembler files).

  • set a variable: "ASM_OUT_FILE" to path of the file processed above

  • create a custom target which depends on this "ASM_OUT_FILE"

Finally add this target as a dependency so it gets created before the binary is created.

I'm sorry I cannot provide more actually example for what I've done but it's work related :D.

The result is "no rule to make target for that assembler file" as if the file was not there but it is(I checked).

Please tell me if possible if there are other things I need to do or if I'm doing something wrong in handling this assembler file. Thank you for reading and I'm sorry if my erxplanation was not so clear!

Edit:

set_source_files_properties(assembly_file.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
Kennedy
  • 277
  • 2
  • 7
  • 21
  • 1
    "you can't just include them as you do with the c files." - CMake **supports assembler sources**: https://stackoverflow.com/questions/15132185/mixing-c-and-assembly-sources-and-build-with-cmake. It seems that your problem is somewhere else. Show the code. – Tsyvarev Apr 17 '18 at 09:22
  • I have tried setting the source files properties like this: set_source_files_properties(assembly_file.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") like in that post then added it as to my executable and now I get some asm errors so I guess the file is processed by cmake – Kennedy Apr 17 '18 at 10:17
  • " now I get some asm errors so I guess the file is processed by cmake" - Such a vague description... Do not post code in the comments - **add the code to the question post itself** (via [edit]-ing it). Provide [mcve]. – Tsyvarev Apr 17 '18 at 10:20
  • Ok I will add that piece of code there. Unfortunately I cannot post more as it is work related and I can't replicate a similar example as I do not know assembler. I just need to use an already existing assembler file. – Kennedy Apr 17 '18 at 10:29
  • No needs to add the code on which you currently work. Instead, create **simplified example**, which anyone can run on his/her machine. As the problem is about CMake using, an example should include `CMakeLists.txt` or its part, which includes key command calls: `add_executable`, setting compiler/linker flags and so on. Content of `.c` or `.s` files isn't needed. Also show **exact error message** you got when run your *example*. So anyone who run the code may observe the same (or similar) error. If the error is about some line of the code, provide that line. – Tsyvarev Apr 17 '18 at 10:37
  • Ok I'm trying to replicate the problem now with a simpler example. Btw I think my errors in assembler come from the fact that I need to pass it a file which contains some linker options. But I think I'm not doing this correctly. I have tried appending that file to the 'CMAKE_C_LINK_FLAGS' variable but it did not work. – Kennedy Apr 17 '18 at 10:59
  • Hello again. The problem was solved by processing some header files as libraries(target_link_libraries) instead of putting them with include command. Thanks for your answers and sorry for the late reply. – Kennedy Apr 25 '18 at 08:29

0 Answers0