This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Add stripped installation targets
ClosedPublic

Authored by smeenai on Nov 29 2017, 1:18 PM.

Details

Summary

CMake's generated installation scripts support CMAKE_INSTALL_DO_STRIP
to enable stripping the installed binaries. LLVM's build system doesn't
expose this option to the install- targets, but it's useful in
conjunction with install-distribution.

Add a new function to create the install targets, which creates both the
regular install target and a second install target that strips during
installation. Change the creation of all installation targets to use
this new function. Stripping doesn't make a whole lot of sense for some
installation targets (e.g. the LLVM headers), but consistency doesn't
hurt.

I'll make other repositories (e.g. clang, compiler-rt) use this in a
follow-up, and then add an install-distribution-stripped target to
actually accomplish the end goal of creating a stripped distribution. I
don't want to do that step yet because the creation of that target would
depend on the presence of the install-*-stripped target for each
distribution component, and the distribution components from other
repositories will be missing that target right now.

Diff Detail

Repository
rL LLVM

Event Timeline

smeenai created this revision.Nov 29 2017, 1:18 PM
beanz edited edge metadata.Nov 29 2017, 2:59 PM

Is there a reason to add a new option instead of just adding -DCMAKE_INSTALL_DO_STRIP=${CMAKE_INSTALL_DO_STRIP} to the install commands?

Is there a reason to add a new option instead of just adding -DCMAKE_INSTALL_DO_STRIP=${CMAKE_INSTALL_DO_STRIP} to the install commands?

My reasoning for not going with that approach was that, in the usual CMake setup, CMAKE_INSTALL_DO_STRIP is only applicable when running installation scripts, and it doesn't have any effect at configuration time. If we're adding special behavior to LLVM's build system to make the stripping flag sticky during configuration, it seemed better to make it clear that this behavior was specific to LLVM's build system and not a general CMake thing.

I guess the install- targets themselves are an LLVM build system thing anyway though, so their behavior is already custom. I'm happy to change it according to your suggestion.

beanz added a comment.Nov 29 2017, 3:50 PM

So, I wasn't actually familiar with how CMAKE_INSTALL_DO_STRIP worked, so I went and researched it. I think we actually should mimic how that works. So instead of having an option that enables stripping on the install targets, we should create two targets, one that strips and one that doesn't. Then the user can select whether or not they want their install contents stripped by choosing which target they run.

Also because of how many places we create these install targets we probably should abstract it into a function in AddLLVM.cmake (something like add_llvm_install_targets), which would take a target name and optional component and install prefix, and dependencies. That function would look something like:

function(add_llvm_install_targets target)
  cmake_parse_arguments(ARG "" "COMPONENT;PREFIX" "DEPENDS" ${ARGN})
  if(ARG_COMPONENT)
    set(component_option -DCMAKE_INSTALL_COMPONENT=${ARG_COMPONENT})
  endif()
  if(ARG_PREFIX)
    set(prefix_option -DCMAKE_INSTALL_PREFIX=${ARG_PREFIX})
  endif()
  add_custom_target(${target}
                    DEPENDS ${ARG_DEPENDS}
                    COMMAND "${CMAKE_COMMAND}"
                            ${component_option}
                            ${prefix_option}
                            -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
                    USES_TERMINAL)

  add_custom_target(${target}/strip
                    DEPENDS ${ARG_DEPENDS}
                    COMMAND "${CMAKE_COMMAND}"
                            ${component_option}
                            ${prefix_option}
                            -DCMAKE_INSTALL_DO_STRIP=1
                            -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
                    USES_TERMINAL)
endfunction()

Then you just change the places we create install targets to be calls like:

add_llvm_install_targets(install-${name}
                      DEPENDS ${name}
                      COMPONENT ${name})

or

add_llvm_install_targets(install-distribution-${target}
                DEPENDS ${target}
                COMPONENT ${target}
                PREFIX ${LLVMToolchainDir}/usr/)
smeenai updated this revision to Diff 124993.Nov 30 2017, 12:31 PM
smeenai retitled this revision from [llvm] Add option to strip binaries during installation to [llvm] Add stripped installation targets.
smeenai edited the summary of this revision. (Show Details)

@beanz suggestions. / isn't valid in a target so I went with a -stripped suffix

beanz accepted this revision.Nov 30 2017, 1:20 PM

LGTM. It is a little strange that CMake generates the install/strip target automatically, but won't let you put / in a target name, but there really isn't anything to be done about it.

This revision is now accepted and ready to land.Nov 30 2017, 1:20 PM
This revision was automatically updated to reflect the committed changes.