gil_mo
gil_mo

Reputation: 625

CMake Mac: creating a universal binary using custom command/target

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}")

Upvotes: 2

Views: 1288

Answers (0)

Related Questions