FindSelfPackers.cmake 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindSelfPackers
  5. ---------------
  6. Finds `UPX <https://upx.github.io/>`_, the Ultimate Packer for eXecutables:
  7. .. code-block:: cmake
  8. find_package(SelfPackers [...])
  9. This module searches for executable packers-tools that compress executables or
  10. shared libraries into on-the-fly, self-extracting versions. It currently
  11. supports ``UPX``.
  12. Result Variables
  13. ^^^^^^^^^^^^^^^^
  14. This module defines the following variables:
  15. ``SelfPackers_FOUND``
  16. .. versionadded:: 4.2
  17. Boolean indicating whether packer tools were found.
  18. Cache Variables
  19. ^^^^^^^^^^^^^^^
  20. The following cache variables may also be set:
  21. ``SELF_PACKER_FOR_EXECUTABLE``
  22. Path to the executable packer for compressing executables.
  23. ``SELF_PACKER_FOR_SHARED_LIB``
  24. Path to the executable packer for compressing shared libraries.
  25. ``SELF_PACKER_FOR_EXECUTABLE_FLAGS``
  26. Command-line options to use when compressing executables.
  27. ``SELF_PACKER_FOR_SHARED_LIB_FLAGS``
  28. Command-line options to use when compressing shared libraries.
  29. Examples
  30. ^^^^^^^^
  31. Finding UPX:
  32. .. code-block:: cmake
  33. find_package(SelfPackers)
  34. #]=======================================================================]
  35. include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
  36. include(${CMAKE_CURRENT_LIST_DIR}/FindMsys.cmake)
  37. find_program(SELF_PACKER_FOR_EXECUTABLE
  38. upx
  39. ${CYGWIN_INSTALL_PATH}/bin
  40. ${MSYS_INSTALL_PATH}/usr/bin
  41. )
  42. find_program(SELF_PACKER_FOR_SHARED_LIB
  43. upx
  44. ${CYGWIN_INSTALL_PATH}/bin
  45. ${MSYS_INSTALL_PATH}/usr/bin
  46. )
  47. mark_as_advanced(
  48. SELF_PACKER_FOR_EXECUTABLE
  49. SELF_PACKER_FOR_SHARED_LIB
  50. )
  51. #
  52. # Set flags
  53. #
  54. if (SELF_PACKER_FOR_EXECUTABLE MATCHES "upx")
  55. set (SELF_PACKER_FOR_EXECUTABLE_FLAGS "-q" CACHE STRING
  56. "Flags for the executable self-packer.")
  57. else ()
  58. set (SELF_PACKER_FOR_EXECUTABLE_FLAGS "" CACHE STRING
  59. "Flags for the executable self-packer.")
  60. endif ()
  61. if (SELF_PACKER_FOR_SHARED_LIB MATCHES "upx")
  62. set (SELF_PACKER_FOR_SHARED_LIB_FLAGS "-q" CACHE STRING
  63. "Flags for the shared lib self-packer.")
  64. else ()
  65. set (SELF_PACKER_FOR_SHARED_LIB_FLAGS "" CACHE STRING
  66. "Flags for the shared lib self-packer.")
  67. endif ()
  68. mark_as_advanced(
  69. SELF_PACKER_FOR_EXECUTABLE_FLAGS
  70. SELF_PACKER_FOR_SHARED_LIB_FLAGS
  71. )
  72. if(SELF_PACKER_FOR_EXECUTABLE AND SELF_PACKER_FOR_SHARED_LIB)
  73. set(SelfPackers_FOUND TRUE)
  74. else()
  75. set(SelfPackers_FOUND FALSE)
  76. endif()