1

I have two things that I want to do in a CMakeLists.txt file:

  1. I want to first create an object file that is created by ld (a command like ld -r -b binary -o binary.o foo.bar )
  2. Link in this created file into my executable

I looked into using add_custom_target and/or add_custom_command, but the CMake documentation has got me confused on how I can actually do both of these tasks effectively from within CMake.

If I add a custom target and specify my own command, how would CMake know which file to link into the executable? If I add a custom command (say PRE_LINK), how can I add it into the linking stage?

Or is there a better way to handling resource files using CMake in Linux?

Thanks in advance.

Edit : Found that this question is essentially the same and answers my question as well: compile and add object file from binary with cmake.

Community
  • 1
  • 1
AdmiralJonB
  • 2,038
  • 3
  • 23
  • 27

1 Answers1

0

CMake provides functionality to do this.

  1. You can create an object from your sources using add_library.
  2. You can then link this to your executable using target_link_libraries.
pfhunk
  • 16
  • 3
  • Sorry, but I guess I wasn't clear. The object file that I'm creating isn't an ordinary source file, but a file turned into a binary blob. I found the answer and edited my post with it. – AdmiralJonB Aug 29 '14 at 00:35