2

the overall story: I'm creating 2 libraries (32, 64) and want to create a universal binary out of them, and that the final universal binary would update only if:

(1) one of the two libraries had changed. (2) the universal binary had been deleted.

Details: My two per-architecture libraries are created using an add_library (SHARED). Each need slightly different build options, otherwise I would have used CMAKE_OSX_ARCHITECTURES.

I have a set of commands for creating the universal binary (lipo etc.) Now, when using add_custom_command() or add_custom_target(), either the final universal binary ALWAYS builds, or it does not build at all - depending on how I tweak the arguments.

What is the right way to do it?

The following code creates the universal every time:

add_custom_target(${target} ALL
    "lipo" "-create" ${subtarget_filenames} "-output" "../Temp/${target_filename}"
    COMMAND "ln" "-f" "-s" "../Temp/${target_filename}" "../Products/${target_filename}"
    COMMENT "Creating a universal binary: ${target_filename}")

The following doesn't create it at all:

add_custom_command(OUTPUT ../Temp/${target_filename}
    COMMAND "lipo" "-create" ${subtarget_filenames} "-output" "../Temp/${target_filename}"
    COMMAND "ln" "-f" "-s" "../Temp/${target_filename}" "../Products/${target_filename}"
    COMMENT "Creating a universal binary: ${target_filename}")
gil_mo
  • 575
  • 1
  • 6
  • 27
  • 1
    "Now, when using add_custom_command() or add_custom_target(), either the final universal binary ALWAYS builds, or it does not build at all - depending on how I tweak the arguments." - **Show the code** which causes this behaviour. – Tsyvarev Dec 27 '18 at 17:27
  • Thanks, code added. – gil_mo Dec 27 '18 at 19:59
  • 2
    A *COMMAND*, specified in `add_custom_target`, is intended to be run every time. Approach with `add_custom_command` is correct, but see there why your code doesn't work and how to fix it: https://stackoverflow.com/questions/2937128/cmake-add-custom-command-not-being-run. – Tsyvarev Dec 27 '18 at 20:26

0 Answers0